Skip to content

Game.Zones.Cell

Assembly: Assembly-CSharp
Namespace: Game.Zones

Type: struct

Base: System.ValueType

Summary:
Represents a single zoning grid cell used by the game's zone system. The struct stores the cell's state flags, its zone type data and an optional height value. It is marked with InternalBufferCapacity(60) for use as a Unity ECS dynamic buffer element and implements Colossal's serialization interfaces (IStrideSerializable, ISerializable). Serialization and stride calculation are version-aware: deserialization and stride depend on the reader/writer Context version to maintain compatibility with older save formats.


Fields

  • public CellFlags m_State
    Stores the cell state flags (e.g., occupancy/feature flags). During serialization this is written as a ushort; during deserialization older versions may read it as a byte depending on Version.cornerBuildings.

  • public ZoneType m_Zone
    Holds zone-specific data (a ZoneType value). This field is serialized/deserialized via writer.Read/Write and contributes its own stride via m_Zone.GetStride(context).

  • public short m_Height
    Per-cell height value. For reader contexts older than Version.zoneHeightLimit this field is set to short.MaxValue during deserialization (indicating "no height stored"). When present it is written/read as a 2-byte short.

Properties

  • This struct declares no properties.

Constructors

  • public Cell()
    No explicit constructors are defined in the source — the default struct constructor (zero-initialized fields) applies.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the cell to the provided writer in the following order: m_State (written as ushort), m_Zone (delegate write), m_Height (short). Note: serialization always writes state as ushort and writes height; compatibility is handled on deserialization.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the cell from the provided reader using the reader.context.version to handle legacy formats:

  • If reader.context.version >= Version.cornerBuildings: reads state as ushort; otherwise reads as byte and casts to CellFlags.
  • Reads m_Zone via reader.Read(out m_Zone).
  • If reader.context.version >= Version.zoneHeightLimit: reads m_Height; otherwise sets m_Height = short.MaxValue.

  • public int GetStride(Context context)
    Returns the serialized stride (byte size) of this Cell for the supplied context/version. If context.version >= Version.zoneHeightLimit it returns 4 + m_Zone.GetStride(context) (2 bytes for state + 2 bytes for height + zone stride). For older versions it returns 2 + m_Zone.GetStride(context) (legacy smaller footprint).

Usage Example

// Example: initializing a Cell, querying its stride, and preparing for serialization.
using Colossal.Serialization.Entities;
using Game.Zones;

// Create and initialize
Cell cell = new Cell
{
    m_State = CellFlags.None,
    m_Zone = new ZoneType(/* initialize as appropriate */),
    m_Height = 128
};

// Suppose we have a Context and writer available (from Colossal.Serialization)
Context ctx = /* obtain context with appropriate version */;
int stride = cell.GetStride(ctx);

// Serializing
// TWriter is a concrete writer type provided by the serialization framework
// writer.Context should match ctx
// writer.Write overloads must support ZoneType and primitive types
// Example (pseudo):
// TWriter writer = ...;
// cell.Serialize(writer);

// Deserializing (pseudo):
// TReader reader = ...; // reader.Context determines behavior for legacy versions
// Cell readCell = new Cell();
// readCell.Deserialize(reader);

Notes: - The struct is annotated with [InternalBufferCapacity(60)], which is important when this element is used inside a Unity.Entities DynamicBuffer to reserve internal storage capacity. - Version constants (Version.cornerBuildings, Version.zoneHeightLimit) and types like Context, IWriter, IReader, CellFlags and ZoneType are part of the game's serialization and zoning systems and determine compatibility behavior.