Skip to content

Game.Simulation.WealthStatisticsSystem

Assembly:
Namespace: Game.Simulation

Type: class

Base: GameSystemBase

Summary:
WealthStatisticsSystem gathers and publishes wealth-related statistics for the city. It schedules three Burst-compiled IJobChunk jobs to compute and enqueue statistics events for: - residential households (household total wealth), - service companies (company worth per service resource), - processing companies and offices (company worth per output resource; distinguishes office vs processing goods).

The system queries related entity groups, reads resource buffers and prefab/process/vehicle data, and pushes StatisticsEvent entries into the CityStatisticsSystem's statistics queue. It runs on a coarse update cadence (GetUpdateInterval returns 512) and uses SimulationUtils update-frame slicing to only process entities for the relevant update frame slice.


Fields

  • private SimulationSystem m_SimulationSystem
    Reference to the SimulationSystem (used to obtain current frame index for update-frame slicing).

  • private CityStatisticsSystem m_CityStatisticsSystem
    Reference to the CityStatisticsSystem used to obtain a StatisticsEvent queue and register job writers.

  • private ResourceSystem m_ResourceSystem
    Reference to the ResourceSystem to access resource prefabs and register readers.

  • protected EntityQuery m_HouseholdGroup
    Query selecting household entities to process for residential wealth statistics (excludes tourists/commuters/moving/deleted/temp).

  • protected EntityQuery m_ServiceCompanyGroup
    Query selecting service company entities (prefab ref, ServiceAvailable, resource buffer, etc).

  • protected EntityQuery m_ProcessingCompanyGroup
    Query selecting processing companies and offices (prefab ref, ProcessingCompany, resource buffer, excludes ServiceAvailable).

  • private EntityQuery m_EconomyParameterQuery
    Query used to read global EconomyParameterData singleton.

  • private TypeHandle __TypeHandle
    Internal container holding various Entity/Component/Buffer/ComponentLookup handles used by scheduled jobs (auto-assigned in OnCreateForCompiler).

Properties

  • (No public properties exposed by this system)

Constructors

  • public WealthStatisticsSystem()
    Default constructor. The system performs the main initialization in OnCreate.

Methods

  • public override int GetUpdateInterval(SystemUpdatePhase phase)
    Returns the system's update interval. This system returns 512, indicating it only runs at that cadence relative to the game's update phases.

  • protected override void OnCreate()
    Initializes the system: obtains references to dependent systems (CityStatisticsSystem, SimulationSystem, ResourceSystem), sets up EntityQueries for households, service companies, and processing companies, and prepares the economy parameter query. Marked with [Preserve] in the compiled code.

  • protected override void OnUpdate()
    Schedules three parallel Burst IJobChunk jobs to compute wealth statistics:

  • ResidentialWealthStatJob (operates on m_HouseholdGroup): For each moved-in household, computes total household wealth via EconomyUtils.GetHouseholdTotalWealth and enqueues a StatisticsEvent with StatisticType.HouseholdWealth and the wealth amount.
  • ServiceWealthStatJob (operates on m_ServiceCompanyGroup): For prefabs that have IndustrialProcessData, computes the company total worth (uses owned vehicles when present), determines the output resource index, and enqueues a StatisticsEvent with StatisticType.ServiceWealth, the company worth, and the resource index parameter.
  • ProcessingWealthStatJob (operates on m_ProcessingCompanyGroup): Similar to ServiceWealthStatJob but distinguishes office output resources; it enqueues either StatisticType.OfficeWealth or StatisticType.ProcessingWealth depending on EconomyUtils.IsOfficeResource(industrialProcessData.m_Output.m_Resource). Each job checks the entity chunk's UpdateFrame shared component to only process the designated update-frame slice. The method coordinates dependencies between jobs and registers them as writers with CityStatisticsSystem; it also adds ResourceSystem readers where needed.

  • private void __AssignQueries(ref SystemState state)
    Compiler helper (inlined) used during OnCreateForCompiler. The decompiled body only shows creation/disposal of an EntityQueryBuilder placeholder; real query assignment is handled in OnCreate. Present for the compiler-generated pipeline.

  • protected override void OnCreateForCompiler()
    Compiler-time initialization: calls __AssignQueries and assigns TypeHandle handles via __TypeHandle.__AssignHandles(ref base.CheckedStateRef). Present to support the ECS code-gen/IL post-processing.

Nested job structs (summaries; each is Burst-compiled and implements IJobChunk):

  • ResidentialWealthStatJob
  • Purpose: Iterate household chunks and enqueue household wealth events.
  • Main fields: EntityTypeHandle, ComponentTypeHandle, BufferTypeHandle, SharedComponentTypeHandle, NativeQueue.ParallelWriter, uint m_UpdateFrameIndex.
  • Behavior: For chunks whose UpdateFrame matches m_UpdateFrameIndex, for each household with the MovedIn flag, compute household total wealth and enqueue a StatisticsEvent with StatisticType.HouseholdWealth and m_Change set to the wealth.

  • ServiceWealthStatJob

  • Purpose: Iterate service company chunks and enqueue service wealth events per output resource.
  • Main fields: EntityTypeHandle, BufferTypeHandle, SharedComponentTypeHandle, ComponentTypeHandle, ComponentLookup, BufferLookup, BufferLookup, ComponentLookup, ComponentLookup, ResourcePrefabs, EconomyParameterData, NativeQueue.ParallelWriter, uint m_UpdateFrameIndex.
  • Behavior: For chunks matching the UpdateFrame, for entities whose prefab has IndustrialProcessData, compute company total worth (accounting for owned vehicles/layout/delivery trucks when present), get the resource index of the industrial output, and enqueue a StatisticsEvent with StatisticType.ServiceWealth, m_Change as worth, and m_Parameter as resource index.

  • ProcessingWealthStatJob

  • Purpose: Iterate processing company (and offices) chunks and enqueue processing/office wealth events per output resource.
  • Main fields: similar to ServiceWealthStatJob.
  • Behavior: For chunks matching the UpdateFrame, for each entity, read the prefab's IndustrialProcessData, compute company worth, determine the output resource index and whether it is an office resource, then enqueue a StatisticsEvent with either StatisticType.OfficeWealth or StatisticType.ProcessingWealth, m_Change as worth, and m_Parameter as resource index.

Usage Example

// The system is created and managed by the ECS world. Typical mod code does not construct it directly,
// but you can query it or inspect its output via CityStatisticsSystem which hosts the statistics queue.
// Example: logging that the system update interval is 512 (reflects how frequently it runs)

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    var system = World.GetOrCreateSystemManaged<Game.Simulation.WealthStatisticsSystem>();
    Debug.Log($"WealthStatisticsSystem update interval: {system.GetUpdateInterval(SystemUpdatePhase.None)}"); // returns 512
}

// To observe produced statistics, read from CityStatisticsSystem's queue in a reader system:
var cityStats = World.GetOrCreateSystemManaged<CityStatisticsSystem>();
var statsQueue = cityStats.GetStatisticsEventQueue(out var deps);
// dequeue/consume StatisticsEvent entries on the main thread or in a job reader registered with the CityStatisticsSystem.

Note: This system is primarily internal to the simulation and enqueues StatisticsEvent items for CityStatisticsSystem to aggregate/publish. Modders typically interact with the resulting statistics via CityStatisticsSystem or by adding their own systems that read the same StatisticsEvent queue (registered with proper dependencies).