Skip to content

Game.Simulation.IMapTilePurchaseSystem

Assembly: Assembly-CSharp.dll
Namespace: Game.Simulation

Type: interface

Base: n/a

Summary:
Interface used by the simulation to represent a system that handles purchasing of map tiles (land) and reporting the current selection state. Implementations provide information about whether tile selection mode is active, the computed cost for the current selection, any purchase-related error/status flags, and facilities to query feature amounts within the selection, execute the purchase, and perform per-tick updates. The interface references types from Game.Areas (e.g., MapFeature, TilePurchaseErrorFlags).


Fields

  • This interface declares no fields. Implementations may keep private fields to track selection state, computed cost, cached feature counts, timers, etc.
    {{ Implementations should manage internal state (selection geometry, cached cost) privately and expose values via the interface properties and methods. }}

Properties

  • public bool selecting { get; set; }
    Controls or reports whether the tile-purchase selection mode is currently active. Setting this typically begins or ends the user's selection session; getting returns whether selection mode is enabled.
    {{ Implementations should enable input/visuals when selecting is true and clear temporary selection state when set to false. }}

  • public int cost { get; }
    Read-only property returning the calculated cost (in city currency) for the currently selected tiles. If no selection exists, implementations usually return 0.
    {{ Cost should reflect applicable modifiers (discounts, taxes, adjacency rules) and be kept up to date by Update() or selection-change handlers. }}

  • public TilePurchaseErrorFlags status { get; }
    Read-only flags describing the current purchase status or reasons a purchase cannot proceed (e.g., insufficient funds, invalid terrain, selection too large). The TilePurchaseErrorFlags type is defined in Game.Areas.
    {{ Implementations should set status to TilePurchaseErrorFlags.None (or equivalent) when the current selection is valid and purchasable. }}

Constructors

  • Interfaces do not declare constructors.
    {{ Concrete implementations must provide their own constructors or initialization (for example, via dependency injection, an OnCreate method, or MonoBehaviour/Awake) and ensure any required game systems are acquired before being used. }}

Methods

  • float GetFeatureAmount(MapFeature feature)
    Returns the amount (as a floating-point value) of the specified MapFeature present within the current selection. MapFeature is defined in Game.Areas and typically represents things like trees, rocks, water coverage, pollution, or other measurable map attributes.
    {{ Use this to present UI feedback (e.g., number of trees to be removed) or to compute costs/penalties associated with the purchase. Implementations should return 0 for features not present or when there is no selection. }}

  • void PurchaseSelection()
    Attempts to purchase the currently selected tiles. Implementations should perform validation (based on status and cost), deduct funds from the city's wallet, apply ownership changes for tiles, and update any relevant game state. After a successful purchase, selection state should be cleared or updated accordingly.
    {{ This method should be resilient: check current status, handle failure cases gracefully (set status flags), and raise any necessary events or notifications to UI/game systems on success/failure. }}

  • void Update()
    Per-frame or per-simulation-tick update method. Implementations typically update the current selection geometry, recompute cost, refresh status flags, and keep any temporary visuals or cached values in sync.
    {{ Called by the game's simulation loop or by a manager that owns the system. Implementations should avoid heavy work on every frame where possible and cache results until selection changes. }}

Usage Example

using Game.Areas;
using Game.Simulation;

public class MyMapTilePurchaseSystem : IMapTilePurchaseSystem
{
    private bool _selecting;
    private int _cost;
    private TilePurchaseErrorFlags _status;

    public bool selecting
    {
        get => _selecting;
        set
        {
            _selecting = value;
            if (!_selecting)
            {
                // clear selection visuals / temp data
            }
        }
    }

    public int cost => _cost;

    public TilePurchaseErrorFlags status => _status;

    public float GetFeatureAmount(MapFeature feature)
    {
        // return measured amount for specified feature inside current selection
        // e.g., count trees, calculate water coverage, etc.
        return 0f;
    }

    public void PurchaseSelection()
    {
        if (_status != TilePurchaseErrorFlags.None)
        {
            // cannot purchase, handle error (notify UI, log, etc.)
            return;
        }

        // Deduct funds, change tile ownership, apply changes
        // On success, clear selection and update state
    }

    public void Update()
    {
        if (!_selecting)
            return;

        // Recompute current selection geometry, cost and status
        // _cost = ComputeCost();
        // _status = EvaluateStatus();
    }
}

Notes and tips: - MapFeature and TilePurchaseErrorFlags are defined in Game.Areas; check those types to know which features and error flags exist and how they should be interpreted. - Keep heavy computations off tight update loops where possible; recompute only when selection geometry or relevant game state changes. - Ensure PurchaseSelection performs appropriate validation and communicates results back to UI/game systems so the user receives clear feedback.