Skip to content

Game.Simulation.FireAircraftAISystem

Assembly:
Game

Namespace:
Game.Simulation

Type:
public class

Base:
GameSystemBase

Summary:
FireAircraftAISystem is an ECS system responsible for the behavior of fire aircraft (helicopters) in the simulation. It handles dispatching, pathfinding setup, route selection, parking/return behavior, and the actual extinguishing/rescue logic. The system schedules two main jobs each update: - FireAircraftTickJob: iterates fire aircraft entities, updates state, requests paths, appends dispatches, and enqueues extinguishing/rescue actions. - FireExtinguishingJob: dequeues and applies extinguishing/rescue effects to OnFire, Damaged, Destroyed and RescueTarget components.

It uses a static object search tree to find objects in range of the helicopter's water spread. The system also maintains archetypes and component type sets required for creating/handling requests and moving aircraft between active and parked states. Update interval and offset are set for staggered execution within the simulation schedule.

Fields

  • private EndFrameBarrier m_EndFrameBarrier
    {{ The EndFrameBarrier used to create an EntityCommandBuffer. Jobs that produce EntityCommands use this barrier to safely enqueue changes for end-of-frame execution. }}

  • private SimulationSystem m_SimulationSystem
    {{ Reference to the simulation system used to access the simulation frame index and schedule-dependent logic. }}

  • private PathfindSetupSystem m_PathfindSetupSystem
    {{ PathfindSetupSystem used to enqueue pathfinding setup items (SetupQueueItem) generated by fire aircraft when they request new paths. }}

  • private Game.Objects.SearchSystem m_ObjectSearchSystem
    {{ Search system that provides a static quad-tree of objects for spatial queries (used to find fires/rescue targets in range of the aircraft). }}

  • private EntityQuery m_VehicleQuery
    {{ EntityQuery selecting fire aircraft entities (AircraftCurrentLane, Owner, PrefabRef, PathOwner, Game.Vehicles.FireEngine, Target, ...). The system requires this query to run an update. }}

  • private EntityQuery m_ConfigQuery
    {{ EntityQuery used to fetch FireConfigurationData (game configuration for fire behavior). }}

  • private EntityArchetype m_FireRescueRequestArchetype
    {{ Archetype used to create new FireRescueRequest entities (ServiceRequest, FireRescueRequest, RequestGroup). }}

  • private EntityArchetype m_HandleRequestArchetype
    {{ Archetype used to create handle-request entities for bookkeeping when a vehicle takes a dispatch (HandleRequest, Game.Common.Event). }}

  • private ComponentTypeSet m_MovingToParkedAircraftRemoveTypes
    {{ Set of component types removed from an aircraft when converting it from "moving" to "parked" (moving/navigation/path components). }}

  • private ComponentTypeSet m_MovingToParkedAddTypes
    {{ Set of component types added when parking an aircraft (ParkedCar, Stopped, Updated). }}

  • private EventHelpers.StructuralIntegrityData m_StructuralIntegrityData
    {{ Helper data wrapper used to get structural integrity values for prefabs when computing extinguishing/water damage effects on buildings/objects. }}

  • private TypeHandle __TypeHandle
    {{ Internal helper that stores EntityTypeHandle, ComponentTypeHandles, BufferTypeHandles and ComponentLookup handles used by the job scheduling code. It is initialized in OnCreateForCompiler and used to create the job structs. }}

Properties

  • This class does not expose public properties.
    {{ The system's interaction surface is via ECS (component data, archetypes, command buffers) rather than public CLR properties. Internal handles are stored in the private TypeHandle and used for job scheduling. }}

Constructors

  • public FireAircraftAISystem()
    {{ Default constructor. The system is a managed System that relies on OnCreate to initialize internal references (barriers, queries, archetypes, helper data). Typical usage is performed by the World (GetOrCreateSystemManaged). }}

Methods

  • public override int GetUpdateInterval(SystemUpdatePhase phase)
    {{ Returns the update interval in frames for this system. The implementation returns 16 (the system runs every 16 simulation frames). This is used to spread load across frames. }}

  • public override int GetUpdateOffset(SystemUpdatePhase phase)
    {{ Returns the update offset for scheduling within the update interval. The implementation returns 10. Combined with the interval this staggers execution among systems. }}

  • [Preserve] protected override void OnCreate()
    {{ Initializes the system: acquires EndFrameBarrier, SimulationSystem, PathfindSetupSystem, SearchSystem; builds entity queries; creates archetypes and component type sets; initializes structural integrity helper; calls RequireForUpdate to ensure the system runs only when relevant vehicles exist. }}

  • [Preserve] protected override void OnUpdate()
    {{ Main scheduling method. Reads FireConfigurationData, constructs a temporary NativeQueue for extinguishing operations, updates structural integrity data, builds and schedules:

  • FireAircraftTickJob (parallel JobChunk) that iterates relevant aircraft and enqueues pathfind requests, command buffer operations, and extinguishing queue items.
  • FireExtinguishingJob (single IJob) that consumes the queue and applies changes (modify OnFire intensity and rescue request, damaged water damage, destroyed cleared progress). The method wires up job dependencies to the PathfindSetupSystem, ObjectSearchSystem, EndFrameBarrier and disposes the temporary queue appropriately. }}

  • protected override void OnCreateForCompiler()
    {{ Internal helper invoked by compiled systems to assign query and type handles for Burst/Jobs usage. Initializes TypeHandle handles via __AssignHandles. }}

  • private void __AssignQueries(ref SystemState state)
    {{ Internal helper stub invoked by the compiler-generated code for entity query assignment. }}

  • Other important (private) helpers are implemented inside the nested FireAircraftTickJob:

  • Tick(...) — per-entity logic executed for each aircraft chunk.
  • ResetPath(...), ReturnToDepot(...), FindNewPath(...), ParkAircraft(...), CheckServiceDispatches(...), RequestTargetIfNeeded(...), SelectNextDispatch(...), BeginExtinguishing(...), CheckExtinguishing(...), TryExtinguishFire(...), TryAddRequests(...). {{ These methods implement the per-vehicle state machine: handling stuck vehicles, returning to depot, selecting/consuming service dispatches, initiating extinguishing/rescue state, calculating extinguishing rates and water damage, appending paths from requests, and enqueuing extinguishing actions into the shared queue. }}

  • Nested types:

  • FireExtinguishing (struct) — a small POD queued item describing a change to apply (vehicle, target, request, intensity delta, water damage delta, destroyed clear delta).
  • FireAircraftTickJob (BurstCompile, IJobChunk) — core parallel job that iterates aircraft archetype chunks and executes Tick for each vehicle. It contains two spatial iterator structs:
    • ObjectRequestIterator — finds nearby objects (OnFire/RescueTarget) not yet tied to the current request and enqueues request assignments.
    • ObjectExtinguishIterator — finds nearby objects and enqueues extinguish/clear deltas for OnFire / Destroyed entities.
  • FireExtinguishingJob (BurstCompile, IJob) — consumes the extinguishing queue and applies component mutations to OnFire, RescueTarget, Damaged and Destroyed components.
  • TypeHandle — compiler-generated grouping of handles used to access component data in jobs.

Usage Example

// Typical usage: retrieve the system from the world (systems are created/managed by the World).
using Unity.Entities;

// Get the managed system instance (created if not already present).
var fireAircraftSystem = World.DefaultGameObjectInjectionWorld.GetExistingSystemManaged<Game.Simulation.FireAircraftAISystem>();

// Systems operate automatically via ECS. If you need to trigger behavior manually,
// create the appropriate FireRescueRequest entities / OnFire components in the world;
// the system will pick them up on its scheduled updates.

Notes and tips for modders: - The system uses a NativeQueue to aggregate changes from parallel jobs, then a single job applies those changes to component data. This pattern prevents race conditions while allowing parallel scanning of the object search tree. - Extinguishing uses prefab structural integrity and prefab fire-engine parameters (extinguishingRate, spread, capacity) to compute deltas; adjusting those prefab parameters in mods will affect helicopter effectiveness. - Path requests are queued via PathfindSetupSystem — ensure you respect its queue writer dependencies when adding new pathfinding producers. - To influence dispatching / requests, modify FireRescueRequest entities and ServiceDispatch buffers on aircraft. Be cautious: the system expects certain buffer/component shapes; altering them may cause unexpected behavior.