Skip to content

Game.Buildings.WastewaterTreatmentPlant

Assembly: Assembly-CSharp
Namespace: Game.Buildings

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents per-building runtime data for a wastewater treatment plant used by the game's ECS (Unity.Entities). The struct stores the current amount of stored water and the previous stored water value. It implements Colossal's ISerializable to read/write these values for save/load compatibility; the deserialization logic contains a version check to remain backward compatible with older save formats.


Fields

  • public int m_StoredWater
    Current stored water amount for the treatment plant. Serialized/unserialized unconditionally.

  • public int m_LastStoredWater
    Previously stored water value. This value is serialized, but during deserialization it is read only when the saved data version is at or above Version.waterSelectedInfoFix to maintain compatibility with older saves.

Properties

  • This type exposes no properties.

Constructors

  • public WastewaterTreatmentPlant()
    No explicit constructors are declared in the source; the type uses the default parameterless struct constructor. Initialize fields directly when creating instances.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the struct's fields to the provided writer in the following order:
  • m_StoredWater
  • m_LastStoredWater

The method uses local copies of the fields and calls writer.Write for each integer.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the struct's fields from the provided reader. It always reads m_StoredWater. It only reads m_LastStoredWater when reader.context.version >= Version.waterSelectedInfoFix. This conditional read preserves backward compatibility with save files created before the waterSelectedInfoFix version was introduced. The method uses ref locals to write directly into the struct fields.

Usage Example

// Create and initialize the component for an entity (using Unity.Entities)
var plantData = new WastewaterTreatmentPlant
{
    m_StoredWater = 1200,
    m_LastStoredWater = 1100
};

entityManager.AddComponentData(someEntity, plantData);

// Example: manual serialization (pseudo-code; actual writer comes from Colossal.Serialization)
var writer = GetSomeWriter(); // IWriter implementation provided by the engine
plantData.Serialize(writer);

// Example: manual deserialization (pseudo-code)
var reader = GetSomeReader(); // IReader implementation provided by the engine
WastewaterTreatmentPlant loaded = default;
loaded.Deserialize(reader);
// loaded.m_StoredWater and loaded.m_LastStoredWater now populated,
// with m_LastStoredWater only read if reader.context.version >= Version.waterSelectedInfoFix

{{ Notes and tips for modders: - This struct is plain-old-data (two ints) and is safe and efficient to use as an ECS IComponentData. - The Version.waterSelectedInfoFix constant is defined elsewhere in the codebase; when creating custom serialization code or migrating saves, respect this version gating to avoid corrupting older save data. - When modifying serialization order or adding fields, increment and check a version to remain compatible with existing save files. }}