Game.Simulation.GarbagePathfindSetup
Assembly:
Namespace: Game.Simulation
Type: struct
Base: System.ValueType
Summary:
{{ GarbagePathfindSetup is a helper struct used by the pathfinding setup system to create pathfinding targets for the garbage service. It contains EntityQueries, Component/Buffer type handles and Component/Buffer lookups required to schedule three main jobs that prepare pathfind targets for garbage collectors (facilities and trucks), garbage transfer (import/export/transport targets) and explicit garbage collection requests. The struct is designed to be used during the PathfindSetupSystem pass and schedules Burst-compiled IJobChunk jobs via ScheduleParallel to populate the Pathfind target queues. }}
Fields
-
private EntityQuery m_GarbageCollectorQuery
{{ Query matching entities that are either GarbageFacility or GarbageTruck and not deleted/destroyed/temp. Used by SetupGarbageCollector scheduling. }} -
private EntityQuery m_GarbageTransferQuery
{{ Query used for garbage transfer setup (facilities with ServiceDispatch and PrefabRef, and a secondary query for storage companies). Used by SetupGarbageTransfer. }} -
private EntityQuery m_GarbageCollectionRequestQuery
{{ Query to find GarbageCollectionRequest components that are not dispatched and have no PathInformation. Used by SetupGarbageCollectorRequest. }} -
private EntityTypeHandle m_EntityType
{{ Cached EntityTypeHandle for jobs that access entity arrays in chunks. }} -
private ComponentTypeHandle<PathOwner> m_PathOwnerType
{{ Component type handle for PathOwner; read-only in jobs. }} -
private ComponentTypeHandle<Owner> m_OwnerType
{{ Component type handle for Owner; read-only in jobs. }} -
private ComponentTypeHandle<Game.Objects.OutsideConnection> m_OutsideConnectionType
{{ Component type handle to detect outside connection entities (read-only). }} -
private ComponentTypeHandle<ServiceRequest> m_ServiceRequestType
{{ Component type handle for ServiceRequest components (read-only). }} -
private ComponentTypeHandle<GarbageCollectionRequest> m_GarbageCollectionRequestType
{{ Component type handle for GarbageCollectionRequest components (read-only). }} -
private ComponentTypeHandle<Game.Buildings.GarbageFacility> m_GarbageFacilityType
{{ Component type handle to read GarbageFacility data in chunks. }} -
private ComponentTypeHandle<Game.Vehicles.GarbageTruck> m_GarbageTruckType
{{ Component type handle to read GarbageTruck data in chunks. }} -
private ComponentTypeHandle<PrefabRef> m_PrefabRefType
{{ Component type handle for PrefabRef (read-only). }} -
private BufferTypeHandle<PathElement> m_PathElementType
{{ Buffer handle for PathElement buffers (read-only). Used when inspecting existing paths on vehicles/owners. }} -
private BufferTypeHandle<ServiceDispatch> m_ServiceDispatchType
{{ Buffer handle for a ServiceDispatch buffer (read-only). Used to inspect queued service requests on facilities/trucks. }} -
private BufferTypeHandle<Resources> m_ResourcesType
{{ Buffer handle for resource buffers (read-only). Used by transfer/setup queries. }} -
private BufferTypeHandle<TradeCost> m_TradeCostType
{{ Buffer handle for trade cost buffers (read-only). Used by transfer setup. }} -
private BufferTypeHandle<InstalledUpgrade> m_InstalledUpgradeType
{{ Buffer handle for installed upgrades (read-only), cached in the struct for potential use with upgrades/storage. }} -
private ComponentLookup<PathInformation> m_PathInformationData
{{ ComponentLookup for PathInformation (read-only). Used to estimate durations for queued path requests. }} -
private ComponentLookup<GarbageCollectionRequest> m_GarbageCollectionRequestData
{{ ComponentLookup for GarbageCollectionRequest (read-only). Used to get owner-request defaults when probing owners/targets. }} -
private ComponentLookup<Game.Objects.OutsideConnection> m_OutsideConnections
{{ Lookup to detect if an owner or location is an outside connection (read-only). Influences cost/priority. }} -
private ComponentLookup<Game.City.City> m_CityData
{{ Lookup to get City-level settings, e.g., whether outside services are allowed. }} -
private ComponentLookup<CurrentDistrict> m_CurrentDistrictData
{{ Lookup to map entities to their current district (read-only). Used when checking district compatibility. }} -
private ComponentLookup<Game.Vehicles.GarbageTruck> m_GarbageTruckData
{{ Lookup used to detect if a target entity is a truck prefab/vehicle or a facility. }} -
private ComponentLookup<StorageLimitData> m_StorageLimitData
{{ Lookup for storage limit information (read-only). Used by transfer setup to evaluate storage capacity/demand. }} -
private ComponentLookup<StorageCompanyData> m_StorageCompanyData
{{ Lookup for storage company data (read-only). Used in transfer setup. }} -
private BufferLookup<PathElement> m_PathElements
{{ BufferLookup for PathElement buffers on arbitrary entities (read-only). Used to find the last path element on queued requests. }} -
private BufferLookup<ServiceDistrict> m_ServiceDistricts
{{ BufferLookup of ServiceDistricts for entities (read-only). Used by AreaUtils.CheckServiceDistrict to ensure service district compatibility. }} -
private CitySystem m_CitySystem
{{ Reference to the CitySystem (managed). Used to access the current City entity when checking options like ImportOutsideServices. }}
Properties
- None
{{ This struct exposes no public properties; it provides methods to schedule jobs. }}
Constructors
public GarbagePathfindSetup(PathfindSetupSystem system)
{{ Initializes all EntityQueries, component type handles, buffer handles and component/buffer lookups used by the garbage pathfind setup jobs. It also caches a reference to the CitySystem. This constructor must be called before invoking the Setup* methods so handles/queries are created tied to the provided system/world. }}
Methods
public JobHandle SetupGarbageCollector(PathfindSetupSystem system, PathfindSetupSystem.SetupData setupData, JobHandle inputDeps)
{{ Schedules the Burst-compiled SetupGarbageCollectorsJob across m_GarbageCollectorQuery. This job does two main things:- For garbage facilities: finds targets for a facility to collect from (based on facility flags, accept/deliver priorities, industrial waste restrictions and service district checks), calling targetSeeker.FindTargets(entity, cost).
-
For garbage trucks: for each truck, evaluates current queued service dispatches, path owner state and truck flags to either enqueue PathTarget entries (when a tail path element exists) or call FindTargets to build new targets. The method updates required type handles and returns the scheduled JobHandle. }}
-
public JobHandle SetupGarbageTransfer(PathfindSetupSystem system, PathfindSetupSystem.SetupData setupData, JobHandle inputDeps)
{{ Schedules the Burst-compiled SetupGarbageTransferJob across m_GarbageTransferQuery. This job evaluates garbage facility import/export/transport needs based on SetupTarget settings and facility priorities (AcceptGarbagePriority / DeliverGarbagePriority). It filters out outside connections and requires transport trucks if the setup target demands transport. It calls FindTargets for matching facilities with a cost scaled by priority delta. Returns the scheduled JobHandle. }} -
public JobHandle SetupGarbageCollectorRequest(PathfindSetupSystem system, PathfindSetupSystem.SetupData setupData, JobHandle inputDeps)
{{ Schedules the Burst-compiled GarbageCollectorRequestsJob across m_GarbageCollectionRequestQuery. This job iterates service requests and garbage collection requests to create pathfind targets representing individual pickup requests. It respects reversed requests, industrial-waste flags, district/service-district compatibility, and uses a per-chunk Random seed to slightly randomize target cost. It uses PathInformation and existing prefab/truck checks to identify the appropriate service entity. Returns the scheduled JobHandle. }} -
Inner job structs (all private and BurstCompile):
SetupGarbageCollectorsJob : IJobChunk
{{ Implements Execute to handle both facilities and trucks in the same query. Uses many component lookups and buffer accessors to compute costs and enqueue path targets or call FindTargets on the target seeker. Contains logic for industrial waste handling, outside connections, existing path tail reuse and per-request duration estimates. }}SetupGarbageTransferJob : IJobChunk
{{ Implements Execute to examine garbage facilities (excluding outside connections) and add import/export targets based on facility priorities and SetupTarget flags. }}GarbageCollectorRequestsJob : IJobChunk
{{ Implements Execute to convert ServiceRequest + GarbageCollectionRequest entries into pathfind targets, using district checks and randomized cost adjustments. }}
Usage Example
// Example usage inside PathfindSetupSystem or a system that runs the pathfind setup pass:
public void ScheduleGarbageSetup(PathfindSetupSystem system, PathfindSetupSystem.SetupData setupData, JobHandle deps)
{
GarbagePathfindSetup garbageSetup = new GarbagePathfindSetup(system);
// schedule collector/truck target setup
deps = garbageSetup.SetupGarbageCollector(system, setupData, deps);
// schedule transfer (import/export) target setup
deps = garbageSetup.SetupGarbageTransfer(system, setupData, deps);
// schedule explicit collection request targets
deps = garbageSetup.SetupGarbageCollectorRequest(system, setupData, deps);
// pass 'deps' forward to dependency management (Complete / combine as needed)
}
{{ Notes: - All three scheduled jobs are Burst-compiled IJobChunk jobs and use ScheduleParallel. Ensure the SetupData passed in contains valid target seeker entries and random seeds. - The jobs heavily rely on ECS Component/Buffer lookups; update handles (via .Update(system)) before scheduling if the world changed. - Behavior accounts for city options (ImportOutsideServices), service district membership, industrial-waste-only flags and existing queued paths to avoid redundant pathfinding work. }}