Game.Vehicles.WorkVehicle
Assembly: Assembly-CSharp.dll
Namespace: Game.Vehicles
Type: Struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
WorkVehicle is an ECS component used to represent a vehicle that performs discrete "work" tasks (for example maintenance/repair/clearance jobs) inside the Cities: Skylines 2 game systems. It stores a bitmask state (WorkVehicleFlags) and two floats that describe the total amount of work to do and how much has already been completed. The type implements Colossal's ISerializable to allow deterministic saving/loading or network synchronization via the provided IWriter/IReader interfaces. The constructor initializes the flag and total work amount and sets the done amount to zero.
Fields
-
public WorkVehicleFlags m_State
Holds the current state of the work vehicle as a bitmask enum (WorkVehicleFlags). Typical uses: mark whether the vehicle is idle, working, returning, carrying payload, etc. The precise flag values are defined in the WorkVehicleFlags enum elsewhere in the codebase. This value is serialized as a uint. -
public float m_WorkAmount
Total amount of work the vehicle is expected to complete for its current task. Units are game-specific (progress points/time). Set by the constructor or systems that assign tasks. Serialized after m_State. -
public float m_DoneAmount
Amount of work already completed toward m_WorkAmount. Systems increment this as work progresses. The constructor initializes this to 0. Serialized after m_WorkAmount.
Properties
- This type defines no public properties.
Constructors
public WorkVehicle(WorkVehicleFlags flags, float workAmount)
Creates a new WorkVehicle component with m_State set to flags, m_WorkAmount set to workAmount, and m_DoneAmount initialized to 0. Use when assigning a work task to a vehicle.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component fields to the provided writer in the following order:- m_State written as a uint
- m_WorkAmount (float)
-
m_DoneAmount (float)
This order must be preserved by any reader that deserializes the data. This method is used by the Colossal.Serialization system to save or sync component state. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the component fields from reader in the same order used by Serialize: - reads a uint (state)
- reads m_WorkAmount (float)
- reads m_DoneAmount (float)
- assigns m_State by casting the read uint to WorkVehicleFlags
Note: the implementation reads the uint state first then the floats; final assignment to m_State occurs after reading the floats — the net effect is the same ordering as Serialize, but callers should rely on matching read/write order.
Usage Example
// Creating and assigning the component to an entity (EntityManager usage)
var workVehicle = new WorkVehicle(WorkVehicleFlags.Working, 100f);
// m_DoneAmount is 0 after construction
entityManager.AddComponentData(vehicleEntity, workVehicle);
// Example of how serialization would write fields (conceptual)
writer.Write((uint)workVehicle.m_State);
writer.Write(workVehicle.m_WorkAmount);
writer.Write(workVehicle.m_DoneAmount);
// Deserialization will read in the same order; Colossal.Serialization's IReader/IWriter
// implementations are passed in by the engine's save/load or network code.
Notes and tips: - Because WorkVehicle implements ISerializable, any change to the field order or types must be reflected in both Serialize and Deserialize to preserve savegame and compatibility. - The WorkVehicleFlags enum definition controls the meaning of m_State bits — consult that enum for specifics (e.g., Working, Idle, Returning). - As an IComponentData, this struct is intended to be attached to ECS entities and referenced/updated by systems; avoid adding heavy logic to the component itself.