Skip to content

Game.Prefabs.ProcessingCompany

Assembly:
Assembly-CSharp

Namespace:
Game.Prefabs

Type:
Class

Base:
ComponentBase

Summary:
ProcessingCompany is a prefab component used to define an industrial processing company for the ECS-based game systems. It exposes an IndustrialProcess definition and a transports count (max owned transports). At prefab-to-entity conversion time this component registers the required component types (archetype/prefab components) and writes the runtime component data (IndustrialProcessData and optionally TransportCompanyData) to the created Entity. The generated archetype also conditionally includes buying/selling, lodging and transport-related ECS components depending on the configured process and transports value.


Fields

  • public IndustrialProcess process
    Defines the industrial process this company performs. The process contains input/output resources, amounts and worker capacity (m_MaxWorkersPerCell). The presence/values of the process inputs/outputs determine which ECS components are added to the archetype (e.g., BuyingCompany if inputs are present, LodgingProvider/Renter if output is Lodging).

  • public int transports
    Number of transports (max transports) assigned to the company. If greater than zero, the prefab adds transport-related ECS components in the archetype and Initialize will write a TransportCompanyData component containing this value.

Properties

  • None (this component exposes only public fields).

Constructors

  • public ProcessingCompany()
    Default parameterless constructor (inherited behavior). The component is normally configured in the Unity editor as a prefab component; no special construction logic is defined in the class.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the component types that should be present on every instantiated prefab entity. Always adds IndustrialProcessData. Adds TransportCompanyData if transports > 0. This is used by the prefab conversion system to ensure the prefab entity can store the required component data.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds component types that define the archetype for the company entities. Always includes:

  • Game.Companies.ProcessingCompany
  • TaxPayer
  • ResourceSeller
  • Profitability
  • TradeCost

Conditionally adds: - BuyingCompany — if at least one input resource is present (process.m_Input1 or m_Input2 is not NoResource) - LodgingProvider and Renter — if process.m_Output.m_Resource == ResourceInEditor.Lodging - TransportCompany and OwnedVehicle — if transports > 0

These choices ensure the entity has the systems-relevant components required for buying/selling resources, providing lodging, tax handling, vehicle ownership and transport behavior.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Writes runtime component data to the entity once the prefab is instantiated. It creates and sets an IndustrialProcessData component using values from the process field, mapping editor ResourceInEditor values to runtime resource identifiers via EconomyUtils.GetResource. It sets m_Input1, m_Input2, m_Output (amounts and runtime resource ids) and m_MaxWorkersPerCell. If transports > 0, it also sets TransportCompanyData.m_MaxTransports to the transports value.

Notes: - Uses EconomyUtils.GetResource to translate editor resource enums (ResourceInEditor) into the runtime resource id/enumeration expected by IndustrialProcessData. - The method assumes the corresponding component types were added in GetPrefabComponents/GetArchetypeComponents.

Usage Example

// Configure the prefab in code (typically done in the Unity editor on a prefab)
var processing = gameObject.AddComponent<Game.Prefabs.ProcessingCompany>();

processing.process = new IndustrialProcess
{
    m_Input1 = new ProcessIO { m_Resource = ResourceInEditor.Wood, m_Amount = 2 },
    m_Input2 = new ProcessIO { m_Resource = ResourceInEditor.NoResource, m_Amount = 0 },
    m_Output = new ProcessIO { m_Resource = ResourceInEditor.Plank, m_Amount = 1 },
    m_MaxWorkersPerCell = 4
};

processing.transports = 3;

// When the prefab conversion/instantiation runs:
// - GetPrefabComponents will ensure IndustrialProcessData (and TransportCompanyData) exist on the entity.
// - GetArchetypeComponents will include components such as BuyingCompany, ResourceSeller, TransportCompany, etc., depending on the process and transports.
// - Initialize(EntityManager, Entity) will write the IndustrialProcessData (and TransportCompanyData) to the entity,
//   using EconomyUtils.GetResource(...) to map editor resource enums to runtime resource identifiers.

Additional notes: - Configure Process fields (inputs/outputs) in the Unity inspector on the prefab for authoring. The runtime mapping and ECS component wiring happens automatically during prefab-to-entity conversion. - Ensure referenced types (IndustrialProcess, ResourceInEditor, ProcessIO, EconomyUtils) are available in your mod's compile context if inspecting or creating these prefabs programmatically.