Skip to content

Game.LandValueSystem

Assembly: Assembly-CSharp
Namespace: Game.Simulation

Type: class

Base: CellMapSystem, IJobSerializable

Summary:
LandValueSystem is a simulation system responsible for maintaining a 2D land-value grid (texture) and updating per-edge LandValue component data in the entity world. It combines many city factors — ground/air/noise pollution, terrain attractiveness, water pollution/depth, telecom coverage, service/resource availability and nearby net bonuses — to evaluate and smooth land value across the map. Updates are performed with Burst-compiled jobs (a parallel IJobParallelFor to update the grid and a JobChunk to update edge entities). The system exposes constants for its texture resolution and update frequency, and uses several other systems (pollution systems, terrain & water, telecom, visibility/search systems) as read sources.


Fields

  • public static readonly int kTextureSize
    Provides the resolution of the land-value texture (128). This is used when mapping world positions to cells and scheduling the parallel update job.

  • public static readonly int kUpdatesPerDay
    Specifies the number of updates per in-game day used to compute the update interval.

  • private EntityQuery m_EdgeGroup
    EntityQuery selecting edges (Edge + LandValue + Curve) used by the EdgeUpdateJob to update entity LandValue components.

  • private EntityQuery m_NodeGroup
    (Declared but unused in this compilation unit) placeholder group presumably for node-related queries if extended.

  • private EntityQuery m_AttractivenessParameterQuery
    Query to fetch AttractivenessParameterData singleton used by map evaluation.

  • private EntityQuery m_LandValueParameterQuery
    Query to fetch LandValueParameterData singleton holding multipliers and baseline values.

  • private GroundPollutionSystem m_GroundPollutionSystem
    Cached reference to the ground pollution system used to sample ground pollution map.

  • private AirPollutionSystem m_AirPollutionSystem
    Cached reference to the air pollution system used to sample air pollution map.

  • private NoisePollutionSystem m_NoisePollutionSystem
    Cached reference to the noise pollution system used to sample noise pollution map.

  • private AvailabilityInfoToGridSystem m_AvailabilityInfoToGridSystem
    Cached reference providing availability info per grid cell.

  • private SearchSystem m_NetSearchSystem
    Cached reference used to access the native quad tree with net entities (for road-related land value bonuses).

  • private TerrainAttractivenessSystem m_TerrainAttractivenessSystem
    Cached reference for terrain attractiveness map.

  • private TerrainSystem m_TerrainSystem
    Cached reference for terrain height data.

  • private WaterSystem m_WaterSystem
    Cached reference for water surface and pollution sampling.

  • private TelecomCoverageSystem m_TelecomCoverageSystem
    Cached reference for telecom coverage data per grid cell.

  • private TypeHandle __TypeHandle
    Internal struct holding Entity/Component/Buffer type handles used at update time.

  • Nested types (defined in this class):

  • NetIterator — quad-tree iterator used by the LandValueMapUpdateJob to collect nearby net/edge land-value bonuses.
  • LandValueMapUpdateJob (Burst compiled) — parallel job that computes the land-value grid cell values.
  • EdgeUpdateJob (Burst compiled) — chunk job that updates per-edge LandValue component based on service/resource buffers.

Properties

  • public int2 TextureSize { get; }
    Returns the 2D texture resolution used by this system as an int2 (kTextureSize x kTextureSize). Useful for map consumers or for translating between cell indices and textures.

Constructors

  • public LandValueSystem()
    Default parameterless constructor. The system uses OnCreate to initialize queries and cached system references.

Methods

  • public override int GetUpdateInterval(SystemUpdatePhase phase)
    Returns the number of ticks between updates for different update phases. Computed as 262144 / kUpdatesPerDay in this implementation (the system staggers map updates across simulation frames).

  • public static float3 GetCellCenter(int index)
    Returns the world-space center position of a land-value cell given its index in the kTextureSize x kTextureSize grid.

  • public static int GetCellIndex(float3 pos)
    Maps world-space position (x,z) to the cell index in the land-value grid. Uses CellMapSystem map sizing and the kTextureSize.

  • protected override void OnCreate()
    Initializes the system: asserts texture-size consistency with TerrainAttractivenessSystem, creates textures, caches references to other systems (search/pollution/terrain/water/telecom/availability systems) and sets up EntityQueries (edge group and parameter queries). Also calls RequireAnyForUpdate to avoid scheduling edge jobs when no matching entities exist.

  • protected override void OnUpdate()
    Main update path. Schedules:

  • EdgeUpdateJob (JobChunk) when edge group is non-empty to update entity LandValue components from service and resource buffers.
  • LandValueMapUpdateJob (IJobParallelFor, Burst compiled) to compute all grid cells in parallel, reading many map sources (pollution, terrain attractiveness, telecom coverage, availability, water). The method composes and combines multiple JobHandle dependencies, registers readers/writers with referenced systems, and adds appropriate readers to producers (e.g., m_NetSearchSystem.AddNetSearchTreeReader).

  • protected override void OnCreateForCompiler()
    Internal initialization helper invoked by generated code paths that assigns query and type handles used by the compiled system. (This is part of the ECS codegen/convenience wiring.)

  • private void __AssignQueries(ref SystemState state)
    Internal helper used by OnCreateForCompiler to define entity queries. In the current implementation this method contains a placeholder call (new EntityQueryBuilder(Allocator.Temp).Dispose();) and is present to satisfy generated call sites.

  • (Nested job methods)

  • LandValueMapUpdateJob.Execute(int index) — calculates a single cell's land value combining water depth, net-based bonuses, ground/air/noise pollution penalties, attractiveness bonuses, telecom coverage, and smoothing towards baseline.
  • EdgeUpdateJob.Execute(in ArchetypeChunk chunk, ...) — iterates entities in a chunk, reads service/resource buffers and updates each entity's LandValue component using configured multipliers and smoothing.

Notes for modders: - The system heavily relies on reading several map sources and component buffers. If you add readers/writers or change related systems, ensure you manage JobHandle dependencies correctly and register readers/writers as appropriate. - Many computations are Burst-compiled and expect data in native containers; avoid accessing UnityEngine.Object or managed state from the jobs. - The land-value grid uses smoothing (lerp) and threshold checks (delta >= 0.1) before writing changes to limit frequent small updates.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Typical usage: query a cell index and center.
    float3 somePosition = new float3(100f, 0f, -50f);
    int cellIndex = LandValueSystem.GetCellIndex(somePosition);
    float3 cellCenter = LandValueSystem.GetCellCenter(cellIndex);

    // You may want to store or use TextureSize to iterate the grid:
    int2 texSize = this.TextureSize; // yields (128,128) by default.
}