Skip to content

Game.IndustrialFindPropertySystem

Assembly: Assembly-CSharp
Namespace: Game.Simulation

Type: public class

Base: GameSystemBase

Summary:
IndustrialFindPropertySystem is a systems-level class used by the simulation to match industrial (and extractor) company entities with available properties (buildings or extractor areas) in the world. It prepares and schedules two primary jobs each update: a CompanyFindPropertyJob that lets industrial companies find suitable industrial properties on the market, and an ExtractorFindCompanyJob that matches extractor properties/areas with extractor companies. The system coordinates with ResourceSystem, PropertyProcessingSystem, IndustrialDemandSystem and other subsystems, sets up EntityQueries for the relevant entity sets, and uses an EndFrameBarrier for command buffering and job producer synchronization. The class also exposes a static Evaluate method used to score how well a given property fits a company's industrial process.


Fields

  • private EndFrameBarrier m_EndFrameBarrier
    Reference to the EndFrameBarrier system, used to create command buffers for jobs and to register job handles for producer/consumer synchronization.

  • private ResourceSystem m_ResourceSystem
    Reference to ResourceSystem used for reading resource prefabs and other resource-related data required when evaluating properties.

  • private PropertyProcessingSystem m_PropertyProcessingSystem
    Reference to PropertyProcessingSystem used to enqueue rent actions and to mark writers for dependency tracking.

  • private IndustrialDemandSystem m_IndustrialDemandSystem
    Reference to the system providing consumption (demand) information for industrial processes; used by the extractor matching job.

  • private CountCompanyDataSystem m_CountCompanyDataSystem
    Reference to the system providing production counts/aggregates used when evaluating extractor-company matches.

  • private ClimateSystem m_ClimateSystem
    Reference to the climate system used to obtain climate parameters (e.g. average temperature) that affect extractor-area suitability.

  • private EntityQuery m_IndustryQuery
    Query selecting industrial companies (non-extractor) to run the company→property matching job.

  • private EntityQuery m_ExtractorQuery
    Query selecting extractor companies (extractor-company type) to run extractor-specific matching.

  • private EntityQuery m_FreePropertyQuery
    Query selecting available industrial properties on the market (non-extractor) to be considered by companies.

  • private EntityQuery m_EconomyParameterQuery
    Query for economy parameter singleton data used during evaluations.

  • private EntityQuery m_ZonePreferenceQuery
    Query for zone preference singleton data used during company matching.

  • private EntityQuery m_FreeExtractorQuery
    Query selecting available extractor properties/areas on the market to be matched with extractor companies.

  • private EntityQuery m_CompanyPrefabQuery
    Query selecting company prefab data (e.g., IndustrialCompanyData) required for extractor job.

  • private EntityQuery m_ExtractorParameterQuery
    Query for extractor parameter data singleton used when evaluating extractor areas.

  • private TypeHandle __TypeHandle
    Compiler-generated struct containing EntityTypeHandle / ComponentTypeHandle / ComponentLookup / BufferLookup instances. Used to assign and pass component handles into jobs safely.

Properties

  • (none — this system does not expose public properties)

Constructors

  • public IndustrialFindPropertySystem()
    Default constructor (preserve attribute in source). The system is set up by OnCreate; this constructor performs no explicit initialization itself.

Methods

  • public override int GetUpdateInterval(SystemUpdatePhase phase)
    Returns the update interval in ticks (frames) for this system. Implementation returns 16, meaning the system runs every 16 simulation ticks/frames (coarser-than-every-frame scheduling to reduce CPU cost).

  • [Preserve] protected override void OnCreate()
    OnCreate resolves required systems and builds the EntityQueries used by the system:

  • Retrieves/creates EndFrameBarrier, ResourceSystem, PropertyProcessingSystem, IndustrialDemandSystem, CountCompanyDataSystem, ClimateSystem.
  • Creates queries for industrial companies, extractor companies, free properties, free extractors, economy parameters, zone preferences, extractor parameters and company prefabs.
  • Calls RequireAnyForUpdate and RequireForUpdate to control system execution (requires industry or extractor queries and economy parameters). This method prepares everything the system needs before updates begin.

  • [Preserve] protected override void OnUpdate()
    The core update method. Responsibilities:

  • If there are industrial companies to process, create and schedule a parallel CompanyFindPropertyJob (PropertyUtils.CompanyFindPropertyJob) configured with:
    • Entity and component type handles from the TypeHandle.
    • Lists of free property entities and their prefabs (ToEntityListAsync / ToComponentDataListAsync).
    • Various ComponentLookup/BufferLookup instances for building data, resource availability, land values, etc.
    • References to singleton data (EconomyParameterData, ZonePreferenceData) and resource prefabs from ResourceSystem.
    • A parallel rent action queue from PropertyProcessingSystem and a parallel command buffer created from the EndFrameBarrier.
    • Registers dependencies with EndFrameBarrier, ResourceSystem and PropertyProcessingSystem.
  • Always schedules an ExtractorFindCompanyJob (PropertyUtils.ExtractorFindCompanyJob) that:
    • Collects lists of free extractor entities, extractor company entities and company prefabs (async lists).
    • Provides lookup buffers/component lookups for attached objects, extractor data, geometry, prefab references, processes, resource data, subareas and installed upgrades.
    • Supplies production/consumption aggregates from CountCompanyDataSystem and IndustrialDemandSystem (with dependencies).
    • Passes extractor and economy parameters and climate average temperature.
    • Uses PropertyProcessingSystem's rent action queue and EndFrameBarrier's command buffer.
    • Registers dependencies with ResourceSystem, IndustrialDemandSystem, CountCompanyDataSystem, PropertyProcessingSystem and EndFrameBarrier.

The method carefully composes job dependencies (outJobHandle / CombineDependencies) to ensure safe read/write access and to integrate results back into the main ECS world.

  • public static float Evaluate(Entity company, Entity property, ref IndustrialProcessData process, ref PropertySeeker propertySeeker, ComponentLookup<Building> buildings, ComponentLookup<PropertyOnMarket> propertiesOnMarket, ComponentLookup<PrefabRef> prefabFromEntity, ComponentLookup<BuildingData> buildingDatas, ComponentLookup<SpawnableBuildingData> spawnableDatas, ComponentLookup<WorkplaceData> workplaceDatas, ComponentLookup<LandValue> landValues, BufferLookup<ResourceAvailability> availabilities, EconomyParameterData economyParameters, ResourcePrefabs resourcePrefabs, ComponentLookup<ResourceData> resourceDatas, ComponentLookup<BuildingPropertyData> propertyDatas, bool storage)
    Static scoring function that computes a suitability score for a property relative to a company's industrial process and property seeker state. Key behavior:
  • Validates that the property is a building and that the network-edge availability buffer exists for the building.
  • If 'storage' is true: scores the property primarily based on availability and weight of the process output resource (multiplied by process output amount).
  • If 'storage' is false (i.e., operational/production property): requires the company prefab to have workplace data; gives base bonuses for workplaces and worker availability, then factors inputs availability, resource weights, and required amounts for the process inputs.
  • Considers land value (negative effect) scaled by space multipliers and spawnable-level modifiers; penalizes expensive land and adjusts by max workers per cell and resource output weights.
  • Returns a computed float score with a baseline offset (e.g., 250 + computed value) or returns -1 if not applicable (e.g., missing workplace data) or 0 if the building/availability condition is not met.

  • [MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
    Compiler-generated helper used during OnCreateForCompiler to initialize/assign query builders (present but effectively disposes a temporary EntityQueryBuilder).

  • protected override void OnCreateForCompiler()
    Compiler helper used when systems are compiled with source-generation/IL weaving. Calls __AssignQueries and __TypeHandle.__AssignHandles to ensure component handles are ready for job scheduling.

  • [Preserve] public IndustrialFindPropertySystem()
    Public parameterless constructor (repeat of the constructor entry — preserved for runtime linking).

Usage Example

Example: calling the static Evaluate method (e.g., from another system or job) to score a candidate property for a company:

// Assume we are inside a system/job with access to component lookups/buffers and have the required data:
Entity companyEntity = /* company entity */;
Entity propertyEntity = /* property entity */;
IndustrialProcessData process = /* process data for this company */;
PropertySeeker seeker = /* property seeker state for the company */;

float score = IndustrialFindPropertySystem.Evaluate(
    companyEntity,
    propertyEntity,
    ref process,
    ref seeker,
    buildingsLookup,         // ComponentLookup<Building>
    propertiesOnMarketLookup,// ComponentLookup<PropertyOnMarket>
    prefabFromEntityLookup,  // ComponentLookup<PrefabRef>
    buildingDatasLookup,     // ComponentLookup<BuildingData>
    spawnableDatasLookup,    // ComponentLookup<SpawnableBuildingData>
    workplaceDatasLookup,    // ComponentLookup<WorkplaceData>
    landValuesLookup,        // ComponentLookup<LandValue>
    resourceAvailBuffers,    // BufferLookup<ResourceAvailability>
    economyParameters,       // EconomyParameterData singleton
    resourcePrefabs,         // ResourcePrefabs from ResourceSystem.GetPrefabs()
    resourceDatasLookup,     // ComponentLookup<ResourceData>
    propertyDatasLookup,     // ComponentLookup<BuildingPropertyData>
    storage: false           // storage flag
);

// Use 'score' to decide suitability, rank candidate properties, etc.

Notes and tips: - The system is optimized to run infrequently (GetUpdateInterval returns 16) rather than every frame; changes to matching frequency should consider performance implications. - The heavy lifting is performed inside jobs (PropertyUtils.CompanyFindPropertyJob and PropertyUtils.ExtractorFindCompanyJob). If you need to modify matching behavior, examining those job implementations and the Evaluate logic is recommended. - When writing custom jobs or systems that read/write the same components, register readers/writers with the respective systems (ResourceSystem.AddPrefabsReader, PropertyProcessingSystem.AddWriter, etc.) and ensure correct job handle chaining so you don't introduce data races.