Skip to content

Game.Simulation.TransportStationAISystem

Assembly:
Namespace: Game.Simulation

Type: class

Base: GameSystemBase

Summary:
System responsible for updating TransportStation components each simulation tick. It schedules a Burst-compiled IJobChunk (TransportStationTickJob) that reads prefab and upgrade data, evaluates building efficiency, applies combined upgrade stats, and updates runtime TransportStation values such as comfort, loading factor, available refuel types, and activity flags. The system runs on a coarse update interval (see GetUpdateInterval) and only operates for entities matching a TransportStation-only query (excluding temporary, deleted or service-upgrade-tagged entities).


Fields

  • private EntityQuery m_BuildingQuery
    Holds the query that matches TransportStation entities to be processed. It is created in OnCreate to require entities with Game.Buildings.TransportStation and to exclude Temp, Deleted, and ServiceUpgrade components.

  • private TypeHandle __TypeHandle
    Container for the ComponentTypeHandle/BufferTypeHandle/ComponentLookup instances used by the chunk job. Populated via __AssignHandles during compiler-time initialization (OnCreateForCompiler) and used on scheduling to fetch the correct handles from the SystemState.

Properties

  • None

Constructors

  • public TransportStationAISystem()
    Default parameterless constructor. Marked with [Preserve] on the class lifecycle methods; the constructor itself contains no custom initialization logic beyond the base constructor.

Methods

  • public override int GetUpdateInterval(SystemUpdatePhase phase)
    Returns the update interval used by this system. This implementation returns 256, making the system update on a slower cadence (every 256 ticks of the phase).

  • public override int GetUpdateOffset(SystemUpdatePhase phase)
    Returns the update offset. This implementation returns 0.

  • [Preserve] protected override void OnCreate()
    Creates the EntityQuery (m_BuildingQuery) that selects TransportStation entities and calls RequireForUpdate to ensure the system only runs when matching entities exist. The query excludes ServiceUpgrade, Temp, and Deleted components.

  • [Preserve] protected override void OnUpdate()
    Schedules the TransportStationTickJob (Burst-compiled) as a parallel IJobChunk over m_BuildingQuery. It fills the job's handles from __TypeHandle using InternalCompilerInterface.Get* helper wrappers and stores the returned JobHandle in base.Dependency.

  • protected override void OnCreateForCompiler()
    Called during compilation-time setup; it calls __AssignQueries and __TypeHandle.__AssignHandles to initialize internal query/handle state used by the generated scheduling code.

  • [MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
    Internal helper invoked from OnCreateForCompiler. In this generated code it creates and immediately disposes an EntityQueryBuilder; the method exists to allow the compiler-generated code to assign queries if needed.

  • private struct TypeHandle.__AssignHandles(ref SystemState state)
    Assigns and caches BufferTypeHandle/ComponentTypeHandle/ComponentLookup instances from the provided SystemState for:

  • BufferTypeHandle (read-only)
  • ComponentTypeHandle (read-only)
  • BufferTypeHandle (read-only)
  • ComponentTypeHandle (read-write)
  • ComponentLookup (read-only)
  • ComponentLookup (read-only)

  • private struct TransportStationTickJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    IJobChunk entry point. For each chunk it:

  • Retrieves NativeArray/BufferAccessors for PrefabRef, TransportStation and buffers for Efficiency and InstalledUpgrade.
  • Iterates entities in the chunk, fetches the TransportStationData from prefab lookups.
  • If installed upgrades exist, combines upgrade stats into a local TransportStationData copy via UpgradeUtils.CombineStats (uses prefab lookups).
  • Computes efficiency via BuildingUtils.GetEfficiency.
  • Calls the private Tick helper to apply the prefab (and modified) data and efficiency to the runtime TransportStation component.
  • Writes the modified TransportStation back to the component array.

  • private void TransportStationTickJob.Tick(PrefabRef prefabRef, ref Game.Buildings.TransportStation transportStation, TransportStationData prefabTransportStationData, float efficiency)
    Applies the per-station logic:

  • Sets m_ComfortFactor to prefab comfort factor multiplied by efficiency clamped to [0,1].
  • Sets m_LoadingFactor to max(0, (1 + prefab loading factor) * efficiency).
  • If efficiency > 0: copies refuel type sets (car/train/watercraft/aircraft) from prefab data and sets the TransportStopsActive flag.
  • Otherwise: clears refuel types to EnergyTypes.None and clears the TransportStopsActive flag.

  • void IJobChunk.Execute(...)
    Interface shim that calls the strongly-typed Execute defined above.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Builds the query to process transport station entities only
    m_BuildingQuery = GetEntityQuery(
        ComponentType.ReadOnly<Game.Buildings.TransportStation>(),
        ComponentType.Exclude<Game.Buildings.ServiceUpgrade>(),
        ComponentType.Exclude<Temp>(),
        ComponentType.Exclude<Deleted>()
    );
    RequireForUpdate(m_BuildingQuery);
}

[Preserve]
protected override void OnUpdate()
{
    // The system schedules a Burst IJobChunk that updates TransportStation components
    JobHandle dependency = JobChunkExtensions.ScheduleParallel(new TransportStationTickJob {
        m_EfficiencyType = InternalCompilerInterface.GetBufferTypeHandle(ref __TypeHandle.__Game_Buildings_Efficiency_RO_BufferTypeHandle, ref base.CheckedStateRef),
        m_PrefabRefType = InternalCompilerInterface.GetComponentTypeHandle(ref __TypeHandle.__Game_Prefabs_PrefabRef_RO_ComponentTypeHandle, ref base.CheckedStateRef),
        m_InstalledUpgradeType = InternalCompilerInterface.GetBufferTypeHandle(ref __TypeHandle.__Game_Buildings_InstalledUpgrade_RO_BufferTypeHandle, ref base.CheckedStateRef),
        m_TransportStationType = InternalCompilerInterface.GetComponentTypeHandle(ref __TypeHandle.__Game_Buildings_TransportStation_RW_ComponentTypeHandle, ref base.CheckedStateRef),
        m_PrefabRefData = InternalCompilerInterface.GetComponentLookup(ref __TypeHandle.__Game_Prefabs_PrefabRef_RO_ComponentLookup, ref base.CheckedStateRef),
        m_PrefabTransportStationData = InternalCompilerInterface.GetComponentLookup(ref __TypeHandle.__Game_Prefabs_TransportStationData_RO_ComponentLookup, ref base.CheckedStateRef)
    }, m_BuildingQuery, base.Dependency);
    base.Dependency = dependency;
}

Notes and modding tips: - The job is Burst-compiled and designed for parallel chunk processing. Keep managed allocations out of job data and use component lookups and handles. - Upgrades are applied per-entity by CombineStats using InstalledUpgrade buffer; ensure your custom upgrades populate that buffer in expected format. - Efficiency is read from an Efficiency dynamic buffer; if you change how efficiency is represented, you must update BuildingUtils.GetEfficiency or usage accordingly. - The system updates at an interval of 256 ticks; to change responsiveness for mods, override GetUpdateInterval or use a separate system with a different cadence.