Skip to content

Game.Simulation.TaxiStandSystem

Assembly:
Assembly-CSharp.dll (game runtime assembly containing the ECS systems and gameplay logic)

Namespace:
Game.Simulation

Type:
public class TaxiStandSystem

Base:
GameSystemBase

Summary:
Manages Taxi Stand entities in the ECS world. This system runs on a fixed update interval (UPDATE_INTERVAL = 256) and performs the per-stand logic in a Burst-compiled IJobChunk (TaxiStandTickJob). Responsibilities include: - Ensuring a taxi stand has the correct number of vehicles (and requesting new vehicles when needed). - Maintaining dispatched taxi requests and cleaning up invalid requests. - Applying city-level modifiers such as paid taxi starting fees to stands. - Creating TaxiRequest entities (with ServiceRequest / RequestGroup) when new vehicles should be requested. - Using an EndFrameBarrier command buffer to create entities and add components in a thread-safe manner.

The main work is performed in the nested TaxiStandTickJob which iterates archetype chunks matching the stand query and manipulates buffers/components such as RouteVehicle, DispatchedRequest, TaxiStand, WaitingPassengers and others.


Fields

  • public const uint UPDATE_INTERVAL
    Constant update interval used by the system. Value: 256. The system overrides GetUpdateInterval to return this value so the system is ticked only every 256 frames (or update units), reducing work frequency.

  • private EntityQuery m_StandQuery
    EntityQuery used to select Taxi Stand entities the system updates. Query requirements: TaxiStand (ReadWrite), TransportStop (ReadOnly), excludes Temp and Deleted.

  • private EntityArchetype m_VehicleRequestArchetype
    Archetype used when creating new taxi request entities. It contains components ServiceRequest, TaxiRequest and RequestGroup.

  • private CitySystem m_CitySystem
    Cached reference to the CitySystem (used to get the global city Entity and city data needed for modifiers like paid taxi start fee).

  • private EndFrameBarrier m_EndFrameBarrier
    Reference to the EndFrameBarrier system used to get a parallel command buffer for safe structural changes from the Burst Job.

  • private TypeHandle __TypeHandle
    Internal container of component/buffer/entity type handles used by the system and populated in OnCreateForCompiler. It holds handles passed into the TaxiStandTickJob.


Properties

This type exposes no public properties. (All important data is exposed via methods/fields and the nested job.)


Constructors

  • public TaxiStandSystem()
    Default constructor. The system initializes and will set up queries, archetypes and cached system references in OnCreate.

Methods

  • public override int GetUpdateInterval(SystemUpdatePhase phase)
    Returns the system update interval. This system returns 256 (UPDATE_INTERVAL) so it runs periodically rather than every frame.

  • [Preserve] protected override void OnCreate()
    Initializes system state:

  • Obtains CitySystem and EndFrameBarrier from the world.
  • Builds the query for taxi stands (ReadWrite TaxiStand, ReadOnly TransportStop, excluding Temp and Deleted).
  • Creates the VehicleRequest archetype (ServiceRequest, TaxiRequest, RequestGroup).
  • Calls RequireForUpdate to ensure the system only runs when matching entities exist.

  • [Preserve] protected override void OnUpdate()
    Creates and schedules the Burst-compiled TaxiStandTickJob (IJobChunk) in parallel with all the required ComponentTypeHandles, BufferLookups and component lookups set. It attaches the job's handle to the EndFrameBarrier producer (AddJobHandleForProducer) and assigns the job handle to base.Dependency.

The job: - Reads City options and applied modifiers (TaxiStartingFee) to compute and apply starting fee to each stand (and mark PathfindUpdated component when changed). - Validates RouteVehicle buffers (removes entries for vehicles no longer on the route). - Validates DispatchedRequest buffers (removes requests whose TaxiRequest component no longer exists). - If a stand is under capacity, sets RequireVehicles flag and enqueues TaxiRequest entities (using the archetype) to request new vehicles (uses RequestGroup with a group size of 16). The job populates district data for the request by traversing the lane/owner chain using CurrentDistrict/BorderDistrict/Owner lookups.

  • protected override void OnCreateForCompiler()
    Compiler helper that assigns Entity/Component type handles for the system via the __TypeHandle and sets up queries. Called by the generated code path in this project.

  • private void __AssignQueries(ref SystemState state)
    Internal helper for generated/compiled code. In this implementation it creates an empty EntityQueryBuilder and disposes it (placeholder used by code-generation paths).

Nested job methods (inside TaxiStandTickJob) — key behavior implemented in the job:

  • Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    Main per-chunk loop. Iterates entities in the chunk and performs the per-stand logic described above (vehicle checking, request checking, create vehicle requests, apply starting fee).

  • CheckVehicles(Entity route, DynamicBuffer<RouteVehicle> vehicles, out int count)
    Iterates the RouteVehicle buffer for a route and removes entries for vehicles that are no longer following that route. Returns the count of remaining valid vehicles.

  • CheckRequests(ref TaxiStand taxiStand, DynamicBuffer<DispatchedRequest> requests)
    Cleans up the dispatched request buffer by removing requests whose TaxiRequest entity is gone. If the taxiStand has a TaxiRequest component that is in the Dispatched state, the request is added to the buffer and the taxiStand.m_TaxiRequest is reset to Entity.Null.

  • RequestNewVehicleIfNeeded(int jobIndex, Entity entity, Entity lane, TaxiStand taxiStand, int priority)
    If the taxiStand does not already have a taxi request, builds a new TaxiRequest entity using the provided archetype, sets TaxiRequest data (including source stand entity, district info and priority) and RequestGroup. Uses the EndFrameBarrier command buffer (m_CommandBuffer) as a ParallelWriter to create the entity and set components.

  • GetDistricts(Entity entity, out Entity district1, out Entity district2)
    Helper that resolves district(s) for a given entity by checking BorderDistrict, CurrentDistrict, and walking up Owner links until district info is found. Returns Null if none is found.


Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Cache systems used by TaxiStandSystem (this mirrors what the system does internally).
    m_CitySystem = World.GetOrCreateSystemManaged<CitySystem>();
    m_EndFrameBarrier = World.GetOrCreateSystemManaged<EndFrameBarrier>();

    // Typical TaxiStandSystem behavior (query/archetype setup) is handled inside the system.
}

Notes for modders: - If you want to alter taxi stand behavior, consider writing a system that runs on the same update interval and either: - Modifies TaxiStand components (flags, starting fee) before TaxiStandSystem runs, or - Runs after TaxiStandSystem and reacts to PathfindUpdated or created TaxiRequest entities. - Use the same archetype components (TaxiRequest / ServiceRequest / RequestGroup) when interacting with taxi request entities to match game expectations. - TaxiStandTickJob is Burst-compiled and uses parallel command buffer operations; structural changes should be performed via EndFrameBarrier/command buffers for thread safety.