Game.Simulation.LodgingProviderSystem
Assembly:
Assembly-CSharp (game runtime assembly; exact assembly name may vary)
Namespace:
Game.Simulation
Type:
class
Base:
GameSystemBase
Summary:
LodgingProviderSystem is a simulation system that processes lodging (hotel) providers for tourist households. It runs a Burst-compiled IJobChunk (LodgingProviderJob) over provider entities on a specific update frame to:
- compute available room counts,
- update provider prices,
- charge tourist renters daily lodging fees (distributed over updates),
- transfer money from renters to the provider entity,
- consume lodging and tourist service resources,
- remove non-tourist renters from provider buffers,
- release rooms when occupancy exceeds capacity,
and record the provider's free rooms and current price. The system uses an EndFrameBarrier to apply structural/component changes via an EntityCommandBuffer.ParallelWriter.
Fields
-
private static readonly int kUpdatesPerDay
Holds the number of simulation updates per in-game day used for per-update resource/fee calculations. Value: 32. -
private SimulationSystem m_SimulationSystem
Reference to the SimulationSystem for obtaining the global frame index used to compute the update frame this system should process. -
private EndFrameBarrier m_EndFrameBarrier
Barrier system used to create an EntityCommandBuffer.ParallelWriter for safe structural/component mutations from the job. -
private ResourceSystem m_ResourceSystem
Reference to ResourceSystem used to read resource prefabs and register the system as a reader of prefabs. -
private EntityQuery m_ProviderQuery
EntityQuery that selects lodging provider entities. The query requires components like LodgingProvider, PropertyRenter, ServiceAvailable, UpdateFrame and PrefabRef, and filters out Deleted and Temp entities. -
private EntityQuery m_LeisureParameterQuery
EntityQuery to fetch singleton LeisureParametersData which contains parameters used for tourist lodging consumption and service consumption per day. -
private TypeHandle __TypeHandle
Internal struct that stores ComponentTypeHandle / SharedComponentTypeHandle / BufferTypeHandle and ComponentLookup handles used to build the job's data. Assigned during OnCreateForCompiler. -
(nested)
private struct LodgingProviderJob : IJobChunk
Burst-compiled job that executes the provider logic per archetype chunk. See Methods section for details. -
(nested)
private struct TypeHandle
Holds per-type handles and has a __AssignHandles method used to initialize handles from a SystemState.
Properties
- This system exposes no public properties.
Constructors
public LodgingProviderSystem()
Default constructor. System initialization is performed in OnCreate.
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
Returns the system's update interval (an integer tick interval). The method computes: 262144 / (kUpdatesPerDay * 16). This controls how frequently the system is scheduled relative to the engine's scheduling granularity. -
public static int GetRoomCount(int2 lotSize, int level, BuildingPropertyData buildingPropertyData)
Utility to compute the number of rooms provided by a building: returns (int)((lotSize.x * lotSize.y * level) * buildingPropertyData.m_SpaceMultiplier). Used to determine capacity (free rooms) for lodging providers. -
protected override void OnCreate()
Initializes system references and queries: - acquires SimulationSystem, EndFrameBarrier, ResourceSystem,
- constructs m_ProviderQuery to select lodging providers,
- constructs m_LeisureParameterQuery,
-
calls RequireForUpdate on both queries so the system only runs when matching entities exist.
-
protected override void OnUpdate()
Builds and schedules the LodgingProviderJob: - computes updateFrame using SimulationUtils.GetUpdateFrame with m_SimulationSystem.frameIndex, kUpdatesPerDay and a divisor of 16,
- fills a LodgingProviderJob struct with Component/Buffer/Shared handles (via __TypeHandle wrappers and InternalCompilerInterface), ComponentLookup references, resource prefabs and leisure parameters,
- schedules the job in parallel over m_ProviderQuery,
- registers the job dependency with the EndFrameBarrier and with m_ResourceSystem (as a prefabs reader).
The job uses the UpdateFrame shared component to only process providers whose UpdateFrame.m_Index matches the computed updateFrame.
-
private void __AssignQueries(ref SystemState state)
Internal helper used by the compiler-generated path to ensure queries are assigned. Implementation in this file is effectively a no-op (creates and disposes an EntityQueryBuilder) but is kept for compiler wiring. -
protected override void OnCreateForCompiler()
Compiler-invoked initialization that: - calls __AssignQueries,
- assigns type handles stored in __TypeHandle by calling __AssignHandles(ref base.CheckedStateRef).
Nested job behavior (LodgingProviderJob — summary of Execute): - For each chunk whose UpdateFrame.m_Index equals m_UpdateFrameIndex: - For each entity (provider) in the chunk: - If it has a PropertyRenter: - Resolve the property prefab and building data to compute roomCount via GetRoomCount. - Determine market price for Resource.Lodging via EconomyUtils.GetMarketPrice. - Compute a provider price: RoundToInt(2 * rent / roomCount + marketPrice). - Compute per-update charge per renter: ceil(price / kUpdatesPerDay). - Remove non-tourist renters from the Renter dynamic buffer. - If occupancy exceeds roomCount, drop renters from the end of the buffer, setting their TouristHousehold.m_Hotel to Entity.Null (issued via the command buffer). - Charge each remaining renter num2 money units (per-update portion) using EconomyUtils.AddResources and transfer the aggregated amount to the provider. - Consume provider's lodging and tourist service resources based on LeisureParameters (consumption scaled by kUpdatesPerDay). - Update ServiceAvailable and LodgingProvider components (price and free rooms). - If it lacks PropertyRenter, clear all Renter buffer entries.
Notes on thread-safety and architecture: - The job uses BufferLookup/ComponentLookup and a CommandBuffer.ParallelWriter to make safe writes/structural changes from the job. - The system registers job dependencies with EndFrameBarrier and ResourceSystem to ensure correct ordering.
Usage Example
// Querying room count for a prefab building (example usage outside the system)
using Unity.Mathematics;
using Game.Simulation;
using Game.Prefabs;
// assume buildingPropertyData and spawnableBuildingData are available:
int2 lotSize = new int2(4, 6); // example lot size
int level = spawnableBuildingData.m_Level;
int rooms = LodgingProviderSystem.GetRoomCount(lotSize, level, buildingPropertyData);
// Typical system lifecycle: system is created by the world and its OnCreate/OnUpdate are invoked
// by the game. You don't normally instantiate this directly.
If you want, I can also produce a short diagram or walkthrough of the LodgingProviderJob's per-renter and per-provider calculations (price formula, per-update charge distribution, and resource consumption).