Skip to content

Game.Simulation.PoliceEmergencyRequest

Assembly: Assembly-CSharp
Namespace: Game.Simulation

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents a request for police response in the simulation. This struct is a ECS component carrying the origin site, the target entity to attend, a numerical priority, and the intended police purpose. It implements ISerializable to allow persistence and network/state serialization, with backward-compatible handling of the PolicePurpose field based on save/version information.


Fields

  • public Entity m_Site
    Entity representing the site or source of the request (where the request originated, e.g., a building, service site, or incident location).

  • public Entity m_Target
    Entity representing the target of the police action (could be a vehicle, person, building, or other entity that police should interact with).

  • public float m_Priority
    Floating-point priority value for the request. Higher values indicate higher urgency for processing/dispatch.

  • public PolicePurpose m_Purpose
    Bitflag (enum) describing the intended purpose of the police response (e.g., Patrol, Emergency, etc.). This field is serialized conditionally depending on the save/version.

Properties

  • None

Constructors

  • public PoliceEmergencyRequest(Entity site, Entity target, float priority, PolicePurpose purpose)
    Creates a new PoliceEmergencyRequest with the specified site, target, priority and purpose. Typical usage when scheduling or enqueueing a police response request.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component fields to the provided writer in the following order: m_Site, m_Target, m_Priority, and then m_Purpose as an int. Used for saving or networking. The method serializes the PolicePurpose by casting it to int.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the component fields from the provided reader in the same order. For the PolicePurpose field it checks reader.context.version:

  • If reader.context.version >= Version.policeImprovement3: reads an int and casts to PolicePurpose.
  • Otherwise (older versions) sets m_Purpose to a compatibility default: PolicePurpose.Patrol | PolicePurpose.Emergency. This ensures backward compatibility with saves that predate the purpose field.

Usage Example

// Create a new request and add it as a component to an entity
var request = new PoliceEmergencyRequest(siteEntity, targetEntity, 1.0f, PolicePurpose.Emergency);
entityManager.AddComponentData(requestEntity, request);

// Example: read fields from a request component in a system
var req = entityManager.GetComponentData<PoliceEmergencyRequest>(requestEntity);
UnityEngine.Debug.Log($"Police request from {req.m_Site} to {req.m_Target}, priority {req.m_Priority}, purpose {req.m_Purpose}");

Additional notes: - Because this type implements IComponentData it is intended to be used as a DOTS/ECS component attached to Entities. - The ISerializable implementation uses generic reader/writer interfaces from Colossal.Serialization; the Deserialize method contains explicit version checks to preserve behavior for older save versions where m_Purpose did not exist. - PolicePurpose is treated as a flags enum; code handling this field should account for combined flags (e.g., Patrol | Emergency).