Game.Vehicles.MaintenanceVehicle
Assembly:
(assembly not specified — typically part of the game's runtime assembly, e.g. Assembly-CSharp)
Namespace: Game.Vehicles
Type: struct
Base: Implements IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents an ECS component for a maintenance/service vehicle in Cities: Skylines 2. Stores the vehicle's current target request, state flags, counts and timing/efficiency values. This struct is serializable and contains versioned deserialization logic to remain compatible with different game save versions (checks for Version.reverseServiceRequests2, Version.policeShiftEstimate and Version.maintenanceImprovement).
Fields
-
public Entity m_TargetRequest
Reference to the service request Entity that the vehicle is targeting. Can be Entity.Null if no target. Only present in saved data when the save version is >= Version.reverseServiceRequests2 (deserialization respects this check). -
public MaintenanceVehicleFlags m_State
Flags describing the vehicle's state (enum). Serialized as a uint. -
public int m_Maintained
Count of how many maintenance actions/items the vehicle has completed so far. -
public int m_MaintainEstimate
Estimate value for maintenance workload. This field is read from saved data only when save version >= Version.policeShiftEstimate. -
public int m_RequestCount
Number of requests the vehicle is handling or has queued. -
public float m_PathElementTime
Timing information for path progression (per-path element time). -
public float m_Efficiency
Efficiency multiplier for the vehicle. This field is read/written only when save version >= Version.maintenanceImprovement.
Properties
- None (the type exposes fields directly; no C# properties present)
Constructors
public MaintenanceVehicle(MaintenanceVehicleFlags flags, int requestCount, float efficiency)
Initializes a new MaintenanceVehicle setting:- m_TargetRequest = Entity.Null
- m_State = flags
- m_Maintained = 0
- m_MaintainEstimate = 0
- m_RequestCount = requestCount
- m_PathElementTime = 0f
- m_Efficiency = efficiency
Use this constructor to create the component with an initial state, request count and efficiency.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component data to a writer in this order:- m_TargetRequest (Entity)
- m_State (as uint)
- m_Maintained (int)
- m_MaintainEstimate (int)
- m_RequestCount (int)
- m_PathElementTime (float)
- m_Efficiency (float)
Note: The code writes all fields unconditionally when serializing, but deserialization conditionally reads fields depending on the save version. Keep serialization/deserialization consistent across versions when modifying this struct.
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads component data from a reader using version checks:- If reader.context.version >= Version.reverseServiceRequests2: read m_TargetRequest.
- Read an unsigned int into a temporary variable (the serialized state), but m_State is assigned only at the end.
- Read m_Maintained.
- If reader.context.version >= Version.policeShiftEstimate: read m_MaintainEstimate.
- Read m_RequestCount.
- Read m_PathElementTime.
- If reader.context.version >= Version.maintenanceImprovement: read m_Efficiency.
- Finally set m_State = (MaintenanceVehicleFlags)value.
This ordering and the version gates are important for compatibility with saved game formats introduced across game updates.
Usage Example
// Creating and adding this component to an entity (example)
var vehicleComp = new MaintenanceVehicle(MaintenanceVehicleFlags.None, requestCount: 2, efficiency: 1.0f);
entityManager.AddComponentData(vehicleEntity, vehicleComp);
// Typical deserialization flow is handled by the game's serialization system that
// invokes Deserialize<TReader> with the appropriate reader/context/version.
Notes and tips for modders: - This is an ECS IComponentData struct — treat it as a value-type component and use EntityManager/Systems for mutations. - Be careful when changing serialization order or adding/removing fields; keep version checks or migration logic to maintain save compatibility. - The Version.* constants used in Deserialize indicate save-format version thresholds introduced by the game; check their values in-game code to understand when fields became present.