Game.Vehicles.CargoTransport
Assembly:
Unknown (not provided in source)
Namespace: Game.Vehicles
Type: struct
Base: System.ValueType, IComponentData, IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable
Summary:
Represents transport-related state for cargo vehicles in the game's ECS. This struct is an IComponentData component attached to vehicle entities (or related transport entities) to track the current cargo transport request target, transport state flags, timing and counting information. It implements custom serialization/deserialization to support save/load across multiple game versions; certain fields are read/written conditionally based on the save version.
Fields
-
public Entity m_TargetRequest
Reference to the Entity that represents the cargo request this transport is serving (for example a service request or loading point). Note: reading/writing of this field is guarded by a version check in Deserialize — it's only deserialized for saves with version >= Version.reverseServiceRequests. When serializing, the Entity is written unconditionally. -
public CargoTransportFlags m_State
Flags enum describing the transport's current state (stored as a uint during serialization). This encodes state bits such as whether the transport is waiting, en route, returning, etc. The enum definition is external to this file; treat it as a bitfield representing transport-specific statuses. -
public uint m_DepartureFrame
Frame index (uint) indicating when this transport departed or was scheduled to depart. Used for timing/timeout logic and relative scheduling between frames. Always serialized/deserialized (the serialized value is read into a temporary uint and then cast back into the flags in Deserialize flow). -
public int m_RequestCount
Count of requests or items associated with this transport. This field is only present in saves with version >= Version.evacuationTransport (Deserialize reads it only when that version condition is met). If the running code is older than that version, this field will remain at its default value after deserialization. -
public float m_PathElementTime
Timing information used for path element progression (e.g., interpolation along a path). Like m_RequestCount, this is only deserialized for saves with version >= Version.evacuationTransport.
Properties
- None defined in this struct. (All data exposed as public fields suitable for ECS component usage.)
Constructors
public CargoTransport()
Implicit parameterless value-type constructor (default). No explicit constructors are provided in the source; initialize fields directly when creating instances (see usage example).
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Serializes the component fields to the provided writer. The method writes:- m_TargetRequest (Entity)
- m_State as a uint
- m_DepartureFrame (uint)
- m_RequestCount (int)
- m_PathElementTime (float)
Note: Serialize writes all fields unconditionally in the order shown. The serialized representation uses a uint cast for the flags field.
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Deserializes component data from reader with compatibility handling across game save versions:- If reader.context.version >= Version.reverseServiceRequests: reads m_TargetRequest (Entity).
- Always reads a uint value (temporarily stored as 'value') which is later cast to CargoTransportFlags and assigned to m_State.
- Always reads m_DepartureFrame (uint).
- If reader.context.version >= Version.evacuationTransport: reads m_RequestCount (int) and m_PathElementTime (float).
Implementation details: - The method uses ref locals for fields when calling reader.Read to assign directly into the struct's fields. - The ordering and conditional reads must match the writer and the expected save format for compatibility.
Usage Example
// Example: adding a CargoTransport component to an entity in an ECS system.
var transport = new Game.Vehicles.CargoTransport {
m_TargetRequest = Entity.Null,
m_State = CargoTransportFlags.None, // use appropriate enum value
m_DepartureFrame = (uint)SimulationManager.instance.m_currentFrameIndex,
m_RequestCount = 0,
m_PathElementTime = 0f
};
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
entityManager.AddComponentData(vehicleEntity, transport);
Notes and tips: - Because CargoTransport is an IComponentData, modify it via EntityManager or within a System using ComponentDataFromEntity/IComponentData APIs to respect ECS safety and job constraints. - When adding custom save/load logic or working with multiple versions, ensure you respect the same versioned read/write order used here (reverseServiceRequests and evacuationTransport) to maintain save compatibility. - Be careful when directly manipulating Entity fields (m_TargetRequest); entities can become invalid if the referenced request entity is destroyed — check for Entity.Null and EntityManager.Exists as needed.