Game.Buildings.Prison
Assembly:
Assembly-CSharp (inferred)
Namespace:
Game.Buildings
Type:
struct Prison : IComponentData, IQueryTypeParameter, ISerializable
Base:
Value type (struct). Implements:
- Unity.Entities.IComponentData
- Unity.Entities.IQueryTypeParameter
- Colossal.Serialization.Entities.ISerializable
Summary:
Represents the runtime component data for a prison building. Stores an Entity reference for a pending service/request target, various per-prison flags (PrisonFlags), and two small integer values for prisoner wellbeing and health. Implements custom serialization/deserialization with conditional reads depending on save/version compatibility (checks against Version.reverseServiceRequests and Version.happinessAdjustRefactoring).
Fields
-
public Entity m_TargetRequest
Holds an Entity that represents a target request associated with the prison (e.g., a service request). Serialized by Serialize() and conditionally read during Deserialize() depending on the saved data version. -
public PrisonFlags m_Flags
Bitfield enum representing prison-specific flags/state. Serialized as a single byte (cast to byte when written). -
public sbyte m_PrisonerWellbeing
Signed byte representing overall prisoner wellbeing (range -128..127). Read from serialized data only when the save version is >= Version.happinessAdjustRefactoring. -
public sbyte m_PrisonerHealth
Signed byte representing prisoner health (range -128..127). Also read only when save version >= Version.happinessAdjustRefactoring.
Properties
- None (no public properties are defined in the struct).
Constructors
- Default parameterless constructor (compiler-provided).
No explicit constructors are declared in the source; the struct uses the default value initialization.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Serializes the component fields into the provided writer:- Writes m_TargetRequest (Entity) unconditionally.
- Writes m_Flags cast to a byte.
- Writes m_PrisonerWellbeing (sbyte).
- Writes m_PrisonerHealth (sbyte).
Note: The code writes all fields unconditionally; compatibility is handled on deserialization based on the reader's version.
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Deserializes the component from the provided reader. Behavior depends on reader.context.version:- If reader.context.version >= Version.reverseServiceRequests: reads m_TargetRequest (Entity).
- Reads a byte for flags and assigns to m_Flags.
- If reader.context.version >= Version.happinessAdjustRefactoring: reads m_PrisonerWellbeing and m_PrisonerHealth (both sbyte).
This allows older saves to be read safely by omitting fields not present in earlier versions.
Usage Example
// Example: adding the Prison component to an entity in an ECS system.
using Unity.Entities;
using Game.Buildings;
// Somewhere inside a System or initialization code:
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity prisonEntity = em.CreateEntity(); // or obtain an existing building entity
var prison = new Prison
{
m_TargetRequest = Entity.Null, // no outstanding request initially
m_Flags = PrisonFlags.None, // default flags (enum definition assumed)
m_PrisonerWellbeing = 0,
m_PrisonerHealth = 100 // sample values; domain depends on game logic
};
em.AddComponentData(prisonEntity, prison);
// Note: Serialization is handled by the game's save/load system via the ISerializable
// implementation. Modders typically don't call Serialize/Deserialize directly unless
// implementing custom writers/readers for testing or specialized persistence.
Additional notes: - PrisonFlags enum definition is not included in this file; consult the codebase for available flags and meanings. - The Deserialize method's version checks reference Version.reverseServiceRequests and Version.happinessAdjustRefactoring — ensure compatibility when interacting with saved data across game versions.