Game.Simulation.CompanyMoveAwaySystem
Assembly: Assembly-CSharp.dll
Namespace: Game.Simulation
Type: class
Base: GameSystemBase
Summary:
CompanyMoveAwaySystem is a simulation system that periodically checks processing companies (workplaces) for bankruptcy / move-away conditions and marks them to be removed. It runs in two phases implemented as parallel IJobChunk jobs:
- CheckMoveAwayJob: runs per update frame for a subset of companies, computes company total worth (using resources, owned vehicles, prefabs, and resource/workplace data), evaluates a move-away chance (taxes, services, office/industrial data, work provider data) and adds the MovingAway component to companies that should leave.
- MovingAwayJob: processes entities that have MovingAway — places their property on the market (PropertyToBeOnMarket), creates RentersUpdated events, removes WorkProvider notifications, and finally marks the company entity as Deleted.
The system uses other systems (SimulationSystem, ResourceSystem, TaxSystem, EndFrameBarrier, IconCommandSystem) and schedules jobs with correct dependencies (including EndFrameBarrier command buffers and resource-prefab read registration). It requires EconomyParameterData and WorkProviderParameterData to be present.
Fields
-
public static readonly System.Int32 kUpdatesPerDay
Constant controlling how many game updates per in-game day the system uses for frame indexing (value: 16). Used to compute which update-frame the system should run on. -
private Unity.Entities.EntityQuery m_CompanyQuery
Query selecting processing companies to evaluate for move-away (reads ProcessingCompany, PropertyRenter, WorkProvider, Resources, PrefabRef; excludes ExtractorCompany, MovingAway, Deleted, Temp). -
private Unity.Entities.EntityQuery m_MovingAwayQuery
Query selecting companies that have been marked MovingAway to finalize their removal and related world changes. -
private Unity.Entities.EntityQuery m_EconomyParameterQuery
Query used to fetch the EconomyParameterData singleton (contains bankruptcy limit and other economy parameters). -
private Unity.Entities.EntityArchetype m_RentEventArchetype
Archetype used to create RentersUpdated event entities when a property is put on the market. -
private SimulationSystem m_SimulationSystem
Reference to the simulation system (used to compute update frame). -
private EndFrameBarrier m_EndFrameBarrier
EndFrameBarrier used to create an EntityCommandBuffer.ParallelWriter for safe structural changes from jobs. -
private ResourceSystem m_ResourceSystem
Reference to the resource system providing resource prefabs and registration to read them from jobs. -
private TaxSystem m_TaxSystem
Reference to the tax system used to obtain current tax rates for company move-away chance calculations. -
private IconCommandSystem m_IconCommandSystem
Used to remove workplace notification icons via an IconCommandBuffer when companies leave. -
private TypeHandle __TypeHandle
Compiler-generated struct that caches Entity/Component/Buffer handles used by jobs (EntityTypeHandle, PrefabRef handle, Resources buffer handle, etc). -
private Unity.Entities.EntityQuery __query_731167828_0
Compiler-generated query used to get WorkProviderParameterData (used by MovingAwayJob for prefabs of notifications).
Properties
- (No public properties)
This system does not expose public properties.
Constructors
public CompanyMoveAwaySystem()
Default constructor. System initialization is performed in OnCreate.
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
Returns the update interval used by the simulation framework for scheduling this system. It uses the kUpdatesPerDay constant to compute a scaled interval. Modders usually don't need to change this unless altering how frequently company move-away checks run. -
protected override void OnCreate()
Initializes system references and entity queries: - Gets references to SimulationSystem, EndFrameBarrier, ResourceSystem, TaxSystem, IconCommandSystem.
- Builds m_CompanyQuery and m_MovingAwayQuery with the required component filters used by the jobs.
- Creates m_RentEventArchetype (Event + RentersUpdated).
-
Declares required singletons (WorkProviderParameterData and EconomyParameterData) so the system runs only when data exists.
-
protected override void OnUpdate()
Main scheduling method: - Computes the current update frame using SimulationUtils.GetUpdateFrame(..., kUpdatesPerDay, 16).
- If m_CompanyQuery is not empty, schedules CheckMoveAwayJob in parallel:
- The job reads company resources, owned vehicles, prefab/workplace data, service availability, industrial data, work provider data, tax rates, and economy parameters.
- Uses EconomyUtils and CompanyUtils to determine total worth and chance to move away.
- Adds MovingAway component to companies that meet bankruptcy threshold or random move-away chance.
- Registers job with EndFrameBarrier and ResourceSystem for proper synchronization.
- If m_MovingAwayQuery is not empty, schedules MovingAwayJob in parallel:
- For each MovingAway company, if its property is valid and not already on market/abandoned, adds PropertyToBeOnMarket and creates a RentersUpdated event entity.
- Removes any educated/uneducated notification icons from the WorkProvider (via IconCommandBuffer).
- Adds Deleted component to the company entity.
-
Ensures dependencies are combined and registered with the EndFrameBarrier.
-
private void __AssignQueries(ref SystemState state)
Compiler-generated helper that builds an EntityQuery for WorkProviderParameterData (including systems). Called from OnCreateForCompiler to initialize __query_731167828_0. -
protected override void OnCreateForCompiler()
Compiler-time helper called during system creation to assign handles and queries (__AssignQueries and TypeHandle.__AssignHandles). Not typically used directly by modders. -
(Nested types) CheckMoveAwayJob and MovingAwayJob are private IJobChunk implementations. Key points:
- CheckMoveAwayJob: uses RandomSeed, update-frame shared component, reads buffers and component lookups to compute bankruptcy/move-away and writes MovingAway via a parallel ECB.
- MovingAwayJob: uses an ECB and IconCommandBuffer to change property market status, spawn rent events, remove notifications and mark Deleted.
Usage Example
// Mark a specific company entity to move away manually (outside of the scheduled jobs).
// This can be used in a mod to force a company to leave and trigger the same logic
// processed by MovingAwayJob on the next update.
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
if (em.HasComponent<ProcessingCompany>(companyEntity) && !em.HasComponent<MovingAway>(companyEntity))
{
em.AddComponent<MovingAway>(companyEntity);
}
// Alternatively, if you need to create the system or inspect its queries in a custom system:
protected override void OnCreate()
{
base.OnCreate();
var sys = World.GetOrCreateSystemManaged<Game.Simulation.CompanyMoveAwaySystem>();
// The system will run automatically per its schedule; you can also access queries through reflection
// or by copying relevant query logic shown in this documentation if you need a custom behavior.
}
If you want to adjust when companies are considered for move-away, modify the logic used by CompanyUtils.GetCompanyMoveAwayChance or EconomyParameterData (bankruptcy limit) rather than changing this system directly.