Game.Simulation.TouristFindTargetSystem
Assembly: Assembly-CSharp (game runtime)
Namespace: Game.Simulation
Type: class
Base: GameSystemBase
Summary:
TouristFindTargetSystem is a simulation system that processes tourist households which are seeking lodging or leisure targets. It schedules pathfinding for tourists, handles pathfind results (assigning targets or moving households away), queues meetings for leisure visits, and attempts to reserve hotel rooms when the path destination is a lodging provider. The system uses burst-compiled jobs (TouristFindTargetJob and HotelReserveJob), communicates with PathfindSetupSystem and AddMeetingSystem, and defers entity structural changes using an EndFrameBarrier command buffer. It runs periodically (UpdateInterval = 16) and maintains a native queue for hotel reservation actions.
Fields
-
private EntityQuery m_SeekerQuery
Query matching tourist households that are currently seeking lodging (TouristHousehold + LodgingSeeker) and not already moving/targeted/deleted/temp. Used as the job input. -
private ComponentTypeSet m_PathfindTypes
Component set used to add PathInformation components to entities that need pathfinding. -
private EndFrameBarrier m_EndFrameBarrier
System barrier used to create command buffers for structural changes that must be applied at end-of-frame. -
private PathfindSetupSystem m_PathfindSetupSystem
Reference to the pathfinding setup system; used to enqueue pathfinding setup items. -
private AddMeetingSystem m_AddMeetingSystem
Reference to the meeting-adding system; used to enqueue leisure/activity meetings for tourist households. -
private NativeQueue<HotelReserveAction> m_HotelReserveQueue
A persistent native queue used to collect hotel reservation actions from the pathfinding job and consumed later by HotelReserveJob. -
private TypeHandle __TypeHandle
Generated container of type handles / lookups used for chunk/job access. Assigned in OnCreateForCompiler.
(Also contains nested private types: HotelReserveAction, TouristFindTargetJob, HotelReserveJob, and TypeHandle which implement the main job logic and reservation processing.)
Properties
- This system does not expose public properties.
Constructors
public TouristFindTargetSystem()
Default constructor. The system is created/managed by the ECS world (marked with Preserve attribute for runtime linking).
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
Returns the update interval for the system. TouristFindTargetSystem returns 16, so it runs every 16 simulation ticks (or frames according to the game's scheduling). -
[Preserve] protected override void OnCreate()
Initializes system references and resources: - Obtains EndFrameBarrier, PathfindSetupSystem and AddMeetingSystem instances from the world.
- Creates an EntityQuery for tourist seekers.
- Initializes the ComponentTypeSet for pathfind components.
- Allocates the persistent NativeQueue used for hotel reservations.
-
Calls RequireForUpdate to only run when seekers exist.
-
[Preserve] protected override void OnDestroy()
Cleans up resources: disposes the persistent m_HotelReserveQueue and calls base.OnDestroy(). -
[Preserve] protected override void OnUpdate()
Main scheduling method. Prepares and schedules: - TouristFindTargetJob (IJobChunk, Burst) executed in parallel over matched seeker chunks. Responsibilities:
- If entity lacks PathInformation, add PathInformation and enqueue a pathfind request (pedestrian tourist origin/destination) to PathfindSetupSystem.
- If PathInformation exists and is not pending: process results. If path found:
- If destination is a lodging with renters and lodging provider component, enqueue a HotelReserveAction to m_HotelReserveQueue; otherwise enqueue an AddMeeting for leisure attractions.
- Add a Target component pointing to the destination. If no destination, schedule household to move away.
- Remove PathInformation and LodgingSeeker components once a final decision is taken.
- Uses EndFrameBarrier command buffer (AsParallelWriter) for structural changes.
- HotelReserveJob (IJob, Burst) scheduled after the chunk job:
- Dequeues HotelReserveAction items and, if lodging has free rooms and types match, reserves a room: decrements free rooms, appends Renter to the lodging's buffer, sets the TouristHousehold.m_Hotel, and removes LodgingSeeker from the household. If no free rooms remain, re-add LodgingSeeker.
-
Ensures proper dependency wiring with PathfindSetupSystem and AddMeetingSystem queues and registers producer handles with EndFrameBarrier.
-
private void __AssignQueries(ref SystemState state)
Compiler helper used in OnCreateForCompiler to initialize runtime query(s). In this generated code it currently contains a no-op builder. -
protected override void OnCreateForCompiler()
Compiler-generated helper that assigns type handles and prepares the system when compiled for burst/jobs. Calls __AssignQueries and __TypeHandle.__AssignHandles.
Usage Example
// Typical usage from other code/mod: retrieve the system from the world to inspect or trigger behavior.
var world = World.DefaultGameObjectInjectionWorld;
var touristSystem = world.GetExistingSystemManaged<Game.Simulation.TouristFindTargetSystem>();
// The system runs automatically according to its schedule. You can ensure it exists or log its presence:
if (touristSystem != null) {
Debug.Log("TouristFindTargetSystem is available and will process tourist seekers every 16 ticks.");
}
(Internal job example — showing what OnCreate does inside the system:)
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
m_EndFrameBarrier = base.World.GetOrCreateSystemManaged<EndFrameBarrier>();
m_PathfindSetupSystem = base.World.GetOrCreateSystemManaged<PathfindSetupSystem>();
m_AddMeetingSystem = base.World.GetOrCreateSystemManaged<AddMeetingSystem>();
m_SeekerQuery = GetEntityQuery(/* TouristHousehold + LodgingSeeker ... */);
m_PathfindTypes = new ComponentTypeSet(ComponentType.ReadWrite<PathInformation>());
m_HotelReserveQueue = new NativeQueue<HotelReserveAction>(Allocator.Persistent);
RequireForUpdate(m_SeekerQuery);
}
Notes: - The system relies heavily on ECS jobs and burst-compiled structs for performance and uses command buffers from EndFrameBarrier to make structural changes at a safe time. - When modding, interact with this system indirectly (e.g., by adding/removing components that match its query) or by obtaining references to its dependent systems (PathfindSetupSystem, AddMeetingSystem). Direct modification of internal fields is not recommended.