Game.Simulation.ResourcePathfindSetup
Assembly: Assembly-CSharp
Namespace: Game.Simulation
Type: struct
Base: System.ValueType
Summary:
ResourcePathfindSetup prepares and schedules pathfinding setup jobs for resource-related logistics in the simulation. It provides three main setup flows used by the PathfindSetupSystem: determining resource sellers (where to buy resources), export targets (where to sell/export resources), and storage transfer requests (balancing transfers between storage buildings and outside connections). The struct builds EntityQueries, maintains Component/Buffer lookups and handles, and schedules Burst-compiled IJobChunk jobs that analyze entity buffers and components to find candidate pathfind targets for the Pathfind system.
Fields
-
public static readonly float kOutsideConnectionAmountBasedPenalty
Constant penalty factor applied to scoring when evaluating outside connections as trade targets. -
public static readonly float kCargoStationAmountBasedPenalty
Constant penalty factor applied per amount for cargo transport stations when scoring. -
public static readonly float kCargoStationPerRequestPenalty
Constant penalty per queued request at cargo stations used in scoring. -
public static readonly int kCargoStationVehiclePenalty
Penalty factor (integer) applied based on vehicle counts for cargo stations. -
public static readonly int kCargoStationMaxRequestAmount
Max request amount constant for cargo locations. -
public static readonly int kCargoStationMaxTripNeededQueue
Max length for the trip-needed queue at cargo stations. -
private EntityQuery m_ResourceSellerQuery
EntityQuery used to select entities that can act as resource sellers (buffers + either StorageCompany, CargoTransportStation or ResourceSeller). -
private EntityQuery m_ExportTargetQuery
EntityQuery for potential export targets (storage companies with resources and trade costs). -
private EntityQuery m_StorageQuery
EntityQuery used by storage-transfer job to select storage entities (StorageCompany + PrefabRef, excluding processing companies and temp/deleted). -
private ResourceSystem m_ResourceSystem
Reference to the global ResourceSystem used for registering readers and prefabs access during job scheduling. -
private EntityTypeHandle m_EntityType
Cached EntityTypeHandle used by IJobChunk executions. -
private ComponentTypeHandle<Game.Objects.OutsideConnection> m_OutsideConnectionType
ComponentTypeHandle for outside-connection component. -
private ComponentTypeHandle<Game.Companies.StorageCompany> m_StorageCompanyType
ComponentTypeHandle for storage company component. -
private ComponentTypeHandle<PrefabRef> m_PrefabType
ComponentTypeHandle for prefab references. -
private BufferTypeHandle<TradeCost> m_TradeCostType
BufferTypeHandle for TradeCost buffers. -
private BufferTypeHandle<StorageTransferRequest> m_StorageTransferRequestType
BufferTypeHandle for StorageTransferRequest buffers. -
private BufferTypeHandle<Game.Economy.Resources> m_ResourceType
BufferTypeHandle for resource buffers stored on entities. -
private BufferTypeHandle<OwnedVehicle> m_OwnedVehicleType
Buffer handle for owned vehicle buffers (used for transport capacity checks). -
private BufferTypeHandle<InstalledUpgrade> m_InstalledUpgradeType
Buffer handle for installed upgrades applied to buildings/prefabs. -
private BufferTypeHandle<TripNeeded> m_TripNeededType
Buffer handle for TripNeeded queue buffers. -
private ComponentLookup<Game.Objects.OutsideConnection> m_OutsideConnections
ComponentLookup for outside connections, used in jobs to test components on arbitrary entities. -
private ComponentLookup<ServiceCompanyData> m_ServiceCompanies
Lookup for service company data (read-only). -
private ComponentLookup<ServiceAvailable> m_ServiceAvailables
Lookup for service available counts for service buildings. -
private ComponentLookup<Game.Companies.StorageCompany> m_StorageCompanys
Lookup for storage company component instances. -
private ComponentLookup<StorageLimitData> m_StorageLimits
Lookup for storage limit data (per-prefab storage limits). -
private ComponentLookup<TransportCompanyData> m_TransportCompanyData
Lookup for transport company data (max transports etc). -
private ComponentLookup<Game.Buildings.CargoTransportStation> m_CargoTransportStations
Lookup used to identify cargo station buildings. -
private ComponentLookup<PropertyRenter> m_PropertyRenters
Lookup for property renter info (used to check building renting state). -
private ComponentLookup<PrefabRef> m_Prefabs
Lookup for prefab refs for arbitrary entities. -
private ComponentLookup<IndustrialProcessData> m_IndustrialProcessDatas
Lookup for industrial process specs for prefabs. -
private ComponentLookup<ResourceData> m_ResourceDatas
Lookup for resource metadata. -
private ComponentLookup<StorageCompanyData> m_StorageCompanyDatas
Lookup for storage company prefab data (what resources are stored etc). -
private ComponentLookup<SpawnableBuildingData> m_SpawnableBuildingDatas
Lookup for spawnable building metadata (level, lot size). -
private ComponentLookup<BuildingData> m_BuildingDatas
Lookup for building data (lot size etc) used in storage limit adjustments. -
private ComponentLookup<Building> m_Buildings
Lookup for Building components (to check options like Inactive). -
private ComponentLookup<Game.Vehicles.DeliveryTruck> m_DeliveryTrucks
Lookup to query delivery truck components on entities. -
private BufferLookup<Game.Economy.Resources> m_Resources
BufferLookup for entity resource buffers (contents). -
private BufferLookup<TradeCost> m_TradeCosts
BufferLookup for trade cost buffers. -
private BufferLookup<GuestVehicle> m_GuestVehicleBufs
BufferLookup for guest vehicles (used to count active guest vehicles). -
private BufferLookup<LayoutElement> m_LayoutElementBufs
BufferLookup for layout elements (used to count layout-based delivery capacity). -
private ComponentLookup<Game.Buildings.CargoTransportStation> m_CargoTransportStations
(already listed above) Lookup used in job logic to identify cargo stations.
Note: The struct contains three private nested Burst-compiled IJobChunk types: - SetupResourceSellerJob - SetupResourceExportJob - SetupStorageTransferJob
Each job type iterates chunks of entities and calls targetSeeker.FindTargets with computed scoring to register pathfinding targets.
Properties
- None (no public properties on this struct)
Constructors
public ResourcePathfindSetup(PathfindSetupSystem system)
Initializes all EntityQueries, TypeHandles, ComponentLookups and BufferLookups used by the setup jobs. It also gets/creates the ResourceSystem instance used to register readers for scheduled jobs. Call this during system initialization (e.g., in a PathfindSetupSystem constructor or OnCreate) so the setup struct is ready for use each frame.
Methods
public JobHandle SetupResourceSeller(PathfindSetupSystem system, PathfindSetupSystem.SetupData setupData, JobHandle inputDeps)
Schedules the SetupResourceSellerJob across entities matched by m_ResourceSellerQuery. The job:- Scans candidate entities for buying/resource demand,
- Considers building states, industrial outputs, commercial/industrial flags, outside connections, cargo stations and storage companies,
- Calculates a score/penalty (based on available service, amount, trade costs, cargo station queues, outside connection penalties, current buying trucks) and calls targetSeeker.FindTargets for valid seller entities. Parameters:
- system: the PathfindSetupSystem scheduling this job (used to update handles/lookup state),
- setupData: PathfindSetupSystem.SetupData containing seekers and targets,
- inputDeps: JobHandle dependency to combine with the returned job. Returns:
-
JobHandle for the scheduled job. Also registers the job with the ResourceSystem reader (m_ResourceSystem.AddPrefabsReader).
-
public JobHandle SetupResourceExport(PathfindSetupSystem system, PathfindSetupSystem.SetupData setupData, JobHandle inputDeps)
Schedules the SetupResourceExportJob across m_ExportTargetQuery entities. The job: - Evaluates storage/warehouse entities that can accept exports (or require transport),
- Applies storage limit/upgrade adjustments and property-related limit changes,
- Considers cargo station queues and transport capacity and trade costs,
-
Computes a cost/score and calls targetSeeker.FindTargets for promising export targets. Parameters/returns are the same pattern as SetupResourceSeller.
-
public JobHandle SetupStorageTransfer(PathfindSetupSystem system, PathfindSetupSystem.SetupData setupData, JobHandle inputDeps)
Schedules the SetupStorageTransferJob across m_StorageQuery entities. The job: - Balances storage transfer requests between storages and outside/cargo connections,
- Uses storage limits, stored resources, pending storage transfer requests, installed upgrades and transport company limits,
- Ignores small imbalances (threshold ~4000 units) and computes a score based on imbalance magnitude and trade cost to find transfer targets,
- Properly handles different mailbox resource cases (LocalMail/Unsorted/Outgoing) w.r.t. outside connections. Returns JobHandle for the scheduled job.
Inner job details - SetupResourceSellerJob (private, BurstCompile, IJobChunk): iterates sellers to compute buying targets and penalties, uses BufferAccessor/ComponentLookup to compute scores and calls FindTargets. - SetupResourceExportJob (private, BurstCompile, IJobChunk): iterates export-capable storages to compute selling/export targets including transport requirements. - SetupStorageTransferJob (private, BurstCompile, IJobChunk): iterates storage companies and computes transfer amounts and scores for storage balancing.
All three jobs are Burst-compiled and scheduled via JobChunkExtensions.ScheduleParallel using the prepared EntityQueries and updated handles/lookups.
Usage Example
// In a PathfindSetupSystem (or similar system) update:
private ResourcePathfindSetup m_ResourcePathfindSetup;
protected override void OnCreate()
{
base.OnCreate();
m_ResourcePathfindSetup = new ResourcePathfindSetup(this); // initialize lookups/queries
}
protected override void OnUpdate()
{
var setupData = /* obtain PathfindSetupSystem.SetupData for this frame */;
JobHandle deps = default;
// Schedule the three setup jobs (can chain dependencies as needed)
deps = m_ResourcePathfindSetup.SetupResourceSeller(this, setupData, deps);
deps = m_ResourcePathfindSetup.SetupResourceExport(this, setupData, deps);
deps = m_ResourcePathfindSetup.SetupStorageTransfer(this, setupData, deps);
// Pass deps to the Pathfind system or complete as appropriate
this.Dependency = deps;
}
Notes and tips - These jobs use many read-only ComponentLookups and BufferLookups — ensure Update(system) is called on handles before scheduling (the struct methods already do this). - The jobs are Burst-compiled IJobChunk implementations and are scheduled in parallel; be mindful of data race requirements if you extend or reuse lookups for writing. - Scoring uses trade costs, available amounts, cargo station penalties, outside-connection penalties, and installed upgrade effects — adjust constants only if you understand trade/transfer balancing ramifications.