Skip to content

Game.Prefabs.CargoTransportStation

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase, implements IServiceUpgrade

Summary:
A prefab component representing a cargo transport station (e.g., freight depots, cargo terminals). When converted to ECS it adds and initializes the runtime components required for storage, trade and transport companies, transport station behavior and update timing. The component exposes inspector-configurable fields for traded resources, number of transports, allowed refuel energy types per vehicle class, loading factor, work multiplier and transport interval. It requires a StorageLimit component on the same GameObject and has a ComponentMenu attribute for placement in the editor.


Fields

  • public ResourceInEditor[] m_TradedResources
    Array of resources this station trades/stores. Used to build the bitmask of stored resources (StorageCompanyData.m_StoredResources) and to set the transport interval.

  • public int transports
    Maximum number of transports/vehicles the station may manage. If > 0, TransportCompany and OwnedVehicle components will be added to archetype/upgrade components.

  • public EnergyTypes m_CarRefuelTypes
    Allowed energy types for refueling cars. OR'ed into TransportStationData.m_CarRefuelTypes during Initialize.

  • public EnergyTypes m_TrainRefuelTypes
    Allowed energy types for refueling trains. OR'ed into TransportStationData.m_TrainRefuelTypes during Initialize.

  • public EnergyTypes m_WatercraftRefuelTypes
    Allowed energy types for refueling watercraft. OR'ed into TransportStationData.m_WatercraftRefuelTypes during Initialize.

  • public EnergyTypes m_AircraftRefuelTypes
    Allowed energy types for refueling aircraft. OR'ed into TransportStationData.m_AircraftRefuelTypes during Initialize.

  • public float m_LoadingFactor
    Loading factor applied to the transport station. Assigned to TransportStationData.m_LoadingFactor during Initialize.

  • public float m_WorkMultiplier
    Multiplier applied to work/throughput. If > 0, OwnedVehicle component is added to archetype components.

  • public int2 m_TransportInterval
    Transport interval used by the storage/transport logic. Assigned to StorageCompanyData.m_TransportInterval when traded resources are configured.

Properties

  • None (this component exposes public fields and overrides behavior via methods)

Constructors

  • public CargoTransportStation()
    Default MonoBehaviour constructor (no custom initialization in code). The component is configured via inspector fields; runtime ECS initialization occurs in Initialize.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the core ECS component types required for the prefab entity conversion:
  • TransportStationData
  • CargoTransportStationData
  • StorageCompanyData
  • TransportCompanyData
  • UpdateFrameData

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds additional runtime components to the archetype depending on prefab configuration:

  • Always adds Game.Buildings.TransportStation and Game.Buildings.CargoTransportStation.
  • If no ServiceUpgrade component is present:
    • If CityServiceBuilding exists on the GameObject, adds Efficiency.
    • Adds Game.Companies.StorageCompany, TradeCost, StorageTransferRequest, Game.Economy.Resources.
    • If transports > 0, also adds TransportCompany and OwnedVehicle.
  • If m_WorkMultiplier > 0, adds OwnedVehicle. This controls which components are present on entities created from this prefab.

  • public void GetUpgradeComponents(HashSet<ComponentType> components)
    Adds components used when the building is upgraded. Similar to the non-upgrade path for storage/transport:

  • Game.Buildings.TransportStation
  • Game.Buildings.CargoTransportStation
  • Game.Companies.StorageCompany
  • TradeCost
  • StorageTransferRequest
  • Game.Economy.Resources
  • If transports > 0, TransportCompany and OwnedVehicle

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called during entity conversion/initialization. Performs the following:

  • Initializes StorageCompanyData.m_StoredResources to Resource.NoResource and, if m_TradedResources is set, ORs the corresponding resources into m_StoredResources and sets m_TransportInterval.
  • If transports > 0, sets TransportCompanyData.m_MaxTransports.
  • Reads and updates TransportStationData on the entity by OR-ing the configured refuel energy types (car, train, watercraft, aircraft) and setting m_LoadingFactor.
  • Writes CargoTransportStationData with m_WorkMultiplier.
  • Sets UpdateFrameData to 0. This ties the inspector-configured values into the ECS component data for runtime use.

Usage Example

// Typical usage: configure the component on a prefab in the editor.
// Example programmatic configuration (e.g., in a custom prefab builder):
var cargo = gameObject.AddComponent<CargoTransportStation>();
cargo.m_TradedResources = new[] { new ResourceInEditor(/* ... */) };
cargo.transports = 4;
cargo.m_CarRefuelTypes = EnergyTypes.Gasoline | EnergyTypes.Electric;
cargo.m_LoadingFactor = 1.15f;
cargo.m_WorkMultiplier = 0.9f;
cargo.m_TransportInterval = new int2(30, 60);

// During conversion to ECS the system will call Initialize(entityManager, entity)
// which will populate the StorageCompanyData, TransportCompanyData (if transports > 0),
// TransportStationData (refuel types and loading factor), CargoTransportStationData and UpdateFrameData.