Game.PostServicePathfindSetup
Assembly:
Assembly-CSharp
Namespace:
Game.Simulation
Type:
public struct PostServicePathfindSetup
Base:
System.ValueType
Summary:
PostServicePathfindSetup is a helper/worker struct used by the PathfindSetupSystem to prepare pathfinding targets related to postal services. It contains several IJobChunk implementations (burst-compiled) that scan entity chunks to enqueue or discover pathfinding targets for:
- Post vans (assigning delivery/collection targets based on current van state and queued dispatches),
- Mail transfer between storage/prefab entities and post facilities (import/export decisions),
- Mailboxes (prioritize mail pickup based on fill level and comfort),
- Post-van specific requests (matching PostVanRequests with available vans/facilities and service districts).
The struct stores EntityQueries and component handles/lookups used to schedule the jobs in parallel. Methods are provided to update the component handles and schedule each job, returning JobHandle dependencies to chain with other systems.
Fields
-
private EntityQuery m_PostVanQuery
Stores the query used to find either PostFacility or PostVan entities (any of) for the post-van setup job. Used by SetupPostVans to schedule the SetupPostVansJob across matching chunks. -
private EntityQuery m_MailTransferQuery
Query used to find entities relevant for mail transfer setup (post facilities with dispatch buffers or storage companies/prefabs). Used by SetupMailTransfer. -
private EntityQuery m_MailBoxQuery
Query to find mailboxes and related prefabs/stops for mail-box related setup. -
private EntityQuery m_PostVanRequestQuery
Query that finds PostVanRequest entities (excluding already dispatched or those with PathInformation) for post-van request processing. -
private EntityTypeHandle m_EntityType
Entity type handle updated per frame before scheduling jobs. Used to fetch entity arrays of chunks inside jobs. -
private ComponentTypeHandle<PathOwner> m_PathOwnerType
Read-only handle for PathOwner components (used for reading current path progress for vans). -
private ComponentTypeHandle<Owner> m_OwnerType
Read-only handle for Owner components (used to resolve owning company/service entity for vehicles/buildings). -
private ComponentTypeHandle<Game.Objects.OutsideConnection> m_OutsideConnectionType
Read-only handle to detect outside connections (used in mail transfer logic to filter imports/exports). -
private ComponentTypeHandle<ServiceRequest> m_ServiceRequestType
Read-only handle used when iterating service requests in PostVanRequestsJob. -
private ComponentTypeHandle<PostVanRequest> m_PostVanRequestType
Read-only handle used to read PostVanRequest components from chunks. -
private ComponentTypeHandle<Game.Buildings.PostFacility> m_PostFacilityType
Read-only handle for PostFacility components (facilities capabilities, flags). -
private ComponentTypeHandle<Game.Vehicles.PostVan> m_PostVanType
Read-only handle for PostVan components (van state, request count, path element time). -
private ComponentTypeHandle<Game.Routes.MailBox> m_MailBoxType
Read-only handle for MailBox components (mail amount). -
private ComponentTypeHandle<Game.Routes.TransportStop> m_TransportStopType
Read-only handle for TransportStop components (comfort factor used to alter mailbox priority). -
private ComponentTypeHandle<PrefabRef> m_PrefabRefType
Read-only handle to access prefab references for storage/company prefabs. -
private BufferTypeHandle<PathElement> m_PathElementType
Read-only buffer handle used to inspect/compute last path element/target of existing paths. -
private BufferTypeHandle<ServiceDispatch> m_ServiceDispatchType
Read-only buffer handle used for service dispatch queues attached to facilities. -
private BufferTypeHandle<Resources> m_ResourcesType
Read-only buffer handle for resource storage buffers on storage-company prefabs. -
private BufferTypeHandle<TradeCost> m_TradeCostType
Read-only handle for trade cost buffers used to evaluate buying/selling viability. -
private BufferTypeHandle<InstalledUpgrade> m_InstalledUpgradeType
Read-only handle for installed upgrades affecting storage limits or stats. -
private ComponentLookup<PathInformation> m_PathInformationData
Component lookup for PathInformation used to estimate durations of queued requests. -
private ComponentLookup<PostVanRequest> m_PostVanRequestData
Lookup for PostVanRequest component when resolving owner target data. -
private ComponentLookup<Game.Buildings.PostFacility> m_PostFacilityData
Lookup for PostFacility component when resolving facility flags for requests. -
private ComponentLookup<Game.Vehicles.PostVan> m_PostVanData
Lookup for PostVan component when resolving van flags/state from an entity id. -
private ComponentLookup<CurrentDistrict> m_CurrentDistrictData
Lookup for CurrentDistrict used to resolve district of a target for service district checks. -
private ComponentLookup<StorageLimitData> m_StorageLimitData
Lookup used to get storage limits for prefabs; used to decide import capacity. -
private ComponentLookup<StorageCompanyData> m_StorageCompanyData
Lookup used to determine which resources a storage company/prefab can store. -
private ComponentLookup<MailBoxData> m_MailBoxData
Lookup used to get mailbox capacity and related static data. -
private BufferLookup<PathElement> m_PathElements
Buffer lookup used to fetch cached PathElement buffers from request entities. -
private BufferLookup<ServiceDistrict> m_ServiceDistricts
Buffer lookup of ServiceDistricts used to check if two entities belong to compatible service districts.
Properties
- This struct has no public properties.
Constructors
public PostServicePathfindSetup(PathfindSetupSystem system)
Initializes queries and component/ buffer handles/lookups. The constructor builds multiple EntityQuery objects (for post vans, mail transfer, mailboxes and requests) and obtains ComponentTypeHandle/BufferTypeHandle/ComponentLookup/BufferLookup references from the provided PathfindSetupSystem. This prepares the struct for per-frame Update() calls on handles and subsequent job scheduling.
Methods
-
public JobHandle SetupPostVans(PathfindSetupSystem system, PathfindSetupSystem.SetupData setupData, JobHandle inputDeps)
Updates the relevant component handles (entity, post facility, post van, path owner, owner, buffer types, lookups) and schedules the SetupPostVansJob using JobChunkExtensions.ScheduleParallel with m_PostVanQuery. The job enqueues path targets for post vans and post facilities considering van state (disabled/returning/estimated full/empty), existing path elements in vans, service districts, and queued dispatches. Returns a JobHandle representing the scheduled job. -
public JobHandle SetupMailTransfer(PathfindSetupSystem system, PathfindSetupSystem.SetupData setupData, JobHandle inputDeps)
Updates component handles needed for mail transfer (prefab refs, outside connection, resources, trade costs, upgrades, storage lookups, service districts) and schedules SetupMailTransferJob across m_MailTransferQuery. The job evaluates whether storage-prefabs or post facilities should be import/export targets based on stored amounts, trade costs, facility flags and storage limits, then calls targetSeeker.FindTargets appropriately. Returns JobHandle. -
public JobHandle SetupMailBoxes(PathfindSetupSystem system, PathfindSetupSystem.SetupData setupData, JobHandle inputDeps)
Updates prefab/ref, mailbox and transport stop handles and schedules SetupMailBoxesJob on m_MailBoxQuery. The job computes a priority score for mailboxes (mail fill percentage plus comfort factor penalty) and enqueues them for pickup targets. -
public JobHandle SetupPostVanRequest(PathfindSetupSystem system, PathfindSetupSystem.SetupData setupData, JobHandle inputDeps)
Updates handles used by post-van requests and schedules PostVanRequestsJob across m_PostVanRequestQuery. This job matches PostVanRequest entities to van/facility owners, checks district compatibility, evaluates whether a van/facility can collect/deliver, and issues targetSeeker.FindTargets calls (with a randomized minor cost) for candidate requests. -
Nested job structs (burst-compiled IJobChunk implementations):
- SetupPostVansJob — handles post facilities and post vans chunk processing.
- SetupMailTransferJob — handles storage/prefab and post-facility transfer logic.
- SetupMailBoxesJob — handles mailbox prioritization and enqueuing targets.
- PostVanRequestsJob — handles mapping PostVanRequest -> request entity targets.
Notes about jobs: - All nested jobs are marked with [BurstCompile] and implement IJobChunk; they expect handles/lookups to be kept updated (calls to Update(system) are made just before scheduling). - The jobs rely heavily on read-only component handles and buffer lookups for thread safety. - They use PathfindSetupSystem.SetupData which contains targetSeeker instances used to discover/enqueue PathTarget or call targetSeeker.FindTargets.
Usage Example
// Example: scheduling post-service related pathfind setup from a PathfindSetupSystem
public void OnSetup(PathfindSetupSystem system)
{
// Create/initialize helper (typically stored by the system)
var postSetup = new PostServicePathfindSetup(system);
// Prepare a SetupData (this would be created by the PathfindSetupSystem)
PathfindSetupSystem.SetupData setupData = ...; // obtained from the system context
// Chain jobs as needed. Use inputDeps from prior work (or default)
JobHandle deps = default;
// Schedule jobs; each returns a JobHandle you can combine
deps = postSetup.SetupPostVans(system, setupData, deps);
deps = postSetup.SetupMailTransfer(system, setupData, deps);
deps = postSetup.SetupMailBoxes(system, setupData, deps);
deps = postSetup.SetupPostVanRequest(system, setupData, deps);
// The returned deps now represent all scheduled mailbox/post jobs.
// The PathfindSetupSystem will typically complete or combine these handles with other dependencies.
}
If you are modding: - Ensure you call Update(system) indirectly by invoking the provided Setup* methods before scheduling. - Be careful when modifying component types or buffer layouts — job code assumes specific components (PostFacility, PostVan, PathElement, ServiceDispatch, etc.).