Skip to content

Game.Simulation.AreaLotSimulationSystem

Assembly:
Namespace: Game.Simulation

Type: class

Base: GameSystemBase

Summary:
AreaLotSimulationSystem is a game simulation system responsible for handling area "lots" (extractors, storages, cargo transport stations) in Cities: Skylines 2. It manages spawning and updating work vehicles for lots, extracting natural resources (ore, oil, fish, fertile land, wood), scheduling pathfinding for lot-related vehicle operations, and coordinating with other world systems (city, terrain, water, pathfinding, resources). The system is update-rate limited (UPDATE_INTERVAL = 512) and uses Burst jobs and the DOTS job system to run heavy work in parallel. It also integrates with PathfindSetupSystem and an EndFrameBarrier to produce entity command buffers.


Fields

  • private const uint UPDATE_INTERVAL = 512u
    Defines the update interval (in simulation ticks/frames) for the system. The system reports this interval through GetUpdateInterval to control how frequently it runs.

  • private Game.Objects.SearchSystem m_ObjectSearchSystem
    Reference to the object search system used for area updates that need object queries (e.g., trees, plants).

  • private Game.Areas.SearchSystem m_AreaSearchSystem
    Reference to the area search system. Used to query nearby/overlapping areas when extracting resources or updating area-dependent data.

  • private NaturalResourceSystem m_NaturalResourceSystem
    Provides access to natural resource data (cell maps for ore/oil/fish/fertility/wood) and writers for resource updates.

  • private PathfindSetupSystem m_PathfindSetupSystem
    Used to enqueue pathfinding setup requests (SetupQueue) for vehicles spawned by lots.

  • private CitySystem m_CitySystem
    Reference to the current city entity (and city-level data) used when applying city modifiers to resource extraction.

  • private CityConfigurationSystem m_CityConfigurationSystem
    Used by WorkVehicleSelectData to determine vehicle selection parameters based on city config.

  • private TerrainSystem m_TerrainSystem
    Used when area updates require terrain height data.

  • private WaterSystem m_Watersystem
    Used when area updates or vehicle spawning need water surface information (e.g., watercraft).

  • private GroundWaterSystem m_GroundWaterSystem
    Provides groundwater data used by area resource updating logic.

  • private EndFrameBarrier m_EndFrameBarrier
    Barrier system used to create a parallel EntityCommandBuffer for jobs that issue structural changes (spawn vehicles, add/remove components).

  • private EntityQuery m_AreaQuery
    EntityQuery that matches entities representing lots with Extractor, Storage, or CargoTransportStation components (used to require the system update).

  • private EntityQuery m_ExtractorQuery
    EntityQuery for extractor lots specifically (used by the ExtractResources job path).

  • private EntityQuery m_VehiclePrefabQuery
    EntityQuery used by WorkVehicleSelectData to find eligible vehicle prefabs for spawning.

  • private EntityQuery m_ExtractorParameterQuery
    EntityQuery used to obtain extractor-related parameter data (e.g., consumption parameters).

  • private WorkVehicleSelectData m_WorkVehicleSelectData
    Helper object that encapsulates vehicle selection and creation logic used when spawning work vehicles.

  • private TypeHandle __TypeHandle
    Generated struct that caches Entity/Component type handles and Buffer/Component lookups used by jobs in this system. Populated in OnCreateForCompiler.


Properties

  • No public properties. The system exposes no public set/get properties for mod usage.

Constructors

  • public AreaLotSimulationSystem()
    Default constructor. The system initializes nothing heavy in the constructor; real initialization is done in OnCreate.

Methods

  • public override int GetUpdateInterval(SystemUpdatePhase phase)
    Returns the system update interval. This system returns the constant UPDATE_INTERVAL (512). The ECS scheduler can use this to reduce update frequency.

  • [Preserve] protected override void OnCreate()
    Initializes references to required world systems (ObjectSearchSystem, AreaSearchSystem, NaturalResourceSystem, PathfindSetupSystem, CitySystem, CityConfigurationSystem, TerrainSystem, WaterSystem, GroundWaterSystem, EndFrameBarrier) and constructs WorkVehicleSelectData. Also creates EntityQueries for areas and extractors and marks the system as required when the area query matches (RequireForUpdate).

  • [Preserve] protected override void OnUpdate()
    Main update method. High-level behavior:

  • Prepares WorkVehicleSelectData (preparing vehicle prefab selection).
  • Schedules ManageVehiclesJob as a parallel IJobChunk to process lots and owned vehicles:
    • Spawns vehicles when lots have accumulated enough work.
    • Updates owned vehicle buffers and checks work progress.
    • Enqueues pathfinding setup requests when needed via PathfindSetupSystem.
    • Uses an EndFrameBarrier command buffer for entity modifications and vehicle creation.
  • If extractor lots exist, schedules ExtractResourcesJob and a follow-up AreaResourceSystem.UpdateAreaResourcesJob to:
    • Extract natural resources from the map cell data.
    • Update area resources and notify other search systems.
  • Wires job dependencies into the world systems (AreaSearchSystem, ObjectSearchSystem, NaturalResourceSystem, TerrainSystem, WaterSystem, GroundWaterSystem).
  • Updates base.Dependency to the scheduled job handle.

  • public static int GetUnlimitedTotalAmount(int used, int originalAmount, float mu)
    Utility method to compute an "unlimited" total amount for resource consumption formulae. It wraps a logarithmic formula used to compute usage limits. Useful for mods that need to compute the same unbounded resource consumption metric used by extraction logic.

  • [Preserve] protected override void OnCreateForCompiler()
    Internal initialization used by compiled code paths: assigns query state and type handles by calling __AssignQueries and the generated TypeHandle.__AssignHandles.

  • private void __AssignQueries(ref SystemState state)
    Generated helper for query assignment (empty in this build but present for compiler pipeline).

Nested job types and key job functions (summary):

  • ManageVehiclesJob (IJobChunk, [BurstCompile])
  • Purpose: main job that handles vehicle management for lots in parallel over archetype chunks.
  • Key responsibilities:
    • When PathInformation is present on a lot, attempts to spawn vehicles from path data (path-based spawn).
    • Otherwise iterates owned vehicles, updates WorkVehicleData contributions to lot work counters, finds targets/routes, enqueues pathfinding, and spawns vehicles when accumulated work thresholds are reached.
    • Uses many lookups (PrefabRef, WorkVehicleData, Prefab data types, buffer lookups) to decide spawn behavior.
    • Important helper methods inside job:
    • CheckVehicle(...) — consumes vehicle capacity into lot's work amount and updates pending counters.
    • HasNavigation(...) / HasNavigationSelf(...) — determines whether an area or its subareas allow navigation for a road type.
    • FindTarget(...) (multiple overloads) — finds a destination waypoint or area location and enqueues pathfinding through m_PathfindQueue; if a route exists, it may spawn vehicles directly with route information.
    • TrySpawnVehicle(...) / SpawnVehicle(...) — attempts to create a work vehicle using WorkVehicleSelectData; if successful, configures Owner, Target, CurrentRoute or Path buffer on the created vehicle.
  • Outputs structural/entity changes via m_CommandBuffer (EndFrameBarrier).

  • ExtractResourcesJob (IJob, [BurstCompile])

  • Purpose: performs natural resource extraction for extractor lots, reading extractor data and the map's natural resource cell map.
  • Key responsibilities:
    • Iterates extractor lots (chunks provided), and for non-forest map features with extracted amount >= threshold, samples triangles and underlying natural resource cells to pick extraction targets.
    • For each cell chosen, consumes resource usage values depending on feature type and extractor parameters, updating m_NaturalResourceData cell usage and decrementing the extractor's m_ExtractedAmount.
    • For forest (wood) feature: ensures area updates are added to the update list to cause a full update later (handled by AreaResourceSystem.UpdateAreaResourcesJob).
    • Uses helper GetUnlimitedUsage(...) for ore/oil to model consumption scaling based on concentration and extractor parameters.
  • Produces m_UpdateList of areas to update; the system then schedules AreaResourceSystem.UpdateAreaResourcesJob to apply geometry/object/tree updates for changed areas.

  • TypeHandle (generated struct)

  • Contains cached ComponentTypeHandle, BufferTypeHandle, ComponentLookup and BufferLookup instances for all components/buffers used by the jobs in this system. Populated by __AssignHandles and used when scheduling jobs to create job data handles.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Example of how the AreaLotSimulationSystem initializes required systems.
    m_ObjectSearchSystem = base.World.GetOrCreateSystemManaged<Game.Objects.SearchSystem>();
    m_AreaSearchSystem = base.World.GetOrCreateSystemManaged<Game.Areas.SearchSystem>();
    m_NaturalResourceSystem = base.World.GetOrCreateSystemManaged<NaturalResourceSystem>();
    m_PathfindSetupSystem = base.World.GetOrCreateSystemManaged<PathfindSetupSystem>();
    m_CitySystem = base.World.GetOrCreateSystemManaged<CitySystem>();
    m_EndFrameBarrier = base.World.GetOrCreateSystemManaged<EndFrameBarrier>();
    // Prepare WorkVehicleSelectData to be used during OnUpdate for spawning vehicles.
    m_WorkVehicleSelectData = new WorkVehicleSelectData(this);
}

Notes and modding tips: - If you mod vehicle prefabs or the vehicle selection pipeline, ensure WorkVehicleSelectData and the m_VehiclePrefabQuery are kept consistent so the system can correctly create work vehicles for lots. - The system uses EndFrameBarrier for structural changes — if you need to observe created vehicles immediately, read from the same barrier or add a dependent system tied to the barrier/job handle. - Natural resource cell updates are done through NaturalResourceSystem and the CellMapData; when modifying resource cell behavior, consider both ExtractResourcesJob logic and AreaResourceSystem.UpdateAreaResourcesJob so area visuals/objects stay consistent. - The ManageVehiclesJob contains many internal decisions (map feature types, work thresholds of 1000f, multipliers from CargoTransportStationData). Mods changing these data pieces should account for interaction with this system.