Game.Simulation.WorkProviderStatisticsSystem
Assembly: Assembly-CSharp (game code)
Namespace: Game.Simulation
Type: class
Base: GameSystemBase
Summary:
WorkProviderStatisticsSystem is a Unity ECS system used by the game to collect and publish statistics about senior-level workplace supply/demand. The system enumerates work providers (buildings/entities with WorkProvider and Employee components but not OutsideConnection/Deleted/Temp), counts free senior workplaces relative to the number of workplaces provided by the prefab, computes an average shortage percentage, and enqueues a StatisticsEvent with StatisticType.SeniorWorkerInDemandPercentage. It uses Burst-compiled jobs (CountSeniorWorkplacesJob, StatisticsJob), NativeAccumulator for aggregation, ComponentTypeHandle/ComponentLookup for fast access, and coordinates with CityStatisticsSystem for event publishing and writer synchronization.
Fields
-
private CityStatisticsSystem m_CityStatisticsSystem
Reference to the CityStatisticsSystem used to obtain the statistics event queue and to register as a writer for synchronization. -
private EntityQuery m_WorkProviderQuery
EntityQuery that matches active work provider entities (Requires WorkProvider and Employee components; excludes OutsideConnection, Deleted, Temp). Used to iterate/schedule jobs over relevant entities. -
private TypeHandle __TypeHandle
Holds ComponentTypeHandle/ComponentLookup instances for PrefabRef, WorkProvider, FreeWorkplaces, WorkplaceData and SpawnableBuildingData. Populated via __AssignHandles during OnCreateForCompiler to avoid repeated handle construction at runtime. -
private EntityQuery __query_1149970541_0
Internal query that selects PoliceConfigurationData singleton (includes systems option). Used in OnUpdate to check police service prefab lock state. -
private EntityQuery __query_1149970541_1
Internal query that selects WorkProviderParameterData singleton (includes systems option). Used in OnUpdate to retrieve m_SeniorEmployeeLevel parameter.
Properties
- None (the system exposes no public properties).
Constructors
public WorkProviderStatisticsSystem()
Default constructor. The real initialization is performed in OnCreate / OnCreateForCompiler. Marked with [Preserve] on OnCreate methods, but constructor itself is empty in the decompiled code.
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
Returns 8192. The system requests this update interval so the ECS scheduler will run this system at the defined periodicity (8192 ticks/frames as used by the game's update scheduling). -
[Preserve] protected override void OnCreate()
Initializes the system: obtains the CityStatisticsSystem from the World, constructs the m_WorkProviderQuery (matching WorkProvider + Employee and excluding OutsideConnection, Deleted, Temp), and registers requirements for update (RequireForUpdate) including WorkProviderParameterData. Called on system creation. -
[Preserve] protected override void OnUpdate()
Main runtime logic: - Reads PoliceConfigurationData singleton and verifies whether the police service prefab is locked (skips work if locked).
- Allocates a NativeAccumulator
(TempJob) to aggregate free senior workplaces across entities. - Schedules a Burst-compiled CountSeniorWorkplacesJob as a parallel JobChunk that:
- Iterates matching archetype chunks, reads PrefabRef, WorkProvider, FreeWorkplaces components.
- Looks up WorkplaceData and optional SpawnableBuildingData via ComponentLookup.
- Computes number of workplaces by level with EconomyUtils.CalculateNumberOfWorkplaces.
- Accumulates per-level free vs total workplaces for all senior levels (m_SeniorEmployeeLevel .. 4) into the NativeAccumulator.
- After scheduling the chunk job, schedules a StatisticsJob that:
- Reads the aggregated AverageFloat result from the accumulator and enqueues a StatisticsEvent with StatisticType.SeniorWorkerInDemandPercentage and the computed percentage (100f * average).
-
Combines job dependencies, registers the CityStatisticsSystem as a writer (AddWriter) with the combined dependency, and disposes the NativeAccumulator with the dependency.
-
private void __AssignQueries(ref SystemState state)
Compiler-generated helper used on creation to build internal EntityQuery instances: - Builds __query_1149970541_0 for PoliceConfigurationData (IncludeSystems option).
- Builds __query_1149970541_1 for WorkProviderParameterData (IncludeSystems option).
-
Uses an EntityQueryBuilder transiently and disposes it at the end.
-
protected override void OnCreateForCompiler()
Called by generated/compiled code paths to hook up the queries and assign component handles. Calls __AssignQueries and __TypeHandle.__AssignHandles using the system's checked SystemState reference. -
Nested/Burst types (brief)
CountSeniorWorkplacesJob : IJobChunk
(BurstCompile)
Iterates archetype chunks matching the work provider query, reads PrefabRef, WorkProvider and FreeWorkplaces, uses ComponentLookup to read WorkplaceData and SpawnableBuildingData, computes workplaces per level, and accumulates free vs total into a NativeAccumulator. Runs in parallel via ScheduleParallel. StatisticsJob : IJob
(BurstCompile)
Consumes the accumulator result and enqueues a single StatisticsEvent containing SeniorWorkerInDemandPercentage with the computed change (percentage).
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// similar initialization that the system performs:
m_CityStatisticsSystem = base.World.GetOrCreateSystemManaged<CityStatisticsSystem>();
m_WorkProviderQuery = GetEntityQuery(new EntityQueryDesc
{
All = new ComponentType[] {
ComponentType.ReadOnly<WorkProvider>(),
ComponentType.ReadOnly<Employee>()
},
None = new ComponentType[] {
ComponentType.ReadOnly<Game.Objects.OutsideConnection>(),
ComponentType.ReadOnly<Deleted>(),
ComponentType.ReadOnly<Temp>()
}
});
RequireForUpdate(m_WorkProviderQuery);
RequireForUpdate<WorkProviderParameterData>();
}
Notes and modding tips: - WorkProviderStatisticsSystem relies on WorkProviderParameterData to supply which employee level counts as "senior" (m_SeniorEmployeeLevel). Changing that singleton will affect the statistic. - The system uses ComponentLookup and ComponentTypeHandle patterns to work efficiently with Burst and the job scheduler; when writing similar systems, populate handles in OnCreateForCompiler-like code or cache them before job scheduling. - The output statistic is enqueued via CityStatisticsSystem.GetStatisticsEventQueue; make sure any custom statistics consumers are synchronized with CityStatisticsSystem writers/readers when modifying behavior.