Skip to content

Game.Simulation.WaterPumpingStationAISystem

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

Type: class WaterPumpingStationAISystem

Base: GameSystemBase

Summary:
System responsible for processing water pumping station buildings each system tick. It reads pump prefab data, building components and connected water pipe edges, consumes groundwater / surface water sources, computes production capacity and pollution, updates flow edge capacities, and manages pump-related notifications (icons). The heavy per-building work is performed inside the nested Burst-compiled PumpTickJob (IJobChunk) for performance.


Fields

  • private GroundWaterSystem m_GroundWaterSystem
    Holds a reference to the GroundWaterSystem used to read/modify groundwater maps and consume groundwater when pumps operate.

  • private WaterSystem m_WaterSystem
    Reference to the WaterSystem used to read surface water data (WaterSurfaceData) needed for surface water pumping and depth/pollution sampling.

  • private IconCommandSystem m_IconCommandSystem
    Reference to IconCommandSystem used to add or remove notification/icon prefabs on pump buildings.

  • private EntityQuery m_PumpQuery
    EntityQuery used to select WaterPumpingStation entities for processing (requires WaterPumpingStation component, PrefabRef, Transform, WaterPipeBuildingConnection, excludes Temp and Deleted).

  • private EntityQuery m_ParameterQuery
    EntityQuery used to retrieve singleton WaterPipeParameterData (global parameters for water behavior).

  • private TypeHandle __TypeHandle
    Internal container of Entity/Component/Buffer type handles used to build and schedule the PumpTickJob.

Properties

  • This class exposes no public properties. The system is driven via OnCreate/OnUpdate and uses queries and nested job data.

Constructors

  • public WaterPumpingStationAISystem()
    Default parameterless constructor. The system performs setup in OnCreate (acquires references to other systems and entity queries).

Methods

  • public override int GetUpdateInterval(SystemUpdatePhase phase)
    Returns the update interval used by the system (128). Controls how often the system is scheduled relative to the simulation tick.

  • public override int GetUpdateOffset(SystemUpdatePhase phase)
    Returns the update offset used by the system (64). Used along with interval to distribute updates across frames.

  • [Preserve] protected override void OnCreate()
    Initializes the system: gets references to GroundWaterSystem, WaterSystem and IconCommandSystem; creates the entity queries for pumps and parameters; registers requirements for updating the system only when those queries have results.

  • [Preserve] protected override void OnUpdate()
    Creates and schedules the Burst-compiled PumpTickJob. It gathers required type/component lookups, obtains the water surface data and groundwater map, creates an IconCommandBuffer and passes the WaterPipeParameterData singleton. After scheduling, it registers writers/readers with the referenced systems so dependencies are tracked.

  • public static float GetSurfaceWaterAvailability(float3 position, AllowedWaterTypes allowedTypes, WaterSurfaceData waterSurfaceData, float effectiveDepth)
    Utility to compute normalized availability (0..1) of surface water at a given position based on water depth and an effective depth parameter.

  • [MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
    Internal helper used by the generated/compiled version of the system to assign up-to-date queries. (Usually compiler-generated and not intended for modder use.)

  • protected override void OnCreateForCompiler()
    Compiler-only helper that assigns component type handles and queries when building for the Job system.

Nested / Job methods (from PumpTickJob):

  • public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) (PumpTickJob)
    Main per-chunk worker. For each pump in the chunk it:
  • Reads prefab and pump data (WaterPumpingStationData).
  • Applies installed upgrades.
  • Reads connected WaterPipeEdge producer edge and current fresh flow into the pump.
  • Computes efficiency factors from building efficiency buffers.
  • Computes capacity and pollution considering allowed water types:
    • Consumes groundwater from the ground water map when groundwater pumping is allowed.
    • Samples and uses surface water sources (SubObjects) when surface water pumping is allowed.
  • Writes computed fresh capacity and pollution to the associated WaterPipeEdge.
  • Updates building efficiency factors and pump component fields.
  • Manages notifications (missing water, dirty water, not enough capacity) via IconCommandBuffer.

  • private void UpdateNotification(Entity entity, Entity notificationPrefab, bool enabled, DynamicBuffer<IconElement> iconElements) (PumpTickJob)
    Adds or removes a notification icon prefab for the given entity depending on the enabled flag using IconCommandBuffer.

  • private bool HasNotification(DynamicBuffer<IconElement> iconElements, Entity notificationPrefab) (PumpTickJob)
    Checks if a given notification prefab is present in the entity's IconElement buffer.


Usage Example

Example: using the static helper to sample surface water availability and using the system behavior description to understand pump capacity calculation.

// Query surface water availability at a position for SurfaceWater pumps:
float3 pumpPosition = new float3(100f, 0f, 200f);
float effectiveDepth = 10f; // typically taken from WaterPipeParameterData.m_SurfaceWaterPumpEffectiveDepth
float availability = WaterPumpingStationAISystem.GetSurfaceWaterAvailability(
    pumpPosition,
    AllowedWaterTypes.SurfaceWater,
    waterSystem.GetSurfaceData(out _), // obtain WaterSurfaceData from WaterSystem in your context
    effectiveDepth
);

// availability is clamped 0..1 and used by pump logic to scale capacity from surface water.

Notes for modders: - Pumping logic and notifications are burst-compiled and data-driven; to modify behavior, change WaterPumpingStationData (prefab data) or WaterPipeParameterData (global parameters). - Groundwater is modified via GroundWaterSystem and the system registers write access appropriately; be careful to respect system dependencies when writing custom systems that interact with groundwater or water surface data. - To add custom notifications or alter icon behavior, inspect IconCommandSystem and IconElement usage in PumpTickJob (Add/Remove via IconCommandBuffer).