Game.Buildings.Hospital
Assembly: Assembly-CSharp
Namespace: Game.Buildings
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary: Represents per-entity data for a Hospital building in the ECS world. Holds a reference to a related service request entity, bitflags describing hospital state, and compact health/treatment values used by the healthcare simulation and save/load serialization. Serialization and deserialization are version-aware so data layout can differ between game versions.
Fields
-
public Unity.Entities.Entity m_TargetRequest
Reference to a service-request entity targeted by this hospital (e.g., for patient requests). This value is serialized; reading it during deserialization is gated by a version check (see Deserialize). -
public HospitalFlags m_Flags
Bitmask enum storing hospital-specific flags/state. Serialized as a single byte. -
public byte m_TreatmentBonus
Compact value representing bonus to treatment effectiveness. Introduced in a later game version; read during deserialization only when the reader context version is >= Version.healthcareImprovement. -
public byte m_MinHealth
Minimum health value for patients tracked by this hospital. Only present and read when reader context version >= Version.healthcareImprovement2. -
public byte m_MaxHealth
Maximum health value for patients tracked by this hospital. Only present and read when reader context version >= Version.healthcareImprovement2.
Properties
- This struct exposes no public properties. It is a plain IComponentData struct with public fields.
Constructors
public Hospital()
No explicit constructors are defined; the default value-type (struct) constructor is used. When added as a component the fields should be initialized explicitly where required.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Serializes the component fields into the provided writer. Order written:- m_TargetRequest (Entity)
- m_Flags (written as a byte)
- m_TreatmentBonus (byte)
- m_MinHealth (byte)
-
m_MaxHealth (byte) The writer does not perform version gating here; the corresponding Deserialize performs version checks when reading.
-
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Deserializes fields from the reader with version-aware branching: - If reader.context.version >= Version.reverseServiceRequests2, reads m_TargetRequest.
- Reads a byte into a temporary
value
which is later cast to HospitalFlags and assigned to m_Flags. - If reader.context.version >= Version.healthcareImprovement, reads m_TreatmentBonus.
- If reader.context.version >= Version.healthcareImprovement2, reads m_MinHealth and m_MaxHealth. Note: The order of reads matches the order written by Serialize; conditional reads ensure compatibility across versions.
Usage Example
// Creating and adding a Hospital component to an entity using an EntityManager:
var hospital = new Game.Buildings.Hospital {
m_TargetRequest = Entity.Null, // no active request initially
m_Flags = HospitalFlags.None, // set appropriate flags
m_TreatmentBonus = 5, // example bonus
m_MinHealth = 30,
m_MaxHealth = 90
};
entityManager.AddComponentData(hospitalEntity, hospital);
// Serialization is handled by the game's save system via ISerializable implementations.
// When implementing custom save/load logic, respect the writer/reader versioning used above.
Additional notes: - Because Hospital implements IComponentData it is intended to be used as an ECS component (Unity.Entities). - The struct also implements IQueryTypeParameter which allows using this type as a parameter in ECS query helpers. - The version checks in Deserialize rely on game Version constants (Version.reverseServiceRequests2, Version.healthcareImprovement, Version.healthcareImprovement2) to maintain backward/forward compatibility of saved data. Ensure reader.context.version is set appropriately when performing manual reads.