Game.Zones.ZoneType
Assembly: Assembly-CSharp
Namespace: Game.Zones
Type: struct
Base: IEquatable
Summary:
ZoneType is a small value type that represents a zone type identifier used by the game's zoning systems. It wraps a single ushort index (m_Index) and provides equality semantics, version-aware serialization/deserialization, and a fixed serialization stride. This struct is optimized for compact on-disk/in-memory representation and compatibility with older save/stream formats (it falls back to a byte-sized index for older versions).
Fields
public ushort m_Index
Holds the numeric identifier for the zone type. This is the primary data for the struct and is used for equality and serialization. Because it's a ushort, it supports indices from 0..65535. m_Index == 0 corresponds to the default/None value.
Properties
public static ZoneType None => default(ZoneType)
A convenience static property that returns the default/empty ZoneType (m_Index == 0). Use this to represent the absence of a zone type.
Constructors
public ZoneType()
No explicit constructors are defined in the source; the default parameterless struct constructor applies and initializes m_Index to 0. You may initialize instances directly by assigning m_Index.
Methods
-
public bool Equals(ZoneType other)
Implements IEquatable. Returns true when this instance's m_Index equals the other's m_Index. Use for value-type equality checks (faster than object.Equals boxing). -
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Serializes the m_Index to the provided writer. The writer will write the ushort value (2 bytes). This method is generic to support different writer implementations used by the game's serialization system. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Deserializes m_Index from the provided reader. This method is version-aware: - If reader.context.version >= Version.cornerBuildings, the index is read as a ushort (2 bytes).
-
Otherwise (older versions), the index is read as a byte and stored into m_Index (backwards compatibility with older save formats). This ensures saved data from older game versions remains loadable.
-
public int GetStride(Context context)
Implements IStrideSerializable. Returns the number of bytes used to represent this struct when striding a buffer — always 2 (since a ushort is 2 bytes). The Context parameter is present to match the interface, though this implementation does not use it.
Usage Example
// Basic usage: creating and comparing ZoneType values
ZoneType z1 = default; // m_Index = 0, equivalent to ZoneType.None
ZoneType z2 = new ZoneType { m_Index = 5 };
bool areEqual = z1.Equals(z2); // false
// Serialization (example, actual writer/reader types come from the game's serialization system)
public void SaveZone<TWriter>(TWriter writer, ZoneType zone) where TWriter : IWriter
{
zone.Serialize(writer);
}
public ZoneType LoadZone<TReader>(TReader reader) where TReader : IReader
{
ZoneType zone = default;
zone.Deserialize(reader); // handles version compatibility internally
return zone;
}
// Getting stride (useful when allocating buffers or interop)
int bytesPerZone = new ZoneType().GetStride(someContext); // returns 2
Additional notes: - Because ZoneType is a struct, it is a value type and cheap to copy; prefer using the Equals method for comparisons. - The Deserialize method relies on Version.cornerBuildings (an enum/constant in the game's save/versioning system) to choose between reading a byte or ushort, preserving compatibility with older save data.