Game.GameModeWealthSupportSystem
Assembly: Assembly-CSharp
Namespace: Game.Simulation
Type: class
Base: GameSystemBase
Summary:
System that enforces a minimum household wealth for citizens when the current game mode has "support poor citizens" enabled. It runs a Burst-compiled IJobChunk (SupportWageJob) over household entities and top-ups money (Resource.Money) for households whose total wealth is below the configured minimum. The system reads ModeSettingData on game load to decide whether it should be enabled and what minimum wealth to apply. It excludes tourists, deleted and temporary households from processing.
Fields
-
public static readonly System.Int32 kUpdatesPerDay
Constant (32) used to compute update timing. The system spreads work across multiple update frames; this constant defines how many update ticks per in-game day are considered when computing which households to process on each update. -
private SimulationSystem m_SimulationSystem
Reference to the SimulationSystem used to obtain the global frame index for computing the current update frame. -
private EntityQuery m_GameModeSettingQuery
EntityQuery used to fetch the ModeSettingData singleton. The system requires this query to be non-empty to run. -
private EntityQuery m_HouseholdGroup
EntityQuery selecting households to process. The query requires Household, UpdateFrame and Resources components and HouseholdCitizen, and explicitly excludes TouristHousehold, Deleted and Temp markers. -
private System.Int32 m_MinimumWealth
Configured minimum wealth threshold read from ModeSettingData when the game loads. Households at or below this value will be topped up to this amount. -
private struct SupportWageJob
(nested, private, Burst-compiled)
IJobChunk implementation that does the per-chunk work. Important fields: public System.UInt32 m_UpdateFrameIndex
— the update frame index this job should operate on (jobs skip chunks whose UpdateFrame shared component does not match).public System.Int32 m_MinimumWealth
— minimum wealth threshold used when topping up.public SharedComponentTypeHandle<UpdateFrame> m_UpdateFrameType
— handle for the UpdateFrame shared component.public ComponentTypeHandle<Household> m_HouseholdType
— read-only handle for the Household component.public BufferTypeHandle<Resources> m_ResourcesType
— handle for the Resources dynamic buffer on households.- Execute logic: for each household in the chunk whose shared UpdateFrame matches m_UpdateFrameIndex, compute total household wealth via EconomyUtils.GetHouseholdTotalWealth and, if <= m_MinimumWealth, call EconomyUtils.AddResources(Resource.Money, m_MinimumWealth - householdTotalWealth, resources).
Properties
- (none)
This system has no public properties to expose; all state is stored in private fields.
Constructors
public GameModeWealthSupportSystem()
Default constructor. No custom initialization is performed here; the main setup happens in OnCreate. Preserved for serialization.
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
Returns the system's update interval. Implementation: return 262144 / (kUpdatesPerDay * 16). This value controls how often the system's OnUpdate is invoked by the simulation scheduler and is chosen to distribute updates across frames and ensure the update frame calculation aligns with kUpdatesPerDay and internal tick resolution. -
[Preserve] protected override void OnCreate()
Initializes the system: - Obtains SimulationSystem from the World.
- Creates m_GameModeSettingQuery to read ModeSettingData singleton.
- Builds m_HouseholdGroup query to select households with Household, UpdateFrame, Resources, HouseholdCitizen and excluding TouristHousehold, Deleted, Temp.
-
Calls RequireForUpdate on both queries so the system only runs when both are present.
-
[Preserve] protected override void OnUpdate()
Main update loop: - Computes the current update frame using SimulationUtils.GetUpdateFrame(m_SimulationSystem.frameIndex, kUpdatesPerDay, 16).
- Constructs a SupportWageJob with the computed update frame index, the configured minimum wealth, and component type handles (UpdateFrame, Household read-only, Resources buffer).
-
Schedules the job against m_HouseholdGroup using JobChunkExtensions.Schedule and updates base.Dependency accordingly.
-
protected override void OnGameLoaded(Context serializationContext)
Runs when the game finishes loading. Behavior: - If the ModeSettingData singleton is missing (m_GameModeSettingQuery is empty) the system disables itself.
-
Otherwise reads ModeSettingData singleton and, if ModeSettingData.m_Enable && ModeSettingData.m_SupportPoorCitizens are both true, sets m_MinimumWealth from the singleton and enables the system. Otherwise disables the system.
-
(SupportWageJob)
void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
Per-chunk execution described above; uses shared UpdateFrame to only process households assigned to the current frame and uses EconomyUtils helpers to compute and add money to household resources.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// System sets up its queries here; nothing else is required from mods to use it.
}
// The system reads ModeSettingData on game load. To enable support for poor citizens,
// ensure a ModeSettingData singleton is present and configured, for example:
ModeSettingData settings = new ModeSettingData {
m_Enable = true,
m_SupportPoorCitizens = true,
m_MinimumWealth = 1000
};
// Persist or create the singleton in the world so GameModeWealthSupportSystem will pick it up after loading.
Notes and cautions: - The system runs as an ECS system and schedules a Burst-compiled job; editing its private fields from other code is not supported. Configure behavior via ModeSettingData instead. - Households marked as tourist, deleted, or temporary are explicitly excluded. - The job uses EconomyUtils.GetHouseholdTotalWealth and EconomyUtils.AddResources(Resource.Money, ...), so any changes to those helper functions will affect how top-ups are calculated/applied.