Skip to content

Game.Prefabs.PoliceStation

Assembly: Game
Namespace: Game.Prefabs

Type: public class PoliceStation

Base: ComponentBase, IServiceUpgrade

Summary:
Represents the Police Station prefab used by the game's ECS-based simulation. Exposes configurable capacities (patrol cars, helicopters, jail) and purposes (patrol, emergency, etc.). When the prefab is instantiated it registers the required component types for both the prefab and the runtime archetype and initializes runtime component data (PoliceStationData and UpdateFrameData). Provides support for service upgrades via IServiceUpgrade (GetUpgradeComponents).


Fields

  • public int m_PatrolCarCapacity = 10
    Configurable number of patrol car slots this police station provides. Written into PoliceStationData during Initialize.

  • public int m_PoliceHelicopterCapacity
    Configurable number of police helicopter slots. Written into PoliceStationData during Initialize.

  • public int m_JailCapacity = 15
    Number of jail occupant slots. If non-zero, the archetype will include the Occupant component so prisoners can be tracked.

  • [EnumFlag] public PolicePurpose m_Purposes = PolicePurpose.Patrol | PolicePurpose.Emergency
    Bitmask indicating functional purposes of this station (e.g., Patrol, Emergency). Stored to PoliceStationData.m_PurposeMask during Initialize.

Properties

  • None exposed by this class.

Constructors

  • public PoliceStation()
    Implicit default constructor. The class is generally used as a Unity prefab component, so initialization of runtime data is performed in Initialize rather than the constructor.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the component types that must exist on the prefab (not necessarily on instantiated entities). This implementation adds:
  • PoliceStationData (read/write)
  • UpdateFrameData (read/write)

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds component types required on the runtime entity archetype when this prefab is instantiated. Behavior:

  • Always adds Game.Buildings.PoliceStation component (the building descriptor).
  • If the prefab does not include ServiceUpgrade:
    • If it includes CityServiceBuilding, adds Efficiency.
    • Adds ServiceDispatch and OwnedVehicle.
    • If it is not a UniqueObject, adds ServiceDistrict.
    • If m_JailCapacity != 0, adds Occupant.

This logic ensures entities have the appropriate simulation components for dispatching vehicles, tracking efficiency, districts, and jail occupants.

  • public void GetUpgradeComponents(HashSet<ComponentType> components)
    Implements IServiceUpgrade to declare component types required when this prefab is used as an upgrade. Adds:
  • Game.Buildings.PoliceStation
  • ServiceDispatch
  • OwnedVehicle
  • Occupant (if m_JailCapacity != 0)

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Initializes runtime component data for an instantiated entity:

  • Creates and sets PoliceStationData with m_PatrolCarCapacity, m_PoliceHelicopterCapacity, m_JailCapacity, and m_PurposeMask (from m_Purposes).
  • Sets UpdateFrameData with a tick/frame offset of 8 (new UpdateFrameData(8)).

Usage Example

// When the prefab is instantiated, the framework will call Initialize.
// The following mirrors what PoliceStation.Initialize does:

protected override void Initialize(EntityManager entityManager, Entity entity)
{
    var policeData = default(PoliceStationData);
    policeData.m_PatrolCarCapacity = m_PatrolCarCapacity;
    policeData.m_PoliceHelicopterCapacity = m_PoliceHelicopterCapacity;
    policeData.m_JailCapacity = m_JailCapacity;
    policeData.m_PurposeMask = m_Purposes;
    entityManager.SetComponentData(entity, policeData);

    // Schedule the update frame offset
    entityManager.SetComponentData(entity, new UpdateFrameData(8));
}

Notes and tips: - Tweak the public integer fields on the prefab (in the Unity inspector or via prefab script) to alter the station's capacity/purpose behavior. - If you add ServiceUpgrade, CityServiceBuilding, UniqueObject, or other marker components to the prefab, GetArchetypeComponents will behave differently (e.g., skip adding Efficiency or ServiceDistrict). - m_Purposes uses an EnumFlag; combine flags like PolicePurpose.Patrol | PolicePurpose.Emergency to enable multiple behaviors.