Game.Events.AddHealthProblemSystem
Assembly: Game
Namespace: Game.Events
Type: class
Base: GameSystemBase
Summary:
AddHealthProblemSystem listens for event components that indicate citizens should receive health problems (AddHealthProblem), and also responds to building-related events such as Ignite and Destroy. It schedules two primary burst jobs:
- FindCitizensInBuildingJob: scans citizens inside a building (for ignite/destroy) and enqueues AddHealthProblem requests for matching citizens.
- AddHealthProblemJob: collects AddHealthProblem requests (from entities and the queue), merges multiple problems per citizen, applies or updates HealthProblem components, stops transport/pathing for citizens who require transport, removes/updates notification icons, adds event journal entries, and enqueues TriggerAction entries for further game logic (sick/injured/trapped/in danger).
The system coordinates with: - IconCommandSystem for notifications, - TriggerSystem for triggers, - CityStatisticsSystem for statistics events, - ModificationBarrier4 for safe structural changes.
It uses ECS queries for citizens and healthcare settings and performs work across jobs and main thread command buffers to apply component changes.
Fields
-
private IconCommandSystem m_IconCommandSystem
This is a reference to the IconCommandSystem used to add/remove notification icons (e.g., ambulance notifications) when health problems require transport or when they clear. -
private ModificationBarrier4 m_ModificationBarrier
Barrier system used to create an EntityCommandBuffer for making structural changes (adding HealthProblem components, creating journal entries, etc.) safely from jobs. -
private EntityQuery m_AddHealthProblemQuery
Query that finds event entities relevant to adding health problems. It targets Game.Common.Event entities that also have AddHealthProblem, Ignite or Destroy components. -
private EntityQuery m_HealthcareSettingsQuery
Query that reads HealthcareParameterData (game settings for healthcare) used to determine death probabilities (e.g., building destroy death rate). -
private EntityQuery m_CitizenQuery
Query for Citizen entities with CurrentBuilding (and excluding Deleted) used by the FindCitizensInBuildingJob to iterate citizens. -
private EntityArchetype m_JournalDataArchetype
Archetype used to create AddEventJournalData entities when a casualty-related health problem should be logged in the event journal. -
private TriggerSystem m_TriggerSystem
Reference to TriggerSystem used to create and enqueue TriggerAction entries (e.g., CitizenGotSick, CitizenGotInjured). -
private CityStatisticsSystem m_CityStatisticsSystem
Reference to statistics system used to enqueue statistics events when deaths occur. -
private TypeHandle __TypeHandle
Internal struct holding component/lookup handles used to access component data in jobs and to assign handles during system initialization.
Properties
- None declared on this system.
This system relies on internal fields and job structs rather than public properties.
Constructors
public AddHealthProblemSystem()
Default constructor. The system's important initialization is done in OnCreate (queries, barriers and child system lookups). The constructor itself is empty/preserved.
Methods
-
protected override void OnCreate()
: System.Void
Initializes queries, gets or creates dependent systems (ModificationBarrier4, IconCommandSystem, TriggerSystem, CityStatisticsSystem), creates m_JournalDataArchetype, and registers required queries for update. This sets up the system so it will run only when relevant event/query data is present. -
protected override void OnUpdate()
: System.Void
Main update method. Steps performed: - Collects event chunks (ignite/destroy/AddHealthProblem).
- For each Ignite/Destroy that targets a Building, it schedules FindCitizensInBuildingJob to scan citizens whose CurrentBuilding matches and enqueue AddHealthProblem entries (also handling death probability on Destroy).
- Constructs and schedules AddHealthProblemJob that:
- Aggregates AddHealthProblem requests from both existing components and the parallel queue.
- Merges multiple requests per citizen, respecting flags (Dead, RequireTransport, etc.).
- Updates or adds HealthProblem components, stops transport/pathing where necessary, manipulates icons, writes journal entries, and enqueues TriggerAction events for other systems.
-
Registers and wires job dependencies with ModificationBarrier4, IconCommandSystem, TriggerSystem, and CityStatisticsSystem.
-
protected override void OnCreateForCompiler()
: System.Void
Internal helper used by generated/compiled code to assign queries and TypeHandle component handles. Calls __AssignQueries and assigns component/lookup handles. -
private void __AssignQueries(ref SystemState state)
: System.Void
Internal method (used during compiler-time setup) prepared for assigning or validating queries. This implementation in the generated code is minimal but required for the compiled system boilerplate.
Notes about nested types: - FindCitizensInBuildingJob (IJobChunk, burst-compiled): iterates citizen archetype chunks, enqueues AddHealthProblem entries for citizens in a specified building and can perform death checks that enqueue statistics/trigger actions. - AddHealthProblemJob (IJob, burst-compiled): merges and applies health problems, manipulates path/transport state for affected citizens, updates icons, creates journal entries and trigger actions. - TypeHandle: holds component type handles and buffer/component lookups passed into jobs.
Usage Example
// Example: Raise an AddHealthProblem request for a citizen entity so AddHealthProblemSystem will process it.
// EntityManager em = ... (get from World or SystemBase)
// Entity eventEntity = em.CreateEntity();
// em.AddComponentData(eventEntity, new Game.Common.Event { /* fill event data if required */ });
// em.AddComponentData(eventEntity, new AddHealthProblem {
// m_Event = eventEntity,
// m_Target = targetCitizenEntity,
// m_Flags = HealthProblemFlags.Sick
// });
// // After this, the AddHealthProblemSystem will pick up the event on its next update and apply a HealthProblem to the target citizen.