Game.Policies.ModifiedSystem
Assembly: Game (in-game assembly / Assembly-CSharp)
Namespace: Game.Policies
Type: class
Base: GameSystemBase
Summary:
ModifiedSystem is the ECS system that processes policy modifications (activate/deactivate/adjust) applied to entities in the city (buildings, districts, routes, city-wide). It listens for Modify events (entities having both Event and Modify components), applies the requested policy changes to the target entity (or extension), refreshes related modifier/option state (district, building, route, city), enqueues trigger actions (for event/telemetry systems) and records policy activation/deactivation events for telemetry. The heavy lifting is performed inside a Burst-compiled IJobChunk (ModifyPolicyJob) so the work can run across chunks in parallel.
Fields
-
private EntityQuery m_EventQuery
Description: Query used to find event entities that contain a Modify component (system requires an Event + Modify entity to run). -
private EntityQuery m_EffectProviderQuery
Description: Query used to collect CityEffectProvider archetype chunks (effect sources) — passed to modifier refresh routines. -
private ModificationBarrier4 m_ModificationBarrier
Description: Barrier/command buffer system used to create an EntityCommandBuffer for structural/component writes performed by the job. -
private TriggerSystem m_TriggerSystem
Description: Reference to the TriggerSystem. When enabled, the Modify job writes TriggerAction entries into the TriggerSystem's buffer; otherwise a temporary queue is used. -
private NativeQueue<PolicyEventInfo> m_PolicyEventInfos
Description: Thread-safe queue used by the job to record high-level policy activation/deactivation events. After the job completes the system dequeues items and forwards them to telemetry. -
private DistrictModifierInitializeSystem.DistrictModifierRefreshData m_DistrictModifierRefreshData
Description: Helper struct holding data & refresh routines for district-level policy data (options / modifiers). -
private BuildingModifierInitializeSystem.BuildingModifierRefreshData m_BuildingModifierRefreshData
Description: Helper struct holding data & refresh routines for building-level policy data. -
private RouteModifierInitializeSystem.RouteModifierRefreshData m_RouteModifierRefreshData
Description: Helper struct holding data & refresh routines for route-level policy data. -
private CityModifierUpdateSystem.CityModifierRefreshData m_CityModifierRefreshData
Description: Helper struct holding data & refresh routines for city-level policy data. -
private Entity m_TicketPricePolicy
Description: Cached Entity reference to the ticket price policy prefab (used to detect free public transport triggers when a ticket-price-related policy is removed). -
private TypeHandle __TypeHandle
Description: Internal struct used by the system to cache component type/lookups for fast access inside jobs. Assigned in OnCreateForCompiler.
Properties
- This system exposes no public properties.
Constructors
public ModifiedSystem()
Description: Default constructor (preserved for ECS/system creation). Initialization of run-time state happens in OnCreate.
Methods
protected override void OnCreate()
Description: Initializes the system:- Creates persistent NativeQueue
. - Instantiates refresh data helpers for district/building/route/city.
- Gets PrefabSystem and resolves m_TicketPricePolicy from transport UI prefab.
- Builds required EntityQueries (m_EventQuery and m_EffectProviderQuery).
- Caches references to the ModificationBarrier4 and TriggerSystem.
-
Calls RequireForUpdate(m_EventQuery) so the system only runs when there are events to process.
-
protected override void OnUpdate()
Description: Core runtime workflow: - Collects effect-provider archetype chunks asynchronously.
- Updates refresh-data helpers (they may refresh caches or lookups).
- Prepares a TriggerAction queue (uses TriggerSystem if enabled).
- Schedules the Burst-compiled ModifyPolicyJob (IJobChunk) which:
- Iterates over chunked Modify components.
- Applies/remove policy entries in DynamicBuffer
where applicable. - Updates extension flags for building extensions that are effectively policy-driven options.
- Refreshes district/building/route/city option and modifier state (calls RefreshEffects).
- Enqueues triggers for special cases (e.g., FreePublicTransport).
- Adds Updated component to entities modified via an EntityCommandBuffer.
- Writes PolicyEventInfo items to m_PolicyEventInfos for telemetry.
- Adds the job to the modification barrier and ties trigger buffer lifetime to job.
-
Completes the job synchronously (jobHandle.Complete()) then drains m_PolicyEventInfos and calls Telemetry.Policy for each event.
-
protected override void OnDestroy()
Description: Disposes the persistent m_PolicyEventInfos queue to free native memory. -
protected override void OnCreateForCompiler()
Description: Boilerplate used by generated/compiled systems to assign queries and component type handles (calls __AssignQueries and __TypeHandle.__AssignHandles). -
private void __AssignQueries(ref SystemState state)
Description: Internal helper (compiler-generated) for query assignment. Present for completeness; it is empty in this implementation aside from a temporary builder disposal. -
Nested types of interest:
public enum PolicyRange { None, Building, District, City, Route }
Description: Used to indicate the range/scope of a policy when reporting PolicyEventInfo / telemetry.public struct PolicyEventInfo { bool m_Activated; Entity m_Entity; PolicyRange m_PolicyRange; }
Description: Telemetry event payload pushed by the job into m_PolicyEventInfos to indicate a single policy activation/deactivation and its scope.private struct ModifyPolicyJob : IJobChunk
(Burst-compiled)
Description: The job that applies actual changes. It holds many ComponentLookup/BufferLookup handles, the effect provider chunk list, command buffer and parallel queues for triggers and telemetry. Important private methods inside:- CheckFreeBusTicketEventTrigger: Detects removal of the ticket price policy and enqueues a FreePublicTransport trigger.
- GetPolicyRange: Determines the policy scope (Building/District/Route/City/None) based on which modifier/option data the policy is associated with and whether the target entity has the corresponding component/buffer.
- RefreshEffects: Calls the appropriate refresh routines in the refresh-data helpers to recompute modifiers/options on the entity and adds an Updated component via the command buffer.
Usage Example
// Example: Activate a policy on an entity (district/building/route/etc).
// The system only runs when there is an entity with both Event and Modify components.
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
// Create an "event" entity that carries a Modify command.
// Replace `targetEntity` and `policyEntity` with valid Entity references.
Entity modifyEvent = em.CreateEntity(typeof(Event), typeof(Modify));
em.SetComponentData(modifyEvent, new Modify {
m_Entity = targetEntity, // the entity the policy targets (district/building/route/city)
m_Policy = policyEntity, // the policy prefab/entity
m_Flags = PolicyFlags.Active,
m_Adjustment = 0 // slider/adjustment value if applicable (use default where relevant)
});
// The ModifiedSystem will pick up the Event+Modify entity on its next update,
// apply the policy, refresh effects and emit any triggers/telemetry.
Notes / tips: - To deactivate a policy, submit a Modify with PolicyFlags not containing Active; the job will remove or update the Policy buffer entry and refresh effects. - If you target an Extension entity (building extension) and the policy is implemented as a BuildingOption with the "Inactive" option, the system toggles the ExtensionFlags.Disabled flag instead of manipulating a Policy buffer. - Telemetry.Policy is called for each activation/deactivation after the job completes; the PolicyEventInfo includes whether it was activated and its PolicyRange. - The ModifyPolicyJob is Burst-compiled and uses parallel workloads — prefer to use the public event interface (creating Event+Modify) instead of manually altering internal buffers to ensure consistency.