Game.Simulation.ServiceCompanySystem
Assembly:
Game (simulation/game code)
Namespace:
Game.Simulation
Type:
class
Base:
GameSystemBase
Summary:
ServiceCompanySystem is a simulation system responsible for updating service-type companies (non-industrial companies that provide services, e.g. hotels, other service providers). It runs a Burst-compiled IJobChunk (UpdateServiceJob) that:
- increments available service supply based on company production, employees and building efficiency,
- updates tax payer untaxed income based on produced services and district/commercial tax rates,
- creates/removes "no customers" notifications (icons) for company-owned properties when service availability vs customers triggers notification thresholds,
- uses building efficiencies, prefab data and economy parameters to compute production and prices,
- and schedules the update job in parallel using the ECS JobChunk API.
The system queries parameter singletons (economy, company notifications, building configuration), interacts with ResourceSystem, TaxSystem and IconCommandSystem and requires the company entity group to exist to run.
Fields
-
private EntityQuery m_CompanyGroup
This EntityQuery selects company entities to update. It requires components such as CompanyData (read-only), ServiceAvailable (read/write), PrefabRef, PropertyRenter, WorkProvider, Employee buffer and UpdateFrame shared component. The system will not run without matching entities. -
private EntityQuery m_EconomyParameterQuery
Query used to fetch the EconomyParameterData singleton (economy tuning values). -
private EntityQuery m_CompanyNotificationParameterQuery
Query used to fetch CompanyNotificationParameterData (notification thresholds and prefabs). -
private EntityQuery m_BuildingParameterQuery
Query used to fetch BuildingConfigurationData (e.g. high rent notification prefab id). -
private SimulationSystem m_SimulationSystem
Reference to the SimulationSystem used to obtain the current simulation frame index for distributing company updates across frames. -
private ResourceSystem m_ResourceSystem
Reference to the ResourceSystem for accessing ResourcePrefabs used in price/production calculations. -
private TaxSystem m_TaxSystem
Reference to the TaxSystem used to read tax rates and modify TaxPayer components. -
private IconCommandSystem m_IconCommandSystem
Reference to IconCommandSystem used to add/remove notification icons on buildings. -
private TypeHandle __TypeHandle
Holds component and buffer type handles used by the job and assigned during system initialization (internal helper to cache handles). -
private struct UpdateServiceJob
(nested)
Burst-compiled IJobChunk that performs the per-chunk/per-company update logic described in the summary. It contains component handles, lookups, buffers, random seed, resource prefabs, parameter singletons and the IconCommandBuffer used to queue icon changes. -
private struct TypeHandle
(nested)
A helper struct used to obtain and store EntityTypeHandle, ComponentTypeHandles, BufferTypeHandles and ComponentLookup/BufferLookup instances. It has an __AssignHandles method used in OnCreateForCompiler to cache handles.
Properties
- (No public properties)
The ServiceCompanySystem exposes no public properties. It operates via ECS queries and internal fields.
Constructors
public ServiceCompanySystem()
Default constructor. The system initialization and query setup is done in OnCreate/OnCreateForCompiler.
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
Returns the update interval in frames for this system. The system spreads company updates across simulation frames; the value is computed as 262144 / (EconomyUtils.kCompanyUpdatesPerDay * 16). This helps throttle updates so production is distributed across days/frames. -
protected override void OnCreate()
Initializes system references and entity queries: - Acquires SimulationSystem, IconCommandSystem, ResourceSystem and TaxSystem.
- Creates the m_CompanyGroup EntityQuery and queries for the parameter singletons (economy, company notifications, building configuration).
-
Calls RequireForUpdate on relevant queries so the system only runs when required data is present.
-
protected override void OnUpdate()
Prepares and schedules the UpdateServiceJob: - Calculates which update frame index to process using SimulationUtils.GetUpdateFrame.
- Builds an UpdateServiceJob instance, populating component/buffer handles, resource prefabs, singletons and other required data (random seed, icon command buffer, tax rates, etc.).
-
Schedules the job in parallel with JobChunkExtensions.ScheduleParallel and wires dependencies to IconCommandSystem and TaxSystem so icon commands and tax reads happen safely.
-
protected override void OnCreateForCompiler()
Compiler-time helper that assigns the cached TypeHandle handles via __AssignQueries and TypeHandle.__AssignHandles. This method is used to ensure the generated code/compiler gets proper handles for the job system. -
private void __AssignQueries(ref SystemState state)
Internal helper (called from OnCreateForCompiler) for assigning/initializing queries or builder state. In this implementation the method constructs and disposes a temporary EntityQueryBuilder - kept primarily for generated code consistency. -
(Nested)
private struct UpdateServiceJob : IJobChunk
->public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
Core per-chunk execution: - Skips chunks whose UpdateFrame shared component index does not match the job's target frame.
- Retrieves chunk arrays and buffer accessors: Entity, PropertyRenter, ServiceAvailable, LodgingProvider, CompanyNotifications, Employee buffer, Renter buffer.
-
For each company in the chunk:
- Validates property has a Building component and that the prefab has ServiceCompanyData; skips otherwise.
- Determines building efficiency (via BuildingUtils.GetEfficiency if an Efficiency buffer exists on the property).
- Uses EconomyUtils.GetCompanyProductionPerDay, employee buffers and industrial process data to compute production, scales to per-update-step production and increments ServiceAvailable up to m_MaxService.
- If the company entity has a TaxPayer component: calculates the relevant commercial tax rate (district-modified if property is in a district) and updates TaxPayer.m_UntaxedIncome and m_AverageTaxRate based on production value and service price.
- Determines whether a "No customers" notification should be shown, based on company notification parameters, resource amounts (if resource-based), and lodging provider occupancy (special-case for hotels). Adds/removes icon notifications via IconCommandBuffer and stores the notified property entity in CompanyNotifications.m_NoCustomersEntity.
-
void IJobChunk.Execute(...)
(explicit interface)
Dispatches to the job's Execute method (standard IJobChunk pattern).
Usage Example
// Example: reading ServiceAvailable for an entity inside another system (simple snippet)
public partial class MyDebugSystem : SystemBase
{
protected override void OnUpdate()
{
var serviceLookup = GetComponentLookup<ServiceAvailable>(isReadOnly: true);
Entities.WithoutBurst().ForEach((Entity e) =>
{
if (serviceLookup.HasComponent(e))
{
var sa = serviceLookup[e];
Debug.Log($"Entity {e} ServiceAvailable = {sa.m_ServiceAvailable}");
}
}).Run();
}
}
Notes for modders: - The service update logic is implemented inside a Burst-compiled job. Modifying behavior typically requires either: - Hooking into the systems the job uses (ResourceSystem, TaxSystem, IconCommandSystem), or - Replacing/overriding the system via the modding API (advanced) or intercepting component/state changes (preferred). - The system depends on many game-specific structures (ServiceCompanyData, IndustrialProcessData, EconomyParameterData, CompanyNotificationParameterData); altering any of those can change how companies produce services, taxes are applied and notifications triggered.