Skip to content

Game.Simulation.CompanyUtils

Assembly:
Assembly-CSharp (Unity game assembly; adjust if different in your mod environment)

Namespace:
Game.Simulation

Type:
static class

Base:
System.Object (static utility class)

Summary:
Utility helpers for company-related calculations (worker fitting, move-away chance, extractor area-based workers) used by the simulation. The class exposes only static methods and depends on various ECS component lookups, PrefabRefs, and game systems such as TaxSystem and ExtractorAISystem. Intended to be called from systems or other simulation code where component lookups and job/scene context are available. It operates with Unity.Entities types (Entity, ComponentLookup<...>, BufferLookup<...>) and Unity math/engine utilities.


Fields

  • (none)
    This static utility class declares no fields. All functionality is provided via static methods.

Properties

  • (none)
    There are no properties on this static utility class.

Constructors

  • (none)
    No instance or static constructor is declared.

Methods

  • public static int GetCompanyMoveAwayChance(Entity company, Entity companyPrefab, Entity property, ref ComponentLookup<ServiceAvailable> serviceAvailables, ref ComponentLookup<OfficeProperty> officeProperties, ref ComponentLookup<IndustrialProcessData> industrialProcessDatas, ref ComponentLookup<WorkProvider> workProviders, NativeArray<int> taxRates)
    Calculates a move-away chance value for a company based on tax rates, service/office/industrial classification, and work provider notification entities.

Details: - Determines whether the company is a service (via ServiceAvailable component) or if the target property is an office (OfficeProperty). - Fetches IndustrialProcessData from the company prefab to determine resource/output type. - Uses a TaxSystem helper to get the appropriate tax rate (commercial, industrial, or office) based on the resource type and taxRates array, then applies a formula: (taxRate - 10) * 5 / 2 to accumulate a base move-away score. - Adds penalties if WorkProvider has notification entities for uneducated (+5) and educated (+20) worker dissatisfaction. - Returns an int representing the accumulated move-away chance/score.

Notes: - Expects industrialProcessDatas to contain an entry for the companyPrefab. - Uses WorkProvider fields to detect notifications (Entity.Null checks). - taxRates should be supplied as the game's tax rate array (NativeArray) for relevant resource indices.

  • public static int GetCommercialMaxFittingWorkers(BuildingData building, BuildingPropertyData properties, int level, ServiceCompanyData serviceData)
    Computes the maximum number of workers that can fit in a commercial/service building.

Details: - Formula: Ceil(serviceData.m_MaxWorkersPerCell * lotWidth * lotHeight * (1 + 0.5 * level) * properties.m_SpaceMultiplier). - level is the building level (spawnable building data level).

  • public static int GetIndustrialAndOfficeFittingWorkers(BuildingData building, BuildingPropertyData properties, int level, IndustrialProcessData processData)
    Computes the maximum fitting workers for industrial and office buildings.

Details: - Similar to commercial but uses processData.m_MaxWorkersPerCell rather than serviceData. - Uses Ceil with same size and level multiplier: lot area * (1 + 0.5 * level) * space multiplier.

  • public static int GetExtractorFittingWorkers(float area, float spaceMultiplier, IndustrialProcessData processData)
    Computes max workers for extractor-type companies based on an area and space multiplier.

Details: - Formula: Ceil(processData.m_MaxWorkersPerCell * area * spaceMultiplier / 2). - Returns an integer and callers often clamp to at least 1 where needed.

  • public static int GetCompanyMaxFittingWorkers(Entity companyEntity, Entity buildingEntity, ref ComponentLookup<PrefabRef> prefabRefs, ref ComponentLookup<ServiceCompanyData> serviceCompanyDatas, ref ComponentLookup<BuildingData> buildingDatas, ref ComponentLookup<BuildingPropertyData> buildingPropertyDatas, ref ComponentLookup<SpawnableBuildingData> spawnableBuildingDatas, ref ComponentLookup<IndustrialProcessData> industrialProcessDatas, ref ComponentLookup<ExtractorCompanyData> extractorCompanyDatas, ref ComponentLookup<Attached> attacheds, ref BufferLookup<Game.Areas.SubArea> subAreaBufs, ref BufferLookup<InstalledUpgrade> installedUpgrades, ref ComponentLookup<Game.Areas.Lot> lots, ref ComponentLookup<Geometry> geometries)
    High-level helper that determines the correct maximum-fitting-workers calculation for a company given its prefab and the target building.

Details: - Resolves the company prefab entity via prefabRefs[companyEntity] and the building prefab via prefabRefs[buildingEntity]. - Attempts to read SpawnableBuildingData to get building level (defaults to 1 if not present). - Branches: - If the company prefab has ServiceCompanyData -> calls GetCommercialMaxFittingWorkers(...) - If it has ExtractorCompanyData -> computes area (via ExtractorAISystem.GetArea using attached parent and provided lookups) and calls GetExtractorFittingWorkers(...), then returns max(1, result). - If it has IndustrialProcessData -> calls GetIndustrialAndOfficeFittingWorkers(...) - Otherwise returns 0. - Requires many component and buffer lookups passed by ref; use appropriate read/write access in your system (ComponentLookup must be obtained with the correct access flags).

Notes and caveats (general for methods above): - All numeric results are returned as ints and use Mathf.CeilToInt to round up where applicable. - This class references other game systems (TaxSystem, ExtractorAISystem) and types (BuildingData, ServiceCompanyData, IndustrialProcessData, WorkProvider, etc.); ensure those are accessible in your mod context. - Methods expect valid ComponentLookup/BufferLookup instances (usually obtained in Systems' OnCreate/OnUpdate with correct readonly/write access). - Passing incorrect or missing component lookups may throw or produce invalid results.

Usage Example

// Example: inside a SystemBase or ComponentSystem where you have access to ComponentLookup/BufferLookup and NativeArray<int> taxRates

protected override void OnUpdate()
{
    var prefabRefs = GetComponentLookup<PrefabRef>(true);
    var serviceCompanyDatas = GetComponentLookup<ServiceCompanyData>(true);
    var buildingDatas = GetComponentLookup<BuildingData>(true);
    var buildingPropertyDatas = GetComponentLookup<BuildingPropertyData>(true);
    var spawnableBuildingDatas = GetComponentLookup<SpawnableBuildingData>(true);
    var industrialProcessDatas = GetComponentLookup<IndustrialProcessData>(true);
    var extractorCompanyDatas = GetComponentLookup<ExtractorCompanyData>(true);
    var attacheds = GetComponentLookup<Attached>(true);
    var subAreaBufs = GetBufferLookup<Game.Areas.SubArea>(true);
    var installedUpgrades = GetBufferLookup<InstalledUpgrade>(true);
    var lots = GetComponentLookup<Game.Areas.Lot>(true);
    var geometries = GetComponentLookup<Geometry>(true);
    var serviceAvailables = GetComponentLookup<ServiceAvailable>(true);
    var officeProperties = GetComponentLookup<OfficeProperty>(true);
    var workProviders = GetComponentLookup<WorkProvider>(true);

    NativeArray<int> taxRates = /* obtain tax rates array from game state or system */;

    // Example call for move-away chance
    int moveAway = CompanyUtils.GetCompanyMoveAwayChance(companyEntity, companyPrefabEntity, propertyEntity,
        ref serviceAvailables, ref officeProperties, ref industrialProcessDatas, ref workProviders, taxRates);

    // Example call for max fitting workers
    int maxWorkers = CompanyUtils.GetCompanyMaxFittingWorkers(companyEntity, buildingEntity,
        ref prefabRefs, ref serviceCompanyDatas, ref buildingDatas, ref buildingPropertyDatas,
        ref spawnableBuildingDatas, ref industrialProcessDatas, ref extractorCompanyDatas,
        ref attacheds, ref subAreaBufs, ref installedUpgrades, ref lots, ref geometries);

    // Use moveAway and maxWorkers as needed...
}

Additional tips: - Ensure ComponentLookup and BufferLookup are requested with the correct read/write permissions in SystemBase.OnCreate or in OnUpdate via GetComponentLookup/GetBufferLookup. - When calling methods from jobs, capture the lookups appropriately (use the job-friendly forms or pass primitive values computed beforehand). - Validate that prefabRefs contains entries for the entities passed; missing PrefabRef entries will result in invalid indexing.