Skip to content

Game.UI.InGame.PollutionInfoviewUISystem

Assembly: (unknown — likely Assembly-CSharp)
Namespace: Game.UI.InGame

Type: class

Base: InfoviewUISystemBase

Summary:
PollutionInfoviewUISystem gathers and aggregates pollution-related data for household properties and updates UI indicator bindings used by the in-game pollution info view. It queries household PropertyRenter components, reads pollution maps (ground, air, noise) from the respective pollution systems, reads water consumer data, and computes averages (and water consumption/pollution totals) via a Burst-compiled IJobChunk (CalculateAveragePollutionJob). Results are published to four IndicatorValue bindings: averageGroundPollution, averageWaterPollution, averageAirPollution and averageNoisePollution. The system requires CitizenHappinessParameterData to calculate bonuses and scales.


Fields

  • private enum Result
    Internal enum used as indexes into the results NativeArray (m_Results). Members:
  • GroundPollution
  • GroundPollutionCount
  • AirPollution
  • AirPollutionCount
  • NoisePollution
  • NoisePollutionCount
  • ConsumedWater
  • PollutedWater
  • ResultCount

  • private AirPollutionSystem m_AirPollutionSystem
    Reference to the game's AirPollutionSystem used to obtain the air pollution map.

  • private GroundPollutionSystem m_GroundPollutionSystem
    Reference to the game's GroundPollutionSystem used to obtain the ground pollution map.

  • private NoisePollutionSystem m_NoisePollutionSystem
    Reference to the game's NoisePollutionSystem used to obtain the noise pollution map.

  • protected CitySystem m_CitySystem
    Reference to the CitySystem (protected) used to get city entity (m_City) for reading city modifiers.

  • private ValueBinding<IndicatorValue> m_AverageGroundPollution
    UI binding for the average ground pollution indicator.

  • private ValueBinding<IndicatorValue> m_AverageWaterPollution
    UI binding for the average water pollution / consumption indicator.

  • private ValueBinding<IndicatorValue> m_AverageAirPollution
    UI binding for the average air pollution indicator.

  • private ValueBinding<IndicatorValue> m_AverageNoisePollution
    UI binding for the average noise pollution indicator.

  • private EntityQuery m_HouseholdQuery
    EntityQuery used to enumerate households (PropertyRenter + Household + HouseholdCitizen + UpdateFrame) excluding seekers, tourists, commuters, moving-away households.

  • private NativeArray<int> m_Results
    NativeArray (length 8) used as accumulator for job results. Indices map to the Result enum. Allocated with Allocator.Persistent.

  • private TypeHandle __TypeHandle
    Internal struct containing ComponentTypeHandle/ComponentLookup/BufferLookup handles used by the chunk job.

  • private EntityQuery __query_374463591_0
    Internal query used to obtain singleton CitizenHappinessParameterData.

  • private struct CalculateAveragePollutionJob (nested)
    Burst-compiled IJobChunk that iterates household chunks, queries per-property pollution bonuses (air, ground, noise), reads water consumer data, and accumulates totals/counters into m_Results. The job reads:

  • PropertyRenter component array
  • WaterConsumer lookup
  • Transform lookup
  • CityModifier buffer for the city entity
  • Air/Noise/Ground pollution maps It uses CitizenHappinessParameterData and the city entity to compute bonuses via CitizenHappinessSystem helper calls.

  • private struct TypeHandle (nested)
    Holds component and buffer handles (read-only) required by the job, and provides a method to assign them from a SystemState.

Properties

  • public override GameMode gameMode => GameMode.GameOrEditor
    Indicates the system runs in Game and Editor modes.

  • protected override bool Active { get; }
    Active is true when the base Active is true or any of the four bindings (average air/ground/noise/water) are active. Controls whether the system should run.

Constructors

  • public PollutionInfoviewUISystem()
    Default constructor. (No custom construction logic beyond base initialization.)

Methods

  • [Preserve] protected override void OnCreate()
  • Creates/gets references to AirPollutionSystem, GroundPollutionSystem, NoisePollutionSystem and CitySystem via World.GetOrCreateSystemManaged.
  • Allocates m_Results as a new NativeArray(8, Allocator.Persistent).
  • Builds the household EntityQuery used to schedule the job.
  • Adds ValueBinding bindings for the four indicator values (averageGroundPollution, averageWaterPollution, averageAirPollution, averageNoisePollution).
  • Calls RequireForUpdate() to ensure required singleton data is present before updating.

  • [Preserve] protected override void OnDestroy()

  • Disposes m_Results and calls base.OnDestroy().

  • protected override void PerformUpdate()

  • Obtains read-only copies of ground/air/noise pollution maps from their respective systems (each returns a NativeArray and an associated JobHandle).
  • Combines dependencies and fetches CitizenHappinessParameterData singleton.
  • Resets m_Results to zero.
  • Schedules and immediately completes CalculateAveragePollutionJob over the household query (the job reads component lookups/handles obtained via __TypeHandle).
  • After job completion, reads accumulated results from m_Results, computes average values where counts are > 0 and converts them into IndicatorValue values.
  • Updates the four ValueBindings:
    • averageGroundPollution: negative average ground pollution bonus (clamped by CitizenHappinessParameterData.m_MaxAirAndGroundPollutionBonus).
    • averageAirPollution: negative average air pollution bonus.
    • averageNoisePollution: negative average noise bonus (clamped by CitizenHappinessParameterData.m_MaxNoisePollutionBonus).
    • averageWaterPollution: shows consumed fresh water (as min/target?) and polluted water (uses total polluted water rounded to int).

Note: The job writes sums and counts; averages are computed by integer division (sum / count) if count > 0.

  • private void ResetResults()
    Sets all entries of m_Results to 0. Called before scheduling the job.

  • [MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
    Builds the internal EntityQuery to fetch CitizenHappinessParameterData singleton and stores it in __query_374463591_0. (Compiler-generated helper.)

  • protected override void OnCreateForCompiler()
    Compiler helper that calls __AssignQueries and assigns TypeHandle component/buffer handles from the system state.

  • (Nested) CalculateAveragePollutionJob.Execute(...)
    Per-chunk logic: iterates properties in the chunk, calls:

  • CitizenHappinessSystem.GetAirPollutionBonuses(...)
  • CitizenHappinessSystem.GetGroundPollutionBonuses(...)
  • CitizenHappinessSystem.GetNoiseBonuses(...) Sums up bonuses and counts; for water consumers it accumulates m_FulfilledFresh and m_Pollution * m_FulfilledFresh, and finally writes all accumulated totals into the shared m_Results array (indices per Result enum).

Usage Example

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

    // Acquire pollution systems and city system
    m_AirPollutionSystem = base.World.GetOrCreateSystemManaged<AirPollutionSystem>();
    m_GroundPollutionSystem = base.World.GetOrCreateSystemManaged<GroundPollutionSystem>();
    m_NoisePollutionSystem = base.World.GetOrCreateSystemManaged<NoisePollutionSystem>();
    m_CitySystem = base.World.GetOrCreateSystemManaged<CitySystem>();

    // Allocate accumulator array for the job (8 entries corresponding to Result enum)
    m_Results = new NativeArray<int>(8, Allocator.Persistent);

    // Register UI bindings
    AddBinding(m_AverageGroundPollution = new ValueBinding<IndicatorValue>("pollutionInfo", "averageGroundPollution", default, new ValueWriter<IndicatorValue>()));
    AddBinding(m_AverageWaterPollution  = new ValueBinding<IndicatorValue>("pollutionInfo", "averageWaterPollution",  default, new ValueWriter<IndicatorValue>()));
    AddBinding(m_AverageAirPollution    = new ValueBinding<IndicatorValue>("pollutionInfo", "averageAirPollution",    default, new ValueWriter<IndicatorValue>()));
    AddBinding(m_AverageNoisePollution  = new ValueBinding<IndicatorValue>("pollutionInfo", "averageNoisePollution",  default, new ValueWriter<IndicatorValue>()));

    // Ensure happiness parameters are available before running updates
    RequireForUpdate<CitizenHappinessParameterData>();
}

Notes and implementation tips: - m_Results uses specific indices — avoid changing the array length or index mapping without updating the Result enum and all readers. - CalculateAveragePollutionJob is Burst-compiled and uses read-only lookups/handles. Ensure those handles are assigned via TypeHandle before scheduling the job (the system does this in OnCreateForCompiler). - The job completes synchronously in PerformUpdate (.Complete()), so results are immediately available for converting to IndicatorValue and updating UI bindings. If you change scheduling to run asynchronously, ensure you manage dependencies and UI update timing accordingly.