Game.FireEngineAISystem
Assembly: Assembly-CSharp.dll
Namespace: Game.Simulation
Type: class
Base: GameSystemBase
Summary:
Manages fire engine AI: dispatching, pathfinding, parking, extinguishing fires and rescue operations. The system schedules two Burst jobs each update: FireEngineTickJob (parallel IJobChunk) which processes every active fire engine entity (movement, dispatch selection, path setup, parking, start/stop, state transitions, queueing pathfinds and extinguish operations), and FireExtinguishingJob (IJob) which consumes queued extinguishing/rescue actions and updates OnFire, RescueTarget, Damaged and Destroyed components. It uses the game's static object search tree (NativeQuadTree) to find nearby on-fire/rescue objects, an EndFrameBarrier command buffer for structural ECS changes, and the PathfindSetupSystem to enqueue pathfind requests. Update frequency is throttled (GetUpdateInterval / GetUpdateOffset).
This system is central to how fire engines behave in Cities: Skylines 2: handling service dispatch lists, estimating empty tanks, returning to depot, merging appended paths from requests, stopping to extinguish/rescue, and applying water/damage/clearing deltas to target components via a queued, thread-safe mechanism.
Modding notes: - Most behavior is driven by FireEngineData (prefab), FireConfigurationData (global config), FireRescueRequest and OnFire/RescueTarget components — tweaking these influences how engines behave. - The system uses Burst-friendly jobs and ComponentLookup/BufferLookup; direct modifications to components from the main thread (EntityManager) are possible but be mindful of concurrency and scheduled jobs. - To create service requests for the fire system you can create entities with ServiceRequest + FireRescueRequest + RequestGroup component types (the system creates and uses such archetypes internally). - The system uses NativeQuadTree search; adding/removing static object entries should be done through the game's SearchSystem API to keep queries consistent.
Fields
-
private EndFrameBarrier m_EndFrameBarrier
Queue/command buffer barrier used to create an EntityCommandBuffer for scheduling structural changes produced by jobs. The jobs call m_EndFrameBarrier.CreateCommandBuffer().AsParallelWriter() to enqueue entity modifications safely for the end of the frame. -
private SimulationSystem m_SimulationSystem
Reference to the global SimulationSystem used to read the simulation frame index and other simulation-wide data. -
private PathfindSetupSystem m_PathfindSetupSystem
Used to acquire the pathfind setup queue (m_PathfindQueue) that FireEngineTickJob writes to when enqueuing pathfind work. -
private Game.Objects.SearchSystem m_ObjectSearchSystem
Provides the static NativeQuadTree search tree (m_ObjectSearchTree) used to query nearby objects (OnFire/RescueTarget/Destroyed). -
private EntityQuery m_VehicleQuery
Query that selects fire engine vehicle entities processed by the Tick job. Required to schedule the FireEngineTickJob. -
private EntityQuery m_ConfigQuery
Query used to read FireConfigurationData singleton used to configure structural integrity and other fire-related settings. -
private EntityArchetype m_FireRescueRequestArchetype
Archetype used to create FireRescueRequest service request entities (ServiceRequest + FireRescueRequest + RequestGroup). -
private EntityArchetype m_HandleRequestArchetype
Archetype used to create HandleRequest entities (HandleRequest + Game.Common.Event), which the system uses to mark that a vehicle will handle a specific request. -
private ComponentTypeSet m_MovingToParkedCarRemoveTypes
Set of component types to remove when transitioning a moving car into a parked state (e.g., Moving, TransformFrame, PathElement, PathInformation, ServiceDispatch, etc.). -
private ComponentTypeSet m_MovingToParkedAddTypes
Set of component types to add when parking a vehicle (ParkedCar, Stopped, Updated). -
private EventHelpers.StructuralIntegrityData m_StructuralIntegrityData
Helper used to consultar structural integrity values for prefabs (affects extinguishing scaling and water damage calculations). -
private TypeHandle __TypeHandle
Internal type handle struct containing ComponentTypeHandles / BufferTypeHandles / ComponentLookup references used by the jobs. Assigned on creation.
Properties
- None (no public properties exposed by this type)
Constructors
public FireEngineAISystem()
Default public constructor. The system initializes references and queries in OnCreate rather than the constructor.
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
Returns 16 — the system updates once every 16 simulation ticks (throttled to reduce per-frame cost). -
public override int GetUpdateOffset(SystemUpdatePhase phase)
Returns 4 — offset aligning update schedule. -
protected override void OnCreate()
Initializes system dependencies and queries: - Gets EndFrameBarrier, SimulationSystem, PathfindSetupSystem and SearchSystem.
- Creates m_VehicleQuery which selects fire-engine vehicles (reads/writes CarCurrentLane, Owner, PrefabRef, PathOwner, Game.Vehicles.FireEngine, Target and excludes Deleted/Temp/TripSource/OutOfControl).
- Creates archetypes used for FireRescueRequest and HandleRequest entities.
- Initializes component type sets for parking transitions and the structural integrity helper.
-
Calls RequireForUpdate(m_VehicleQuery) so the system runs only when there are relevant vehicles.
-
protected override void OnUpdate()
Main update: reads FireConfigurationData, constructs a NativeQueueto pass actions from the parallel Tick job to a single-threaded consumer job, updates structural integrity helper, schedules: - FireEngineTickJob (parallel) — processes fire engine entities, enqueues pathfind requests and extinguishing/rescue queue entries, writes to EndFrameBarrier command buffer and PathfindSetupSystem queue.
- FireExtinguishingJob (single-threaded) — consumes m_ExtinguishingQueue and applies mutations to OnFire, RescueTarget, Damaged, Destroyed components.
-
Registers dependencies with m_EndFrameBarrier, m_ObjectSearchSystem and m_PathfindSetupSystem, and disposes the NativeQueue when jobs complete.
-
private void __AssignQueries(ref SystemState state)
Internal compiler helper (generated) — used during OnCreateForCompiler. No mod usage. -
protected override void OnCreateForCompiler()
Internal helper used by generated code to assign type handles for the jobs; assigns ComponentTypeHandles and lookups via __TypeHandle.__AssignHandles(ref base.CheckedStateRef). -
Nested structs:
-
FireExtinguishing (struct)
Simple POD used to queue extinguishing/rescue operations from the parallel job into the single-thread FireExtinguishingJob. Carries vehicle, target, optional request entity and delta values (fire intensity delta, water damage delta, destroyed clear delta). -
FireEngineTickJob : IJobChunk (BurstCompile)
The main parallel job processing each fire engine. Responsibilities:- Iterate over vehicle chunks and call Tick() per vehicle.
- Tick() handles path resets, reaching path ends, parking logic, stopping/starting vehicles, selecting/assigning dispatches, beginning extinguishing/rescue, returning to depot, estimating empty tanks, requesting targets if needed, queuing pathfind requests, and enqueuing extinguishing/rescue queue entries into m_ExtinguishingQueue.
- Uses two helper iterators (ObjectRequestIterator/ObjectExtinguishIterator) that implement the game's NativeQuadTree iterator interfaces to search nearby objects and either enqueue a RescueRequest bound to a nearby on-fire/rescue object or compute extinguish/clear/water-damage deltas and enqueue FireExtinguishing entries.
- Uses many ComponentLookup and BufferLookup instances exposed via the job struct to read/write components and append to m_PathfindQueue or m_CommandBuffer.
Important internal helpers: - Tick(...) — per-vehicle main logic. - CheckParkingSpace(...) — validates parking spaces when path exists. - ParkCar(...) — transitions vehicle into parked state (clears emergency, sets parked amount). - EndNavigation(...) — finalize path end and clear navigation lanes. - StopVehicle(...) / StartVehicle(...) — manage components for stop/start. - FindNewPath(...) — prepare PathfindParameters and call VehicleUtils.SetupPathfind to enqueue a SetupQueueItem. - CheckServiceDispatches(...) — choose highest priority suitable request to add to serviceDispatches buffer for this vehicle. - RequestTargetIfNeeded(...) — occasionally creates a FireRescueRequest entity if the vehicle needs more targets (creates entity via m_CommandBuffer with m_FireRescueRequestArchetype). - SelectNextDispatch(...) — chooses next target to handle from serviceDispatches, creates HandleRequest entity and appends path data or sets a direct target. - BeginExtinguishing(...) — stops vehicle and sets Extinguishing/Rescueing flags when in range of a valid target. - ReturnToDepot(...) — clears dispatch buffer and sets Returning flag; sets the owner building as target. - ResetPath(...) — resets internal path element buffers and parking state when a path update occurs. - IsCloseEnough(...) — helper distance test to target using Transform components. - TryExtinguishFire(...) — builds an ObjectExtinguishIterator, uses the search tree to find nearby entities to affect, computes extinguish/clear/waterDamage deltas using prefab data and structural integrity, enqueues FireExtinguishing entries and decrements the vehicle's extinguishing amount. - TryAddRequests(...) — when engine is actively extinguishing/rescuing, searches surroundings for additional objects that should be bound to the same FireRescueRequest, by enqueuing FireExtinguishing entries with the request set.
-
FireExtinguishingJob : IJob (BurstCompile)
Consumes the NativeQueueproduced by the parallel job. For each dequeued FireExtinguishing: - If m_Request is not null, it sets the OnFire.m_RescueRequest or RescueTarget.m_Request to link the object to the service request.
- Applies m_FireIntensityDelta to OnFire.m_Intensity (clamped >= 0).
- Applies m_WaterDamageDelta to Damaged.m_Damage.z (clamped to <= 0.5).
- Applies m_DestroyedClearDelta to Destroyed.m_Cleared (clamped to <= 1). This job centralizes component writes that must not happen in parallel for the same target.
-
Other internal / generated methods
- TypeHandle.__AssignHandles(ref SystemState state) — assigns ComponentTypeHandles/Lookups used by the jobs (internal).
Usage Example
Create a FireRescueRequest entity (example pattern the system expects). This is how you can request fire/rescue service for a target entity from other code / a mod:
// Create a fire/rescue service request for 'targetEntity'
Entity requestEntity = EntityManager.CreateEntity(
typeof(ServiceRequest),
typeof(FireRescueRequest),
typeof(RequestGroup)
);
// Mark the service request as reversed (same pattern used in the system)
EntityManager.SetComponentData(requestEntity, new ServiceRequest(reversed: true));
// FireRescueRequest(targetEntity, priority, type) — example constructor as used in the game code
EntityManager.SetComponentData(requestEntity, new FireRescueRequest(targetEntity, 1f, FireRescueRequestType.Fire));
// Grouping (used by the system for selecting requests)
EntityManager.SetComponentData(requestEntity, new RequestGroup(4u));
Quick note on reading the system instance:
// From a managed system or MonoBehaviour with access to World
var fireAISystem = World.GetOrCreateSystemManaged<Game.Simulation.FireEngineAISystem>();
If you want to influence the extinguishing behavior, consider editing FireEngineData (prefab) or FireConfigurationData singleton values rather than changing this system's code; the system consumes those data structures to compute rates and capacities.