Skip to content

Game.UI.InGame.DispatchedVehiclesSection

Assembly: Assembly-CSharp
Namespace: Game.UI.InGame

Type: class

Base: InfoSectionBase

Summary:
Section that collects and displays vehicles currently dispatched to the selected entity (building/citizen/event). Uses a Burst-compiled IJobChunk (CollectDispatchedVehiclesJob) to scan entities with ServiceDispatch buffers and a set of request/vehicle components (fire, police, ambulance, hearse, maintenance, public transport, etc.), builds a list of vehicle entities that are actively dispatched for requests related to the selected entity, then converts those entities to UI vehicle entries (VehiclesSection.UIVehicle) for display. Designed to run inside the game's ECS/SystemState model and is compiler-generated with [Preserve] attributes for in-game usage.


Fields

  • private EntityQuery m_ServiceDispatchQuery
    Holds the entity query used to enumerate entities that have Vehicle and ServiceDispatch components (and are not Deleted/Temp). Initialized in OnCreate.

  • private NativeList<Entity> m_VehiclesResult
    NativeList used by the job to accumulate matching vehicle entities. Allocated with Allocator.Persistent in OnCreate and disposed in OnDestroy.

  • private TypeHandle __TypeHandle
    Struct grouping all EntityTypeHandle / BufferTypeHandle / ComponentLookup handles used to execute the CollectDispatchedVehiclesJob. Populated in OnCreateForCompiler via __AssignHandles.

  • private NativeList<VehiclesSection.UIVehicle> vehicleList { get; set; }
    NativeList of the UI vehicle entries produced in OnProcess by calling VehiclesSection.AddVehicle for each vehicle entity found. Allocated in OnCreate and disposed in OnDestroy.

  • private struct CollectDispatchedVehiclesJob
    Nested Burst-compiled IJobChunk implementation that scans chunks for vehicles and their ServiceDispatch buffers, inspects request components and vehicle-specific data (request counts or Dispatched flags), and appends matching vehicles to m_VehiclesResult. Uses many ComponentLookup<...> fields in read-only mode.

  • private struct TypeHandle
    Nested struct that groups and assigns all required ECS handles (EntityTypeHandle, BufferTypeHandle, multiple ComponentLookup for request and vehicle components). Has __AssignHandles(ref SystemState state) to initialize handles.

Properties

  • protected override string group => "DispatchedVehiclesSection"
    Section grouping name used by the UI/InfoSection system.

  • protected override bool displayForDestroyedObjects => true
    Indicates the section should be shown for destroyed objects.

  • protected override bool displayForUpgrades => true
    Indicates the section should be shown for upgrade previews.

  • private NativeList<VehiclesSection.UIVehicle> vehicleList { get; set; }
    (See field entry) Backed property for the NativeList used to build the UI list.

Constructors

  • public DispatchedVehiclesSection()
    Default constructor (marked [Preserve] on lifecycle methods) — most initialization is done in OnCreate.

Methods

  • [Preserve] protected override void OnCreate()
    Initializes the m_ServiceDispatchQuery (Vehicle + ServiceDispatch, excluding Deleted/Temp), allocates m_VehiclesResult and vehicleList as persistent NativeLists. Also calls base.OnCreate().

  • [Preserve] protected override void OnDestroy()
    Disposes vehicleList and m_VehiclesResult, then calls base.OnDestroy(). Important to avoid native memory leaks.

  • protected override void Reset()
    Clears vehicleList and m_VehiclesResult. Called by the section lifecycle to reset state between uses.

  • private bool Visible()
    Returns true when there are any collected dispatched vehicles (m_VehiclesResult.Length > 0). Used to set base.visible.

  • [Preserve] protected override void OnUpdate()
    Creates and schedules the CollectDispatchedVehiclesJob (passing in the selectedEntity, all ComponentLookup/Handle instances via InternalCompilerInterface.Get... wrappers) against m_ServiceDispatchQuery, then calls Complete() to finish the job immediately. Sets base.visible according to Visible().

Notes: - The job is Burst-compiled and uses read-only ComponentLookup instances for safe multi-threaded access. - The job copies results into the persistent NativeList m_VehiclesResult which is then consumed in OnProcess.

  • protected override void OnProcess()
    Iterates m_VehiclesResult, calls VehiclesSection.AddVehicle(EntityManager, vehicle, vehicleList) to produce UI vehicle entries, and then sorts vehicleList.

  • public override void OnWriteProperties(IJsonWriter writer)
    Serializes vehicleList into JSON by calling VehiclesSection.BindVehicle for each UIVehicle. Writes array under property name "vehicleList".

  • [MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
    Compiler helper; currently creates and disposes an EntityQueryBuilder(Allocator.Temp) — present to satisfy generated code patterns.

  • protected override void OnCreateForCompiler()
    Compiler-time initialization hook that calls __AssignQueries(ref base.CheckedStateRef) and __TypeHandle.__AssignHandles(ref base.CheckedStateRef) to set up type handles and queries for use by the job.

  • private struct CollectDispatchedVehiclesJob.Execute(...)
    Detailed implementation: iterates chunk entities, skips duplicate vehicle entities already in m_VehiclesResult, reads vehicle-specific request counts or dispatched flags (FireEngine.m_RequestCount, PoliceCar.m_RequestCount, Ambulance flags, Hearse flags, etc.), iterates the ServiceDispatch buffer up to min(buffer.Length, requestCount) and for each ServiceDispatch inspects the referenced request entity. If the request component matches the selected entity via direct target/citizen or via event links (OnFire.Event, Destroyed.Event, AccidentSite.Event, InDanger.Event, CurrentBuilding.CurrentBuilding), the vehicle entity is added to m_VehiclesResult.

Important behavior: - Supports multiple request types: FireRescueRequest, PoliceEmergencyRequest, HealthcareRequest, EvacuationRequest, GarbageCollectionRequest, MaintenanceRequest. - Uses component relationships to detect whether a request is relevant to the currently selected entity (direct target/citizen or via event linking components). - Avoids adding duplicate vehicle entities.

Usage Example

// Example: how the section collects vehicles during the UI lifecycle.
// You typically don't instantiate this directly — the InfoSection system creates it.
// This snippet illustrates that OnCreate allocates lists and OnUpdate runs the job.

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // m_VehiclesResult and vehicleList are allocated here by the section,
    // so no extra setup is usually required in user code.
}

[Preserve]
protected override void OnUpdate()
{
    base.OnUpdate();
    // The section schedules the CollectDispatchedVehiclesJob and immediately completes it,
    // then sets base.visible based on whether any dispatched vehicles were found.
}

// After the job completes, OnProcess will call VehiclesSection.AddVehicle(...) for each found vehicle,
// and OnWriteProperties will serialize vehicleList into JSON for the UI.

{{ ADDITIONAL_INFO }} - Threading/memory: m_VehiclesResult and vehicleList are persistent NativeLists — ensure the section runs its OnDestroy to dispose them. The job is scheduled and then .Complete() is called in OnUpdate, so job results are available synchronously in OnProcess. - Extension points: If you need to customize which dispatched vehicles show up, consider modifying or replacing the CollectDispatchedVehiclesJob logic or filtering vehicleList in OnProcess before sorting/writing. - Dependencies: This section relies on VehiclesSection utility methods (AddVehicle, BindVehicle) and many request/event/vehicle component types present in the game's ECS.