Skip to content

Game.Policies.RouteModifierInitializeSystem

Assembly: Assembly-CSharp
Namespace: Game.Policies

Type: class

Base: GameSystemBase

Summary:
Initializes route modifiers and option masks for newly created routes based on active city policies. The system finds entities with Created + Route + Policy (and without Temp), reads active policies and their slider values and modifier data, then populates each Route's option mask and its RouteModifier buffer. Work is performed in a parallel IJobChunk (InitializeRouteModifiersJob). The system exposes a nested RouteModifierRefreshData helper that contains Component/Buffer lookups and the logic for computing modifier deltas and combining modifiers.


Fields

  • private EntityQuery m_CreatedQuery
    Query used to find route entities that have just been created (Created + Route + Policy, excluding Temp). The job is scheduled against this query.

  • private RouteModifierRefreshData m_RouteModifierRefreshData
    Helper struct instance that holds ComponentLookup/BufferLookup instances and implements the core logic for refreshing route option masks and modifiers.

  • private TypeHandle __TypeHandle
    Internal type-handle container used to cache BufferTypeHandle/ComponentTypeHandle for policies, routes and route-modifier buffers for job scheduling.

Properties

  • None.
    This system does not expose public properties.

Constructors

  • public RouteModifierInitializeSystem()
    Default constructor. The system uses OnCreate to initialize its state; no special construction-time parameters are required.

Methods

  • protected override void OnCreate() : System.Void
    Initializes the RouteModifierRefreshData and constructs the entity query (Created + Route + Policy, excluding Temp). Calls RequireForUpdate with the query so the system only runs when matching entities exist.

  • protected override void OnUpdate() : System.Void
    Updates the lookups in RouteModifierRefreshData, builds an InitializeRouteModifiersJob with the required type handles, and schedules it in parallel over m_CreatedQuery. The job will refresh each route's option mask and route modifiers for entities that have active policies.

  • protected override void OnCreateForCompiler() : System.Void
    Internal setup used by the compiled system to assign queries and type handles for the Burst/job pipeline. Calls __AssignQueries and assigns handles in __TypeHandle.

  • private void __AssignQueries(ref SystemState state) : System.Void
    Internal stub used to initialize queries for the compiler. (No custom query logic beyond what OnCreate sets up.)

Nested types and utilities (summary of the important ones):

  • InitializeRouteModifiersJob : IJobChunk
    Job that iterates chunks matching the query, reads the Route and Policy buffers, and uses RouteModifierRefreshData to refresh route option masks and route modifier buffers per-route.

  • RouteModifierRefreshData
    Contains:

  • ComponentLookup m_PolicySliderData (read-only)
  • ComponentLookup m_RouteOptionData (read-only)
  • BufferLookup m_RouteModifierData (read-only)

Key methods: - Update(SystemBase system) — updates the internal ComponentLookup/BufferLookup before use on main thread. - RefreshRouteOptions(ref Route route, DynamicBuffer<Policy> policies) — computes route.m_OptionMask by OR-ing option masks from active policies that define RouteOptionData. - RefreshRouteModifiers(DynamicBuffer<RouteModifier> modifiers, DynamicBuffer<Policy> policies) — clears and adds route modifiers based on active policies and their RouteModifierData buffers. - GetModifierDelta(RouteModifierData modifierData, float policyAdjustment, Entity policy, ComponentLookup<PolicySliderData> policySliderData) (static) — maps a policy slider value (or raw adjustment) into the modifier's numeric delta using the slider range and the modifierData range. - GetPolicyAdjustmentFromModifierDelta(RouteModifierData modifierData, float modifierDelta, PolicySliderData sliderData) (static) — inverse mapping from modifier delta back to policy slider adjustment. - AddModifierData(ref RouteModifier modifier, RouteModifierData modifierData, float delta) (static) — combines a single modifier delta into an existing RouteModifier using the modifier's mode (Relative, Absolute, InverseRelative). - GetDeltaFromModifier(RouteModifier modifier, RouteModifierData modifierData) (static) — extracts the stored delta corresponding to modifierData's mode. - AddModifier(DynamicBuffer<RouteModifier> modifiers, RouteModifierData modifierData, float delta) (private static) — ensures the modifiers buffer has an entry at the modifier type index and applies AddModifierData.

These nested utilities encapsulate the policy-to-route translation logic, and are intended to be used internally by the job.

Usage Example

// Example: from another SystemBase you can compute the numeric modifier delta
// corresponding to a policy entity and a given policy adjustment (e.g. slider value).
protected override void OnUpdate()
{
    // Get a read-only lookup for slider data
    var sliderLookup = GetComponentLookup<PolicySliderData>(isReadOnly: true);

    // Suppose you already have a RouteModifierData `modifierData`, a float policyAdjustment,
    // and an Entity policyEntity (policy prefab entity).
    float modifierDelta = RouteModifierInitializeSystem.RouteModifierRefreshData
        .GetModifierDelta(modifierData, policyAdjustment, policyEntity, sliderLookup);

    // You can then use AddModifierData to apply that delta to a RouteModifier instance:
    RouteModifier routeModifier = default;
    RouteModifierInitializeSystem.RouteModifierRefreshData.AddModifierData(ref routeModifier, modifierData, modifierDelta);

    // (In practice, route modifiers are filled by the RouteModifierInitializeSystem job,
    // but these helpers are useful if you need to calculate or inspect modifier values
    // from a custom tool/system.)
}

Notes and tips: - The system runs only for newly created routes (Created tag), which avoids re-processing existing routes each frame. - Modifier value mapping respects the slider ranges (if present) and performs saturation/clamping to keep deltas in expected ranges. - Modifier modes (Relative, Absolute, InverseRelative) change how deltas are stored and combined; use GetDeltaFromModifier / AddModifierData to interact correctly.