Skip to content

Game.Simulation.AdjustWaterConsumptionSystem

Assembly:
Namespace: Game.Simulation

Type: class

Base: GameSystemBase

Summary:
AdjustWaterConsumptionSystem updates the wanted water consumption of buildings each simulation update slice. It computes per-building water demand from prefab consumption data, installed upgrades, city water fees, building state (inactive/park/storage), renters/household multipliers, and randomness. When a building's wanted consumption changes the system enqueues related road/water-pipe edges for update and updates connected water pipe edge capacities. The work is performed in a parallel IJobChunk (AdjustWaterConsumptionJob) and a follow-up IJob (UpdateEdgesJob) that adjusts aggregated edge capacities for non-connected buildings. The system runs on a staggered update interval (128) to distribute full updates across frames.


Fields

  • private const int kFullUpdatesPerDay = 128
    Controls the update interval used by the system; the system expects at least 128 update interval so each building gets fully updated once per day (constant used to compute update slices).

  • private SimulationSystem m_SimulationSystem
    Cached reference to the SimulationSystem (used for frame index and simulation context).

  • private CitySystem m_CitySystem
    Cached reference to the CitySystem (used to access the city entity and related city-level data such as service fees).

  • private WaterPipeFlowSystem m_WaterPipeFlowSystem
    Cached reference to the WaterPipeFlowSystem (used to find the sink node and flow graph helpers).

  • private EntityQuery m_ConsumerQuery
    EntityQuery targeting buildings with WaterConsumer (and required components). Used to schedule the chunk job across consumer entities.

  • private TypeHandle __TypeHandle
    Internal struct holding ComponentTypeHandle / BufferTypeHandle / ComponentLookup / BufferLookup instances used by jobs. Populated on creation for efficient job access.

  • private EntityQuery __query_1300465010_0
    Internal query used to get the singleton ServiceFeeParameterData (includes water fee consumption multiplier curve).

  • private EntityQuery __query_1300465010_1
    Internal query used to get the singleton BuildingEfficiencyParameterData (includes water fee efficiency factor curve).

Properties

  • None

Constructors

  • public AdjustWaterConsumptionSystem()
    Default constructor. System initialization and dependency resolution happen in OnCreate.

Methods

  • public override int GetUpdateInterval(SystemUpdatePhase phase)
    Returns the number of frames between full updates for this system. This system uses 128 to spread updates across frames.

  • public override int GetUpdateOffset(SystemUpdatePhase phase)
    Returns the update offset within the interval. The system uses 64 so updates are staggered relative to other systems.

  • protected override void OnCreate()
    Initializes the system: asserts update interval, acquires SimulationSystem/CitySystem/WaterPipeFlowSystem, builds the consumer EntityQuery and registers required singletons (ServiceFeeParameterData and BuildingEfficiencyParameterData). Also calls RequireForUpdate for the consumer query and required parameter singletons.

  • public static float GetFeeConsumptionMultiplier(float relativeFee, in ServiceFeeParameterData feeParameters)
    Evaluates and returns the water consumption multiplier from service fee parameters for a given relative fee. Used to scale base consumption based on the city's water fee level.

  • public static float GetFeeEfficiencyFactor(float relativeFee, in BuildingEfficiencyParameterData efficiencyParameters)
    Evaluates and returns the efficiency factor used for building efficiency bookkeeping based on the water fee and parameter curves.

  • protected override void OnUpdate()
    Main update entry. Creates a NativeQueue for updated edges, computes the current updateFrame slice, schedules AdjustWaterConsumptionJob as a parallel IJobChunk over m_ConsumerQuery, then schedules UpdateEdgesJob to process the queued edges and update flow edge capacities. Disposes the NativeQueue as a dependency.

  • private void __AssignQueries(ref SystemState state)
    Internal helper to construct the internal EntityQuery instances used to fetch singletons (ServiceFeeParameterData, BuildingEfficiencyParameterData). Called during compiler-specific OnCreateForCompiler path.

  • protected override void OnCreateForCompiler()
    Compiler/serialization helper called in some build flows. Ensures queries and type handles are assigned for the compiled class.

  • private struct TypeHandle
    Holds all ComponentTypeHandle, BufferTypeHandle, ComponentLookup, and BufferLookup fields used by the jobs. It exposes __AssignHandles to initialize these handles from a SystemState.

Nested job types (brief):

  • public struct AdjustWaterConsumptionJob : IJobChunk
    Chunk job that iterates consumer building chunks and:
  • Filters by shared UpdateFrame index to only operate on the slice for this frame.
  • Reads prefab consumption (ConsumptionData) and applies installed upgrades.
  • Applies inactive/park/storage special handling and renter consumption multipliers.
  • Applies fee-based consumption multiplier and efficiency factor.
  • Computes wanted consumption (with random rounding) and writes into WaterConsumer.m_WantedConsumption.
  • Enqueues related road edges into a NativeQueue when consumption changes.
  • Updates connected WaterPipeEdge capacities directly when a WaterPipeBuildingConnection exists.
  • Updates Efficiency buffer entries with the fee-based efficiency factor.

The job uses numerous ComponentLookup/BufferLookup fields passed from the system to access other components (citizens, employees, spawnable data, flow edges, etc).

  • private struct UpdateEdgesJob : IJob
    Single job that:
  • Dequeues unique edges from the NativeQueue and for each attempts to find the corresponding water pipe flow edge that connects to the sink.
  • If found, sets both m_FreshCapacity and m_SewageCapacity on the flow edge to the sum of consumption of non-connected buildings for that edge.
  • Uses internal helpers and lookups (NodeConnection, ConnectedBuilding buffers, WaterConsumer lookup) to compute the sum for non-connected buildings.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // The system asserts update interval and initializes queries and cached references.
    // This example is the system's own OnCreate; other systems typically acquire
    // system references with World.GetOrCreateSystemManaged<T>().
}