Skip to content

Game.UI.InGame.PoliceInfoviewUISystem

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

Type: public class PoliceInfoviewUISystem

Base: InfoviewUISystemBase

Summary:
PoliceInfoviewUISystem is an ECS-based UI system that collects and exposes police- and crime-related statistics to the UI layer. It defines several EntityQueries and Burst-compiled IJobChunk jobs to enumerate crime producers, police stations, prisons and criminal citizens, aggregates capacity and occupant counts (jail/prison), counts arrested/prisoned criminals, and computes indicators such as average crime probability and availability of jail/prison capacity. The system registers ValueBinding and GetterValueBinding instances under the "policeInfo" group so the UI can display the aggregated values. It also uses CityStatisticsSystem for time-series statistics (crime per month, escaped arrests).


Fields

  • private CityStatisticsSystem m_CityStatisticsSystem
    Holds a reference to the CityStatisticsSystem used to fetch city-wide statistics (e.g., crime count, escaped arrests).

  • private ValueBinding<int> m_CrimeProducers
    Value binding for the number of crime producer buildings; published to the UI under the "policeInfo" group.

  • private ValueBinding<float> m_CrimeProbability
    Value binding for the accumulated crime probability (sum of CrimeProducer.m_Crime) published to UI.

  • private ValueBinding<int> m_JailCapacity
    Value binding for total jail capacity (from police stations).

  • private ValueBinding<int> m_ArrestedCriminals
    Value binding for count of currently arrested criminals (not yet sentenced/prisoner).

  • private ValueBinding<int> m_InJail
    Value binding for number of occupants currently in jails (police station holding cells).

  • private ValueBinding<int> m_PrisonCapacity
    Value binding for total prison capacity.

  • private ValueBinding<int> m_Prisoners
    Value binding for number of citizens who are sentenced/prisoners.

  • private ValueBinding<int> m_InPrison
    Value binding for number of occupants currently held in prison buildings.

  • private ValueBinding<int> m_Criminals
    Value binding for count of entities with the Criminal component (total criminals).

  • private ValueBinding<int> m_CrimePerMonth
    Value binding for crimes per month statistic from CityStatisticsSystem.

  • private ValueBinding<float> m_EscapedRate
    Value binding for escaped-arrest rate (percentage), computed from statistics.

  • private GetterValueBinding<IndicatorValue> m_AverageCrimeProbability
    Getter binding that returns an IndicatorValue representing average crime probability per producer.

  • private GetterValueBinding<IndicatorValue> m_JailAvailability
    Getter binding that computes jail availability indicator (capacity vs arrested).

  • private GetterValueBinding<IndicatorValue> m_PrisonAvailability
    Getter binding that computes prison availability indicator (capacity vs prisoners).

  • private EntityQuery m_PrisonQuery
    EntityQuery selecting active prison buildings (used by PrisonJob).

  • private EntityQuery m_PrisonModifiedQuery
    EntityQuery used to detect changes to prison-related entities for the Modified property.

  • private EntityQuery m_CriminalQuery
    EntityQuery selecting citizen entities that have Criminal component.

  • private EntityQuery m_PoliceStationQuery
    EntityQuery selecting police station buildings (used by PoliceStationJob).

  • private EntityQuery m_PoliceStationModifiedQuery
    EntityQuery used to detect changes to police station entities for the Modified property.

  • private EntityQuery m_CrimeProducerQuery
    EntityQuery selecting buildings that are crime producers.

  • private EntityQuery m_CrimeProducerModifiedQuery
    EntityQuery used to detect changes to crime producer entities for the Modified property.

  • private NativeArray<float> m_Results
    NativeArray used as an accumulator for the various numeric results calculated by jobs. Length is 8 and indices correspond to various counters (see job code).

  • private TypeHandle __TypeHandle
    Generated struct holding ComponentTypeHandle/BufferTypeHandle/ComponentLookup instances used when scheduling IJobChunk jobs.

  • private EntityQuery __query_632591896_0
    Generated internal EntityQuery for PoliceConfigurationData (used by GetCrimeProbability).

  • private nested job structs and helpers (not separate fields but important to note): PoliceStationJob, PrisonJob, CrimeProducerJob, CriminalJob, and the nested TypeHandle struct which contains __AssignHandles.

Properties

  • protected override bool Active
    Returns true if the system should run. It uses base.Active plus the active state of several getter/value bindings (average crime probability, jail/prison availability, various value bindings). This prevents unnecessary updates when none of the UI bindings requiring police info are active.

  • protected override bool Modified
    Reports whether relevant entity sets have been modified. Returns true if the crime producer or police station modified queries are non-empty, or if the prison modified query is non-empty. Used by the UI system to avoid work if underlying data hasn't changed.

Constructors

  • public PoliceInfoviewUISystem()
    Default (parameterless) constructor. The system relies on OnCreate to initialize queries, bindings and allocate the native result array. Marked with [Preserve] on lifecycle methods to avoid stripping.

Methods

  • protected override void OnCreate()
    Initializes the system:
  • Gets or creates CityStatisticsSystem.
  • Builds entity queries for crime producers, police stations, prisons, criminals and "modified" variants that include Created/Updated/Deleted flags.
  • Registers multiple ValueBinding and GetterValueBinding instances under the "policeInfo" group (crimeProducers, crimeProbability, prison/jail capacities and occupancies, criminals, crimePerMonth, escapedRate, indicators).
  • Allocates m_Results as a Persistent NativeArray(8).

  • protected override void OnDestroy()
    Disposes the m_Results NativeArray and calls base.OnDestroy.

  • protected override void PerformUpdate()
    Main update method executed when the system runs. It:

  • Resets the m_Results accumulators.
  • Schedules and completes four Burst IJobChunk jobs in sequence:
    • CrimeProducerJob: counts crime-producer buildings and accumulates crime values.
    • PoliceStationJob: aggregates jail capacity and occupants for police stations (combines prefab data and installed upgrades).
    • PrisonJob: aggregates prison capacity and occupants for prisons (combines prefab data and installed upgrades).
    • CriminalJob: counts arrested and prisoner flags on Criminal components.
  • After jobs complete, updates the ValueBindings from m_Results and other stats (criminal count, average crime probability and availability indicators).
  • Updates crime-per-month and escaped-rate using CityStatisticsSystem.

  • private void ResetResults()
    Zeroes all elements in m_Results. Called at the start of PerformUpdate.

  • private IndicatorValue GetCrimeProbability()
    Getter invoked by m_AverageCrimeProbability. Returns an IndicatorValue constructed from the current accumulated crime probability and the configured maximum crime accumulation from PoliceConfigurationData. It divides accumulated crime by the number of producers to get average per producer.

  • private IndicatorValue GetJailAvailability()
    Getter invoked by m_JailAvailability. Computes availability indicator from jail capacity and arrested criminal count.

  • private IndicatorValue GetPrisonAvailability()
    Getter invoked by m_PrisonAvailability. Computes availability indicator from prison capacity and prisoner count.

  • private void __AssignQueries(ref SystemState state)
    Generated helper that constructs the internal query used to read PoliceConfigurationData (used by GetCrimeProbability).

  • protected override void OnCreateForCompiler()
    Generated override to assign generated queries and type handles (calls __AssignQueries and TypeHandle.__AssignHandles). Ensures the TypeHandle is populated before jobs are scheduled.

Nested types / jobs (summarized as they appear in file): - PoliceStationJob : IJobChunk (BurstCompile)
Reads building entities with PoliceStation, PrefabRef, buffers for Occupant and Efficiency, and installed upgrades buffer. For each active police station (non-zero efficiency), it loads the prefab's PoliceStationData, applies installed upgrades via UpgradeUtils.CombineStats, accumulates jail capacity (m_Results[3]) and occupant counts (m_Results[4]).

  • PrisonJob : IJobChunk (BurstCompile)
    Similar to PoliceStationJob but for Prison buildings. Accumulates prison capacity (m_Results[6]) and prisoner count (m_Results[7]).

  • CrimeProducerJob : IJobChunk (BurstCompile)
    Iterates CrimeProducer components to count number of producers (m_Results[0]) and accumulate crime value (m_Results[1]).

  • CriminalJob : IJobChunk (BurstCompile)
    Iterates Criminal components to count arrested criminals (m_Results[2]) and prisoners (m_Results[5]) based on CriminalFlags.

  • TypeHandle (nested struct)
    Holds the ComponentTypeHandle/BufferTypeHandle/ComponentLookup instances used when scheduling jobs and provides __AssignHandles(ref SystemState) to initialize them.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();

    // The system sets up its queries and registers bindings in its OnCreate.
    // Example: add an extra UI binding in a derived or customizing system.
    AddBinding(new ValueBinding<int>("policeInfo", "customPoliceMetric", 0));
}

// The system's PerformUpdate schedules Burst IJobChunk jobs to populate the UI bindings.
// You read these values from the UI layer by querying the "policeInfo" group keys
// such as "crimeProducers", "crimeProbability", "jailCapacity", "prisonAvailability", etc.

Notes and tips for modders: - The system uses EntityQueries that exclude temporary and deleted entities to reflect only active game state. - The m_Results NativeArray indexes are used consistently by the jobs; avoid changing its layout without updating all jobs. - Several parts of the system rely on prefab data combined with installed upgrades using UpgradeUtils.CombineStats — custom building prefabs or upgrades that modify PoliceStationData/PrisonData should be compatible with this merging. - GetterValueBinding returns an IndicatorValue struct used by UI indicators; check PoliceConfigurationData.m_MaxCrimeAccumulation for normalization of average crime probability.