Skip to content

Game.Simulation.AirPollution

Assembly: Assembly-CSharp.dll
Namespace: Game.Simulation

Type: struct

Base: IPollution, IStrideSerializable, ISerializable

Summary:
Represents a compact air-pollution value used by the simulation. Stores pollution as a 16-bit signed integer (short) and provides simple saturation-safe addition, plus serialization/deserialization logic for save/load. The stride (serialization size) is 2 bytes (size of a short).


Fields

  • public short m_Pollution
    Holds the pollution value. As a short it can represent -32768..32767, but the Add method saturates the upper bound to 32767. Default (uninitialized) value is 0 when the struct is default-constructed. This field is what gets serialized/deserialized.

Properties

  • None

Constructors

  • public AirPollution()
    Implicit default struct constructor. Initializes m_Pollution to 0 (default short).

Methods

  • public void Add(short amount)
    Adds the given amount to m_Pollution and clamps the result to a maximum of 32767 to avoid overflow. Note: there is no lower-bound clamp here, so negative additions could make the value negative.

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the m_Pollution value to the provided writer. Used during saving/streaming of entity data.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the m_Pollution value from the provided reader. Used during loading/restoring of entity data.

  • public int GetStride(Context context)
    Returns the number of bytes used when serializing this struct. Always returns 2 (size of a 16-bit short).

Usage Example

// Create and modify pollution
Game.Simulation.AirPollution pollution = default;
pollution.Add(150);

// Serialize (using a Colossal Serialization writer)
pollution.Serialize(writer);

// Later, deserialize
Game.Simulation.AirPollution loaded;
loaded.Deserialize(reader);

// Check stride (serialization size)
int bytes = loaded.GetStride(default); // returns 2