Game.Buildings.WaterConsumer
Assembly: Assembly-CSharp
Namespace: Game.Buildings
Type: struct
Base: System.ValueType, IComponentData, IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable
Summary:
Represents the water consumption state for a building. Tracks pollution contribution, requested water amount, how much fresh water and sewage have been fulfilled, cooldown counters for supply updates, and connection flags. Implements serialization with compatibility code paths for multiple save/game-version formats so it can be read/written across different game versions.
Fields
-
public float m_Pollution
Holds the pollution value produced by water usage for this building. Read/written conditionally depending on save version (introduced around the waterPipePollution version). -
public int m_WantedConsumption
The amount of water the building requests/needs. Present and deserialized when the save version includes water consumption data. -
public int m_FulfilledFresh
How much fresh water was actually supplied to the building during the simulation (used by the pipe flow simulation). -
public int m_FulfilledSewage
How much sewage/wastewater was returned/transported away from the building (used by the pipe flow simulation). -
public byte m_FreshCooldownCounter
A small counter used to throttle or cooldown fresh-water-related updates (used by the flow simulation logic). -
public byte m_SewageCooldownCounter
A small counter used to throttle or cooldown sewage-related updates. -
public WaterConsumerFlags m_Flags
Bitfield of flags describing connections/state (for example WaterConnected and SewageConnected). Stored/loaded as a byte in serialized data when the save version includes waterConsumerFlags.
Properties
-
public bool waterConnected { get; }
True when the WaterConsumerFlags.WaterConnected bit is set in m_Flags. Use to quickly check whether the building has a fresh-water connection. -
public bool sewageConnected { get; }
True when the WaterConsumerFlags.SewageConnected bit is set in m_Flags. Use to quickly check whether the building has a sewage connection.
Constructors
public WaterConsumer()
Default struct constructor (value-type): zero-initializes all numeric fields and clears flags. Typical instances are created and then populated by the game's simulation or by deserialization.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component state to a writer. Fields are written in a specific order as expected by the game: pollution, wanted consumption, fulfilled fresh/sewage, cooldown counters, then flags (written as a byte). This method is used when saving component data. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads component state from a reader with multiple conditional branches depending on reader.context.version. This method contains backward/forward compatibility logic: - Reads pollution only if the save version >= Version.waterPipePollution; older versions skip a placeholder int.
- Skips fulfilled values for versions before waterPipeFlowSim.
- Reads wanted consumption for versions >= Version.waterConsumption.
- Handles removed/changed fields across versions such as utility fees and waterFee in older revisions.
- Reads fulfilledFresh, fulfilledSewage and cooldown counters when the version includes waterPipeFlowSim.
- Reads flags as a byte and casts to WaterConsumerFlags when the version includes waterConsumerFlags.
The Deserialize method ensures the struct is populated correctly for many historical save formats used by the game.
Usage Example
// Example: manipulating a WaterConsumer instance within a system or utility method
var consumer = new WaterConsumer();
// Set wanted consumption (e.g. 100 units)
consumer.m_WantedConsumption = 100;
// Mark as water-connected (assuming WaterConsumerFlags enum exists with WaterConnected bit)
consumer.m_Flags |= WaterConsumerFlags.WaterConnected;
// Check connections
if (consumer.waterConnected)
{
// handle fresh water logic
}
if (!consumer.sewageConnected)
{
// handle missing sewage connection (e.g. increase pollution or reduce service)
}
// Serialization (conceptual — requires a real writer)
void SaveComponent<TWriter>(ref WaterConsumer wc, TWriter writer) where TWriter : IWriter
{
wc.Serialize(writer);
}
// Deserialization (conceptual — requires a real reader)
void LoadComponent<TReader>(ref WaterConsumer wc, TReader reader) where TReader : IReader
{
wc.Deserialize(reader);
}