Skip to content

Game.Hospital

Assembly:
Assembly-CSharp

Namespace:
Game.Prefabs

Type:
class

Base:
ComponentBase, IServiceUpgrade

Summary:
Prefab component that defines hospital building behaviour and data for the ECS-based simulation. This class exposes configuration fields (ambulance/medical helicopter capacity, patient capacity, treatment bonus, health range and treatment flags) and wires up the required ECS components/archetypes and initial component data when the prefab entity is created. It also provides components used for upgrades (when the prefab represents an upgrade building).


Fields

  • public int m_AmbulanceCapacity = 10
    Defines the number of ambulance slots/capacity that this hospital prefab provides. Used to initialize HospitalData.m_AmbulanceCapacity on the created entity.

  • public int m_MedicalHelicopterCapacity
    Number of medical helicopter slots. Defaults to 0 if not set. Initialized to HospitalData.m_MedicalHelicopterCapacity.

  • public int m_PatientCapacity = 10
    Number of patient slots the hospital supports. If set to 0, patient-related ECS components (Patient) are not added in GetArchetypeComponents/GetUpgradeComponents.

  • public int m_TreatmentBonus = 3
    Numeric modifier applied to treatment effectiveness for this hospital. Mapped to HospitalData.m_TreatmentBonus.

  • public int2 m_HealthRange = new int2(0, 100)
    Range for health values that the hospital affects. Stored in HospitalData.m_HealthRange. Uses Unity.Mathematics.int2.

  • public bool m_TreatDiseases = true
    Flag indicating if the hospital treats diseases. Stored in HospitalData.m_TreatDiseases.

  • public bool m_TreatInjuries = true
    Flag indicating if the hospital treats injuries. Stored in HospitalData.m_TreatInjuries.

Properties

  • (none)
    This class does not declare C# properties; it exposes public fields and implements interface methods for ECS component registration and initialization.

Constructors

  • public Hospital()
    Default constructor (implicit). Fields are initialized to their declared defaults (e.g., m_AmbulanceCapacity = 10, m_PatientCapacity = 10, m_HealthRange = (0,100), etc.). No additional runtime logic in the constructor — prefab setup happens via overridden methods.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds low-level component types required on the prefab entity itself:
  • Adds HospitalData and UpdateFrameData (read/write).
  • This method is used to ensure the prefab asset contains the minimal ECS component layout required for this building's data and update scheduling.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds ECS components that should be part of the instantiated building entity archetype, conditionally:

  • If the prefab does not contain a ServiceUpgrade component, adds Game.Buildings.Hospital component.
  • If the prefab has CityServiceBuilding, also adds Efficiency and ServiceUsage.
  • Adds OwnedVehicle and ServiceDispatch.
  • If the prefab is not a UniqueObject, adds ServiceDistrict.
  • If m_PatientCapacity != 0, adds Patient.
  • This method tailors the entity archetype based on whether the prefab is an upgrade, a city service, or unique, and whether it needs patient support.

  • public void GetUpgradeComponents(HashSet<ComponentType> components)
    Used when this prefab is provided as an upgrade building. Adds components required for upgrade behavior:

  • Always adds Game.Buildings.Hospital, ServiceDispatch, OwnedVehicle and ServiceUsage.
  • Adds Patient if m_PatientCapacity != 0.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Initializes the created entity's component data:

  • Writes a HospitalData struct to the entity with values taken from this prefab's public fields (capacities, treatment bonus, health range, treat flags).
  • Sets UpdateFrameData(1) to schedule the entity for update.
  • This is the place where prefab configuration is converted into runtime component data for the ECS simulation.

Usage Example

// Example: What Initialize does internally — the prefab uses this to set initial ECS component data.
public override void Initialize(EntityManager entityManager, Entity entity)
{
    // Populate the HospitalData component on the entity using the prefab's configured fields
    entityManager.SetComponentData(entity, new HospitalData
    {
        m_AmbulanceCapacity = m_AmbulanceCapacity,
        m_MedicalHelicopterCapacity = m_MedicalHelicopterCapacity,
        m_PatientCapacity = m_PatientCapacity,
        m_TreatmentBonus = m_TreatmentBonus,
        m_HealthRange = m_HealthRange,
        m_TreatDiseases = m_TreatDiseases,
        m_TreatInjuries = m_TreatInjuries
    });

    // Ensure the entity is scheduled for updates (frame index 1 here)
    entityManager.SetComponentData(entity, new UpdateFrameData(1));
}

Notes and tips: - The prefab's behaviour depends on combination with other components (ServiceUpgrade, CityServiceBuilding, UniqueObject). When creating custom hospital prefabs or upgrades, ensure the correct components/markers are present so the correct archetype is generated. - If you want a hospital without patient entities (for example, a building that only dispatches vehicles), set m_PatientCapacity = 0 — this prevents the Patient component from being added to the archetype.