Skip to content

Game.UI.InGame.HealthcareInfoviewUISystem

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

Type: class

Base: InfoviewUISystemBase

Summary:
System that drives the in-game healthcare info view. It collects city data relevant to healthcare, deathcare and cemetery usage using ECS queries and burst jobs, aggregates results into a small NativeArray, and updates a set of UI value bindings (average health, sick count, patient counts, processing rates, availability indicators, etc.). The system schedules three primary IJobChunk jobs to compute citizen health stats, healthcare facility patient/capacity, and deathcare/cemetery statistics, then updates the bound UI values each update tick.


Fields

  • private enum Result
    Maps aggregated numeric results to fixed indices in the internal NativeArray m_Results. Entries:
  • CitizenHealth = 0
  • CitizenCount = 1
  • SickCitizens = 2
  • PatientCount = 3
  • PatientCapacity = 4
  • ProcessingRate = 5
  • CemeteryUse = 6
  • CemeteryCapacity = 7

  • public struct CalculateAverageHealthJob : IJobChunk
    Burst-compiled chunk job that iterates household chunks, reads household citizens and citizen health data, and accumulates three values into m_Results: total health (index 0), citizen count (index 1), and sick citizen count (index 2). Uses ComponentTypeHandle/BufferTypeHandle/ComponentLookup for efficient ECS access.

  • private struct UpdateHealthcareJob : IJobChunk
    Burst-compiled chunk job that iterates hospital/hc facility chunks and accumulates patient count and total patient capacity into m_Results indices 3 and 4. Takes into account building efficiency and installed upgrades when computing capacity.

  • private struct UpdateDeathcareJob : IJobChunk
    Burst-compiled chunk job that iterates deathcare/cemetery facility chunks and accumulates processing rate (index 5), long-term cemetery use (index 6) and cemetery capacity (index 7). Considers facility data, upgrades and building efficiency.

  • private struct TypeHandle
    Container of ComponentTypeHandle, BufferTypeHandle and ComponentLookup fields used to cache component access handles. Has a method __AssignHandles(ref SystemState) to initialize handles from the SystemState (used in OnCreateForCompiler).

  • private const string kGroup = "healthcareInfo"
    String group identifier used when creating ValueBindings.

  • private CityStatisticsSystem m_CityStatisticsSystem
    Reference to a city statistics system used to fetch statistics such as death rate.

  • private ValueBinding<float> m_AverageHealth
    Binding exposed to UI for average health value.

  • private ValueBinding<int> m_PatientCount
    Binding exposed to UI for number of patients in healthcare facilities.

  • private ValueBinding<int> m_SickCount
    Binding exposed to UI for number of sick citizens.

  • private ValueBinding<int> m_PatientCapacity
    Binding exposed to UI for total patient capacity.

  • private ValueBinding<float> m_DeathRate
    Binding exposed to UI for city death rate (pulled from CityStatisticsSystem).

  • private ValueBinding<float> m_ProcessingRate
    Binding exposed to UI for deathcare processing throughput.

  • private ValueBinding<int> m_CemeteryUse
    Binding exposed to UI for current cemetery usage (long-term stored corpses).

  • private ValueBinding<int> m_CemeteryCapacity
    Binding exposed to UI for cemetery capacity.

  • private GetterValueBinding<IndicatorValue> m_HealthcareAvailability
    Getter binding that computes an availability indicator for healthcare (capacity vs demand).

  • private GetterValueBinding<IndicatorValue> m_DeathcareAvailability
    Getter binding that computes an availability indicator for deathcare (processing vs death rate).

  • private GetterValueBinding<IndicatorValue> m_CemeteryAvailability
    Getter binding that computes an availability indicator for cemeteries (capacity vs use).

  • private EntityQuery m_HouseholdQuery
    Query to select household entities (residents) used by CalculateAverageHealthJob.

  • private EntityQuery m_DeathcareFacilityQuery
    Query to select deathcare facility entities (cemeteries, crematoriums).

  • private EntityQuery m_HealthcareFacilityQuery
    Query to select healthcare facility entities (hospitals, clinics).

  • private EntityQuery m_DeathcareFacilityModifiedQuery
    Query used to detect modified deathcare entities (Created/Updated/Deleted) to mark the system modified.

  • private EntityQuery m_HealthcareFacilityModifiedQuery
    Query used to detect modified healthcare entities (Created/Updated/Deleted) to mark the system modified.

  • private NativeArray<float> m_Results
    Persistent NativeArray of length 8 used to aggregate job results. Index mapping is defined by the Result enum. Allocator.Persistent and disposed in OnDestroy.

  • private TypeHandle __TypeHandle
    Instance of the TypeHandle struct storing the prepared component handles.

Properties

  • protected override bool Active
    Returns whether the system should be considered active (controls whether bindings are evaluated). True when the base is active or any of the exposed ValueBindings/GetterValueBindings are active. Otherwise false.

  • protected override bool Modified
    Indicates whether entities relevant to this system changed. True if either the deathcare modified query or the healthcare modified query contains changes (tests Created/Updated/Deleted components), otherwise false.

Constructors

  • public HealthcareInfoviewUISystem()
    Default constructor (preserved). Actual initialization of queries, bindings and m_Results happens in OnCreate.

Methods

  • [Preserve] protected override void OnCreate()
    Initializes entity queries, gets CityStatisticsSystem, creates and registers value bindings for the healthcareInfo group, and allocates m_Results (NativeArray(8, Persistent)). Also sets up GetterValueBindings that call GetHealthcareAvailability/GetDeathcareAvailability/GetCemeteryAvailability.

  • [Preserve] protected override void OnDestroy()
    Disposes m_Results and calls base.OnDestroy. Ensures native memory is freed when system is destroyed.

  • protected override void PerformUpdate()
    Main update routine:

  • Clears m_Results to zeros.
  • Schedules and completes CalculateAverageHealthJob against m_HouseholdQuery.
  • Schedules and completes UpdateHealthcareJob against m_HealthcareFacilityQuery.
  • Schedules and completes UpdateDeathcareJob against m_DeathcareFacilityQuery.
  • Reads aggregated values from m_Results and updates the ValueBindings: average health (rounded), patient count, sick count, patient capacity, death rate (from CityStatisticsSystem), processing rate, cemetery use, cemetery capacity.
  • Calls Update() on the three GetterValueBindings to recalculate availability indicators.

  • private IndicatorValue GetHealthcareAvailability()
    Calculates the healthcare availability indicator by comparing patient capacity vs sick count (uses IndicatorValue.Calculate).

  • private IndicatorValue GetDeathcareAvailability()
    Calculates the deathcare availability indicator by comparing processing rate vs city death rate.

  • private IndicatorValue GetCemeteryAvailability()
    Calculates the cemetery availability indicator by comparing cemetery capacity vs cemetery use.

  • [MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
    Compiler helper; minimal implementation here. Called from OnCreateForCompiler.

  • protected override void OnCreateForCompiler()
    Compiler helper that calls __AssignQueries and __TypeHandle.__AssignHandles(ref base.CheckedStateRef). Prepares component handles for job scheduling.

Usage Example

// Simplified view of how PerformUpdate reads aggregated job results.
// m_Results indexes correspond to the Result enum (CitizenHealth=0, CitizenCount=1, ...).
m_Results.Fill(0f);

// jobs run and accumulate into m_Results...

float totalHealth = m_Results[0];
float citizenCount = m_Results[1];
m_AverageHealth.Update(math.round(totalHealth / math.max(citizenCount, 1f)));

m_PatientCount.Update((int)m_Results[3]);
m_SickCount.Update((int)m_Results[2]);
m_PatientCapacity.Update((int)m_Results[4]);
m_DeathRate.Update(m_CityStatisticsSystem.GetStatisticValue(StatisticType.DeathRate));
m_ProcessingRate.Update(m_Results[5]);
m_CemeteryUse.Update((int)m_Results[6]);
m_CemeteryCapacity.Update((int)m_Results[7]);

// Availability indicators are computed on demand via their getter bindings.
m_HealthCareAvailability.Update();
m_DeathcareAvailability.Update();
m_CemeteryAvailability.Update();

{{ Notes }} - The system is designed for the game's ECS + Burst jobs pipeline and expects its queries and component handles to be initialized from the SystemState (via __AssignHandles). - m_Results is central to the design: the three jobs each write into non-overlapping slots and the main thread aggregates those slots into UI bindings in PerformUpdate. - All numeric aggregation happens in jobs with Complete() calls before reading the NativeArray to ensure thread completion and safe access from the main thread.