Skip to content

Game.PostFacility

Assembly: Game
Namespace: Game.Buildings

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents the runtime component attached to building entities that model post/mail facilities (post offices) in the game. Holds references to transfer-request entities used by the in-game transfer system, mail accept/deliver priorities, a small flags field and a processing factor. Implements Colossal.Serialization.Entities.ISerializable to control how the component is written to and read from saved data, with explicit version checks to preserve compatibility across save-format changes.


Fields

  • public Entity m_MailDeliverRequest
    Holds an Entity reference to the transfer request used when this post facility is delivering mail. Serialized when the save version is at or past the transferRequestRefactoring change.

  • public Entity m_MailReceiveRequest
    Holds an Entity reference to the transfer request used when this post facility is receiving/accepting mail. Serialized when the save version is at or past transferRequestRefactoring.

  • public Entity m_TargetRequest
    An Entity reference introduced/used by a later refactor. This field is read during deserialization only if the save version is at or beyond Version.reverseServiceRequests2.

  • public float m_AcceptMailPriority
    A float that represents the priority/weight this facility gives to accepting incoming mail transfer requests. Serialized when reader.context.version >= Version.transferRequestRefactoring.

  • public float m_DeliverMailPriority
    A float that represents the priority/weight this facility gives to delivering outgoing mail transfer requests. Serialized when reader.context.version >= Version.transferRequestRefactoring.

  • public PostFacilityFlags m_Flags
    A small flags enum stored as a byte in serialized data. During serialization it is cast to a byte; during deserialization a single byte is read and converted back into PostFacilityFlags.

  • public byte m_ProcessingFactor
    A byte-sized factor used by mail processing logic (e.g., processing speed/throughput scaling). Only read from serialized data when reader.context.version >= Version.mailProcessing; otherwise it remains at the default value.

Properties

  • This type does not declare any public properties. It exposes only public fields and the serialization methods required by ISerializable.

Constructors

  • public PostFacility()
    No explicit constructor is defined in the source file (C# provides a default parameterless constructor for structs). Initialization typically relies on setting fields directly before the component is used. When deserialized, fields are set by the Deserialize implementation according to save version.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes component state to the writer in a fixed order:
  • Writes m_MailDeliverRequest and m_MailReceiveRequest (these correspond to transfer-request entities).
  • Writes m_AcceptMailPriority and m_DeliverMailPriority.
  • Writes m_TargetRequest.
  • Writes m_Flags cast to a byte.
  • Writes m_ProcessingFactor. The method assumes the target save format expects these values in this exact order.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads component state from the reader while handling multiple save-version differences:

  • If reader.context.version >= Version.transferRequestRefactoring, reads m_MailDeliverRequest, m_MailReceiveRequest, m_AcceptMailPriority and m_DeliverMailPriority. For older versions it reads and discards an Entity placeholder.
  • If reader.context.version >= Version.reverseServiceRequests2, reads m_TargetRequest; otherwise leaves it default (Entity.Null).
  • Reads a single byte that represents flags, converts that byte to PostFacilityFlags and assigns to m_Flags.
  • If reader.context.version >= Version.mailProcessing, reads m_ProcessingFactor; otherwise m_ProcessingFactor remains the default (0). This method ensures compatibility across changes to the transfer/requests model by conditionally reading fields only when present in the saved data.

Usage Example

// Create and initialize a PostFacility component for a building entity
Entity entity = entityManager.CreateEntity(typeof(PostFacility));

PostFacility post = new PostFacility
{
    m_MailDeliverRequest = Entity.Null,
    m_MailReceiveRequest = Entity.Null,
    m_TargetRequest = Entity.Null,
    m_AcceptMailPriority = 1.0f,
    m_DeliverMailPriority = 1.0f,
    m_Flags = default(PostFacilityFlags), // use the enum's default value
    m_ProcessingFactor = 1
};

entityManager.SetComponentData(entity, post);

Notes and tips: - The Serialize/Deserialize methods are invoked by the game's save/load infrastructure (Colossal.Serialization.Entities). Modders generally do not call them directly unless implementing custom serialization paths. - Pay attention to the version checks in Deserialize: fields are only present in certain save versions, so code that reads these fields must be prepared for Entity.Null/default values when loading older saves. - PostFacilityFlags and related Version enum members are defined elsewhere in the game's codebase; consult those definitions to understand available flags and version constants.