Game.PollutionSection
Assembly:
Assembly-CSharp.dll
Namespace:
Game.UI.InGame
Type:
class
Base:
InfoSectionBase
Summary:
PollutionSection is an in-game UI info section that displays pollution information (ground, air and noise) for the currently selected building/entity. It queries the world (ECS) for pollution parameters and uses prefab and building data to compute effective pollution via BuildingPollutionAddSystem and PollutionUIUtils. The section is only visible for buildings that produce any pollution and supports destroyed/abandoned/park states and building efficiency modifiers. The class is compiler-generated to wire up ECS ComponentLookup/BufferLookup handles and entity queries required to compute pollution values.
Fields
-
private EntityQuery m_UIConfigQuery
Holds the entity query used to fetch UIPollutionConfigurationData (used to map pollution float values to UI thresholds/keys). Initialized in OnCreate(). -
private TypeHandle __TypeHandle
Nested struct instance used to store ComponentLookup/BufferLookup handles for various prefab/citizen/company components (PrefabRef, BuildingData, PollutionData, Employee buffers, etc.). Its __AssignHandles method is called during setup to bind lookups to the current SystemState. -
private EntityQuery __query_1774369403_0
EntityQuery built to fetch a singleton PollutionParameterData. Created by __AssignQueries. -
private EntityQuery __query_1774369403_1
EntityQuery built to fetch a CityModifier buffer (RW) singleton. Created by __AssignQueries.
Properties
-
protected override string group { get; }
Returns the group name for this info section: "PollutionSection". Used by the UI framework to categorize/identify this section. -
protected override bool displayForDestroyedObjects { get; }
Overrides InfoSectionBase property; this class sets it to true so the section can display for destroyed objects as well. -
private PollutionThreshold groundPollutionKey { get; set; }
Holds the computed UI threshold/key for ground pollution after OnProcess runs. Written to JSON in OnWriteProperties. -
private PollutionThreshold airPollutionKey { get; set; }
Holds the computed UI threshold/key for air pollution. -
private PollutionThreshold noisePollutionKey { get; set; }
Holds the computed UI threshold/key for noise pollution.
Constructors
public PollutionSection()
Default constructor. Marked with [Preserve] attribute in source (ensures the constructor is preserved by code stripping). Initialization of ECS handles and queries is performed in OnCreateForCompiler/OnCreate.
Methods
-
private struct TypeHandle.__AssignHandles(ref SystemState state)
Initializes the ComponentLookupand BufferLookup fields inside TypeHandle using the provided SystemState. This binds read-only lookups for prefab data, pollution data, citizens buffers, employee buffers, etc. Must be called before GetPollution uses those lookups. -
protected override void OnCreate()
Called when the UI section is created. Calls base.OnCreate() and sets up m_UIConfigQuery to find UIPollutionConfigurationData. This configuration is later used in OnProcess to compute pollution threshold keys. -
protected override void OnCreateForCompiler()
Compiler/injection-time override that wires up entity queries and TypeHandle by calling __AssignQueries and TypeHandle.__AssignHandles with the CheckedStateRef (SystemState). Ensures ECS handles are available in runtime. -
protected override void Reset()
Resets the stored pollution keys to PollutionThreshold.None. Called when the section is reset/initialized. -
protected override void OnUpdate()
Updates base.visible by evaluating the Visible() method. Ensures the UI section is shown/hidden according to the currently selected entity and its pollution. -
private bool Visible()
Determines whether the pollution section should be visible for the current selectedEntity. Returns true if the selected entity is a Building and has any ground, air or noise pollution. Uses GetPollution() to retrieve pollution amounts. -
protected override void OnProcess()
Main processing step invoked by the UI system. Calls GetPollution(), obtains the UIPollutionConfigurationPrefab singleton via m_PrefabSystem and m_UIConfigQuery, then maps raw pollution float values to PollutionThreshold keys (groundPollutionKey, airPollutionKey, noisePollutionKey) using PollutionUIUtils.GetPollutionKey. -
private PollutionData GetPollution()
Core method that queries ECS state and computes the effective PollutionData for the selectedPrefab/selectedEntity. Steps: - Calls CompleteDependency() (ensures jobs are completed before reading component data).
- Checks if the entity is Destroyed, Abandoned, or a Park.
- Reads building efficiency via a DynamicBuffer
(if available). - Reads Renter and InstalledUpgrade buffers (if present) to account for modifiers.
- Fetches singleton PollutionParameterData and CityModifier buffer via previously built queries.
- Retrieves ComponentLookup/BufferLookup instances via the TypeHandle.
-
Calls BuildingPollutionAddSystem.GetBuildingPollution(...) with all gathered data to compute and return a PollutionData struct for the building. Note: this method depends on properly assigned ComponentLookup / BufferLookup handles and entity queries.
-
public override void OnWriteProperties(IJsonWriter writer)
Serializes the computed pollution keys into JSON properties: "groundPollutionKey", "airPollutionKey", and "noisePollutionKey". Each value is written as its integer representation. -
[MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
Builds and stores the ECS queries used by this section: - A query for a singleton PollutionParameterData (IncludeSystems option).
-
A query for a RW CityModifier buffer (IncludeSystems option). This method is invoked during OnCreateForCompiler to bind queries to the SystemState.
-
private void __AssignQueries(ref SystemState state)
(See above — same method; present in source with AggressiveInlining attribute)
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Bind the UI config entity query so OnProcess can map pollution values to UI thresholds
m_UIConfigQuery = GetEntityQuery(ComponentType.ReadOnly<UIPollutionConfigurationData>());
}
// OnProcess will be called by the UI system — example flow:
// 1) OnUpdate -> Visible() -> decides whether to show the section
// 2) OnProcess -> GetPollution() -> compute PollutionData
// 3) Map pollution values to pollution keys using UIPollutionConfigurationPrefab and PollutionUIUtils
Notes and Modding Tips: - PollutionSection relies on ECS ComponentLookup/BufferLookup handles initialized via TypeHandle.__AssignHandles and entity queries initialized via __AssignQueries. When mirroring or extending this behavior in your own systems, ensure you call the equivalent setup against a valid SystemState. - The actual pollution computation is delegated to BuildingPollutionAddSystem.GetBuildingPollution(...). If you need to override pollutant behavior, consider intercepting or replacing that system or provide custom CityModifier/PollutionModifierData entries. - The UI mapping (float -> PollutionThreshold) uses UIPollutionConfigurationPrefab (a prefab singleton). To adjust thresholds shown in the UI, modify or provide a different UIPollutionConfigurationPrefab instance. - Selected entity/prefab references (selectedEntity, selectedPrefab) are provided by InfoSectionBase; when creating custom info sections derive from InfoSectionBase to reuse selection handling.