Skip to content

Game.Simulation.SewageOutletAISystem

Assembly:
Namespace: Game.Simulation

Type: class

Base: GameSystemBase

Summary:
SewageOutletAISystem is an ECS system responsible for updating sewage outlet buildings each simulation tick. It schedules a Burst-compiled IJobChunk (OutletTickJob) that: - reads building prefab data and upgrades, - computes outlet capacity and purification based on building efficiency and prefab SewageOutletData, - updates connected water pipe edges (sewage capacity, last processed/purified amounts and flags), - updates any surface water source sub-objects (amount and pollution fraction), - and toggles in-world notification icons when sewage backup conditions occur. The system runs as a parallel JobChunk and writes icon commands via an IconCommandSystem command buffer. It uses ComponentLookup (formerly ComponentDataFromEntity) for flow edges and water sources and carefully combines upgrade stats with prefab data.


Fields

  • private IconCommandSystem m_IconCommandSystem
    This holds a reference to the IconCommandSystem used to create command buffers for adding/removing notification icons on building entities.

  • private EntityQuery m_OutletQuery
    EntityQuery selecting SewageOutlet entities to process. The query requires:

  • Game.Buildings.SewageOutlet (Read/Write)
  • WaterPipeBuildingConnection (ReadOnly)
  • PrefabRef (ReadOnly)
  • excludes Deleted and Temp. This query determines which entities the OutletTickJob will run over.

  • private EntityQuery m_ParameterQuery
    EntityQuery for reading the singleton WaterPipeParameterData, which supplies global parameters such as m_SurfaceWaterUsageMultiplier and notification prefabs.

  • private TypeHandle __TypeHandle
    Internal holder for all Entity/Component/Buffer type handles and ComponentLookup handles used when scheduling the job. Populated in OnCreateForCompiler / __AssignHandles and used to get runtime handles in OnUpdate.


Properties

  • This class exposes no public properties.

Constructors

  • public SewageOutletAISystem()
    Default constructor. The real initialization occurs in OnCreate(); this constructor is preserved for ECS construction.

Methods

  • public override int GetUpdateOffset(SystemUpdatePhase phase)
    Returns 64. Used by the engine to offset the system's execution within a phase for ordering.

  • public override int GetUpdateInterval(SystemUpdatePhase phase)
    Returns 128. Indicates the system's update interval; the system is intended to run at this cadence.

  • [Preserve] protected override void OnCreate()
    Creates or retrieves the IconCommandSystem, builds the outlet and parameter queries, and registers the outlet query as a requirement for update (RequireForUpdate). This ensures the system only runs when relevant entities exist.

  • [Preserve] protected override void OnUpdate()
    Constructs and populates an OutletTickJob with:

  • entity/component handles (EntityTypeHandle, ComponentTypeHandle and BufferTypeHandle)
  • ComponentLookup for SewageOutletData, PrefabRef, WaterPipeEdge, and WaterSourceData
  • an IconCommandBuffer from the IconCommandSystem
  • the WaterPipeParameterData singleton from m_ParameterQuery The job is scheduled in parallel over m_OutletQuery via JobChunkExtensions.ScheduleParallel and the IconCommandSystem is informed of the job dependency (AddCommandBufferWriter).

Job responsibilities (OutletTickJob.Execute): - Get per-entity prefab and building connections, read efficiencies and installed upgrades. - Combine upgrade stats into the SewageOutletData where applicable. - Compute last processed/purified/used amounts and capacity (capacity = round(efficiency * prefab capacity)). - Update connected WaterPipeEdge with sewage capacity and set last processed/purified counters on the building component. - Update any SubObject water sources' amount and pollution fraction using m_Parameters.m_SurfaceWaterUsageMultiplier. - Check flow edge flags for SewageBackup and add or remove the "not enough sewage capacity" notification via IconCommandBuffer. - Uses NativeDisableContainerSafetyRestriction on some ComponentLookup fields (m_FlowEdges, m_WaterSources) to allow writing in a job context.

The job is Burst-compiled and implements IJobChunk for good performance.

  • private void __AssignQueries(ref SystemState state)
    Stub used by compiler-time initialization. In this class it creates/cleans up an EntityQueryBuilder temporary; real handle assignment occurs elsewhere.

  • protected override void OnCreateForCompiler()
    Called during ECS codegen/compilation time flow. It calls __AssignQueries and delegates to __TypeHandle.__AssignHandles to prepare type handles used at runtime.

Nested job helper methods (inside OutletTickJob): - void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
Main IJobChunk execution function performing the per-chunk logic described above.

  • private void UpdateNotification(Entity entity, Entity notificationPrefab, bool enabled, DynamicBuffer<IconElement> iconElements)
    Adds or removes notification icon commands via m_IconCommandBuffer when the enabled state differs from the presence in iconElements. Relies on HasNotification to check existing icons.

  • private bool HasNotification(DynamicBuffer<IconElement> iconElements, Entity notificationPrefab)
    Checks whether the provided IconElement buffer already contains the given notification prefab.


Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Create or fetch the IconCommandSystem used to write icon add/remove commands
    m_IconCommandSystem = World.GetOrCreateSystemManaged<IconCommandSystem>();

    // Build queries: outlets and the parameters singleton
    m_OutletQuery = GetEntityQuery(
        ComponentType.ReadWrite<Game.Buildings.SewageOutlet>(),
        ComponentType.ReadOnly<WaterPipeBuildingConnection>(),
        ComponentType.ReadOnly<PrefabRef>(),
        ComponentType.Exclude<Deleted>(),
        ComponentType.Exclude<Temp>()
    );
    m_ParameterQuery = GetEntityQuery(ComponentType.ReadOnly<WaterPipeParameterData>());

    // Only run when there are outlets present
    RequireForUpdate(m_OutletQuery);
}

Notes & Modding tips: - If you need to change sewage behavior, consider editing SewageOutletData (prefab data), WaterPipeParameterData (global parameters), or intercepting/augmenting the OutletTickJob logic via a custom system scheduled before/after this system. - The system writes to WaterPipeEdge and WaterSourceData via ComponentLookup in a job — exercise care when modifying these data structures to avoid race conditions. - Notifications are managed via IconCommandSystem; to add custom notification prefabs, supply them through the WaterPipeParameterData or PrefabRef patterns used by the game.