Skip to content

Game.Simulation.ExtractorCompanySystem

Assembly: Assembly-CSharp
Namespace: Game.Simulation

Type: class

Base: GameSystemBase

Summary:
Handles production for extractor companies (natural resource extractors such as oil rigs, fisheries, forests, fertile land and ore). This system gathers extractor company entities, computes production based on resource concentrations, building efficiencies and upgrades, updates extractor area depletion, increments achievement counters (offshore oil, fish), records produced resources for processing/production specialization, and can spawn ResourceExporter components when storage/dispatch conditions require it. The heavy per-entity work is performed in a Burst-compiled IJobChunk (ExtractorJob) for parallel execution.


Fields

  • private SimulationSystem m_SimulationSystem
    Holds a reference to the central simulation system used for frame/update information.

  • private EndFrameBarrier m_EndFrameBarrier
    Barrier used to create an EntityCommandBuffer to enqueue structural changes (e.g., adding ResourceExporter components).

  • private TaxSystem m_TaxSystem
    Reference to the TaxSystem for looking up current tax rates.

  • private ResourceSystem m_ResourceSystem
    Reference to the ResourceSystem for resource prefab info.

  • private VehicleCapacitySystem m_VehicleCapacitySystem
    Provides delivery truck selection data / capacity ranges used when adding ResourceExporter components.

  • private ProcessingCompanySystem m_ProcessingCompanySystem
    Used to get access to the produced-resources array (aggregating production across systems).

  • private ProductionSpecializationSystem m_ProductionSpecializationSystem
    Provides a concurrent queue to enqueue produced resources for production specialization logic.

  • private AchievementTriggerSystem m_AchievementTriggerSystem
    Used to increment achievement-related counters (offshore oil/produced fish).

  • private CitySystem m_CitySystem
    Reference to the CitySystem; used to access city modifiers.

  • private EntityQuery m_CompanyGroup
    EntityQuery selecting extractor company entities (ExtractorCompany + dependencies) required for this system to run.

  • private TypeHandle __TypeHandle
    Generated helper that stores TypeHandles/ComponentLookups/BufferLookups used by the job and system; assigned on creation.

  • private EntityQuery __query_1012523227_0
    Generated query used to obtain a singleton EconomyParameterData.

  • private EntityQuery __query_1012523227_1
    Generated query used to obtain a singleton ExtractorParameterData.

Properties

  • (none)

Constructors

  • public ExtractorCompanySystem()
    Default constructor (generated/preserved). Initialization of system-managed references is done in OnCreate.

Methods

  • public override int GetUpdateInterval(SystemUpdatePhase phase)
    Returns the update interval (in ticks) for this system. The interval is computed relative to EconomyUtils.kCompanyUpdatesPerDay and internal scheduling factors. Used by the game to determine when this system runs.

  • [Preserve] protected override void OnCreate()
    Sets up references to other systems (SimulationSystem, TaxSystem, ResourceSystem, VehicleCapacitySystem, ProcessingCompanySystem, ProductionSpecializationSystem, AchievementTriggerSystem, CitySystem) and builds the EntityQuery (m_CompanyGroup) used to select extractor companies. Also requires singleton data (EconomyParameterData, ExtractorParameterData) for updates.

  • public static MapFeature GetRequiredMapFeature(Resource output, Entity lotPrefab, ResourcePrefabs resourcePrefabs, ComponentLookup<ResourceData> resourceDatas, ComponentLookup<ExtractorAreaData> extractorAreaDatas)
    Utility that returns which MapFeature (if any) is required for a specific extractor lot prefab given an output resource. Returns None when no natural resource requirement exists.

  • public static bool GetBestConcentration(Resource resource, Entity mainBuilding, ref BufferLookup<Game.Areas.SubArea> subAreas, ref BufferLookup<InstalledUpgrade> installedUpgrades, ref ComponentLookup<Extractor> extractors, ref ComponentLookup<Geometry> geometries, ref ComponentLookup<PrefabRef> prefabs, ref ComponentLookup<ExtractorAreaData> extractorDatas, ExtractorParameterData extractorParameters, ResourcePrefabs resourcePrefabs, ref ComponentLookup<ResourceData> resourceDatas, out float concentration, out float size)
    Scans a main building's sub-areas and installed upgrades to compute the best available concentration and total size for the requested resource. This value is used to scale production and depletion. Returns true if any concentration > 0 was found.

  • private static void GetBestConcentration(DynamicBuffer<Game.Areas.SubArea> subAreas, ref ComponentLookup<Extractor> extractors, ref ComponentLookup<Geometry> geometries, ref ComponentLookup<PrefabRef> prefabs, ref ComponentLookup<ExtractorAreaData> extractorDatas, ExtractorParameterData extractorParameters, bool requireNaturalResource, ref float concentration, ref float size)
    Internal helper that accumulates concentration and size across a set of sub-areas. Applies extractorParameters when resource requires natural resource handling (effective concentration capped against parameter-defined full values).

  • public static float GetEffectiveConcentration(ExtractorParameterData extractorParameters, MapFeature feature, float concentration)
    Given a raw concentration and extractor parameter thresholds (m_FullOil, m_FullFertility, m_FullFish, m_FullOre), returns an adjusted effective concentration clamped to [0,1]. Useful when depletion or scaling needs normalization.

  • [Preserve] protected override void OnUpdate()
    Main update method. Prepares and schedules the Burst-compiled ExtractorJob (IJobChunk) that processes all extractor companies in parallel. Sets up job data: component lookups, buffers, parameter singletons, random seed, achievement checks, produced-resources array, and production queue. Schedules the job and registers the job handle with the EndFrameBarrier and TaxSystem.

  • private void __AssignQueries(ref SystemState state)
    Generated method that constructs EntityQueries for required singletons (EconomyParameterData and ExtractorParameterData). Called during compiler-time creation.

  • protected override void OnCreateForCompiler()
    Generated compiler-time initialization that assigns queries and type handles.

  • private struct TypeHandle
    Generated struct that holds EntityTypeHandle, BufferTypeHandles, ComponentLookups and SharedComponentTypeHandles used by the system and the job. It exposes __AssignHandles(ref SystemState) to populate these handles.

  • private struct ExtractorJob : IJobChunk
    Burst-compiled job that does the per-chunk processing for extractor companies. Responsibilities include:

  • Filter by update frame (UpdateFrame shared component).
  • Read company buffers/resources and building data (IndustrialProcessData, StorageLimitData, Efficiency buffers).
  • Determine resource concentration and building efficiency; consider city modifiers and installed upgrades.
  • Compute company production per tick (using EconomyUtils.GetCompanyProductionPerDay scaled by updates per day).
  • Distribute production across sub-areas and upgrades by calling ProcessArea.
  • Update TaxPayer fields (average tax rate and untaxed income) based on company profit.
  • Call AddProducedResource to increment global produced resources array and enqueue ProducedResource for ProductionSpecializationSystem.
  • Increment achievement counters (offshore oil, fish) when applicable.
  • Add a ResourceExporter component via command buffer when storage/dispatch thresholds require deliveries.

Major helper methods inside ExtractorJob: - void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
Main chunk execution: loops entities in the chunk and applies extraction logic described above. - private bool FindResourceConnectionNode(Entity ownerEntity, out Entity node, out bool connected)
Searches owner's sub-nets for a resource connection node; returns whether the node is connected (flow's LSB). - private bool CheckHaveValidRoute(Entity placeholderEntity, Entity upgradeEntity, out Entity stopObject)
Validates whether a building (placeholderEntity) has a route connecting to an upgradeEntity, used for upgrades that require route connectivity. - private unsafe void AddProducedResource(Resource resource, int amount)
Atomically adds produced amount into the provided m_ProducedResources NativeArray (via Interlocked.Add on the unsafe pointer) and enqueues the produced resource into the production queue. - private float ProcessArea(Entity area, float totalProduced, float totalConcentration, float totalSize, bool requireNaturalResources)
Computes how much of the produced amount should be applied to a specific extractor sub-area, applies depletion and work amount accumulation, and updates the Extractor component for that area. - private float GetExtractionMultiplier(Entity subArea)
Returns a multiplier for extraction based on the MapFeature of the extractor area (e.g., fertility, fish, forest consumption factors from ExtractorParameterData).

Usage Example

// Basic usage is internal — the system runs automatically. Example: call GetBestConcentration to query
// if a building has any extractable resource concentration (returns concentration [0..1] and area size).

float concentration;
float areaSize;
bool hasResource = ExtractorCompanySystem.GetBestConcentration(
    resource: Resource.Ore,
    mainBuilding: myMainBuildingEntity,
    subAreas: ref world.GetExistingSystemManaged<YourSystem>().__TypeHandle.__Game_Areas_SubArea_RO_BufferLookup, // example access
    installedUpgrades: ref /* BufferLookup<InstalledUpgrade> */,
    extractors: ref /* ComponentLookup<Extractor> */,
    geometries: ref /* ComponentLookup<Geometry> */,
    prefabs: ref /* ComponentLookup<PrefabRef> */,
    extractorDatas: ref /* ComponentLookup<ExtractorAreaData> */,
    extractorParameters: extractorParamsSingleton,
    resourcePrefabs: resourceSystem.GetPrefabs(),
    resourceDatas: ref /* ComponentLookup<ResourceData> */,
    out concentration,
    out areaSize
);

if (hasResource)
{
    UnityEngine.Debug.Log($"Found resource concentration {concentration} over area {areaSize}");
}

Notes: - Most interaction with this system is internal to the game's simulation. Mods typically call its static helpers (GetBestConcentration, GetEffectiveConcentration, GetRequiredMapFeature) or hook into events/queues exposed by other systems (ProductionSpecializationSystem, ProcessingCompanySystem) to react to production. - The heavy per-company logic runs in a Burst job (ExtractorJob) and uses atomic operations to safely increment global produced resource counters and enqueue production events.