Skip to content

Game.PoliceStation

Assembly: Assembly-CSharp
Namespace: Game.Buildings

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents the ECS component data for a police station building. Stores references to active service requests (prisoner transport and target requests), station flags and the purposes this station can serve. Implements custom binary serialization/deserialization and is version-aware: some fields are only present when reading data from sufficiently recent save/game versions. This component is intended to be attached to police station entities within the game's Entities (ECS) world.


Fields

  • public Entity m_PrisonerTransportRequest
    {{ Holds an Entity reference to the active prisoner-transport request associated with this station. This value is serialized/deserialized only when the saved data's version is >= Version.policeImprovement2. In older versions this field will remain default (Entity.Null). }}

  • public Entity m_TargetRequest
    {{ Holds an Entity reference to an active "target" service request (reverse service requests). This value is serialized/deserialized only when the saved data's version is >= Version.reverseServiceRequests2. In older versions this will remain default (Entity.Null). }}

  • public PoliceStationFlags m_Flags
    {{ Bitflags describing the station state/configuration. Always serialized as a byte. During deserialization the byte is read and cast back to PoliceStationFlags. }}

  • public PolicePurpose m_PurposeMask
    {{ Bitmask (enum) indicating which police purposes this station serves (e.g., Patrol, Emergency, etc.). This value is serialized as an int and only read from saved data when reader.context.version >= Version.policeImprovement3. For older versions the component defaults this field to PolicePurpose.Patrol | PolicePurpose.Emergency. }}

Properties

  • None.
    {{ This struct exposes only public fields; there are no C# properties defined. }}

Constructors

  • public PoliceStation()
    {{ Implicit default constructor (value type). All fields are default-initialized (Entity.Null for Entity fields, zero for enum/flag fields). No custom construction logic is defined in this struct. }}

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    {{ Writes the component's data into the provided writer in a fixed order:
  • m_PrisonerTransportRequest (Entity)
  • m_TargetRequest (Entity)
  • m_Flags (as byte)
  • m_PurposeMask (as int) Note: Serialize always writes all four values; the corresponding Deserialize method will decide how to read them depending on the reader.context.version. The method uses generic IWriter to remain decoupled from the concrete writer implementation. }}

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    {{ Reads component data from the provided reader while handling backward compatibility:

  • If reader.context.version >= Version.policeImprovement2, reads m_PrisonerTransportRequest.
  • If reader.context.version >= Version.reverseServiceRequests2, reads m_TargetRequest.
  • Always reads a byte for m_Flags and casts it to PoliceStationFlags.
  • If reader.context.version >= Version.policeImprovement3, reads an int and casts it to PolicePurpose for m_PurposeMask. Otherwise, sets m_PurposeMask to the default value PolicePurpose.Patrol | PolicePurpose.Emergency. This approach ensures older save files that lack newer fields can still be loaded with sensible defaults. }}

Usage Example

// Example: create and serialize a PoliceStation component
var station = new PoliceStation
{
    m_PrisonerTransportRequest = Entity.Null,
    m_TargetRequest = Entity.Null,
    m_Flags = PoliceStationFlags.None,
    m_PurposeMask = PolicePurpose.Patrol | PolicePurpose.Emergency
};

// writer is an implementation of IWriter supplied by the game's serialization system.
// station.Serialize(writer);

// Example: deserializing with a reader and handling older save versions
// reader is an implementation of IReader with reader.context.version set by the loader.
// PoliceStation deserializedStation = default;
// deserializedStation.Deserialize(reader);
// After Deserialize, deserializedStation.m_PurposeMask will be set from saved data if
// reader.context.version >= Version.policeImprovement3, otherwise it will be set to
// PolicePurpose.Patrol | PolicePurpose.Emergency.

Notes: - This component is used within the Unity.Entities (ECS) framework; Entity fields reference other ECS entities/requests. - Depends on the enums/types PoliceStationFlags, PolicePurpose and the Version constants (policeImprovement2, reverseServiceRequests2, policeImprovement3) provided by the game's codebase.