Game.Events.AccidentSite
Assembly: Game
Namespace: Game.Events
Type: struct (value type)
Base: System.ValueType
Implements: Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable
Summary:
Represents an accident site tracked by the game/event systems. Stores references to the event entity and an optional police request entity, flags describing the accident site state, and frame timestamps for creation and (optionally) when the site was secured. Implements custom binary serialization and deserialization to support save/load and version compatibility (the secured-frame field is only read for newer save versions).
Fields
-
public Unity.Entities.Entity m_Event
Reference to the Entity that represents the accident event (the primary event entity). -
public Unity.Entities.Entity m_PoliceRequest
Reference to an Entity representing a police request related to the accident. Set to Entity.Null by the provided constructor by default. -
public AccidentSiteFlags m_Flags
Flags (likely an enum) describing the accident site's properties/state. Serialized as a uint. -
public uint m_CreationFrame
The simulation frame at which the accident site was created. -
public uint m_SecuredFrame
The simulation frame at which the site was secured. This field is only deserialized when the save/version supports the policeImprovement feature.
Properties
- None (no C# properties defined; this is a plain struct with public fields).
Constructors
public AccidentSite(Entity _event, AccidentSiteFlags flags, uint currentFrame)
Initializes a new AccidentSite:- m_Event is set to the supplied _event.
- m_PoliceRequest is initialized to Entity.Null.
- m_Flags is set to the supplied flags.
- m_CreationFrame is set to currentFrame.
- m_SecuredFrame is set to 0.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the struct fields to the provided writer in this order:- m_Event (Entity)
- m_PoliceRequest (Entity)
- m_Flags (written as uint)
- m_CreationFrame (uint)
-
m_SecuredFrame (uint)
This method is used for saving the component state. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the struct fields from the provided reader in the same order they were written: - m_Event (Entity)
- m_PoliceRequest (Entity)
- a uint that will be interpreted as AccidentSiteFlags (stored temporarily)
- m_CreationFrame (uint)
- m_SecuredFrame (uint) — only read if reader.context.version >= Version.policeImprovement
After reading, assigns the read flags uint to m_Flags. The conditional read ensures backward/forward compatibility with saves created before the police improvement change.
Notes: - The generic Serialize/Deserialize signatures rely on writer/reader types implementing IWriter/IReader. - The version check (reader.context.version >= Version.policeImprovement) gates reading of m_SecuredFrame to avoid errors with older save formats.
Usage Example
// Create a new AccidentSite and add it as a component to an entity (EntityManager example):
var accidentEventEntity = /* obtain or create the event entity */;
uint currentFrame = (uint)SimulationManager.instance.m_currentFrameIndex;
var site = new AccidentSite(accidentEventEntity, AccidentSiteFlags.None, currentFrame);
// Assuming you have an Entity 'siteEntity' to hold the component:
entityManager.AddComponentData(siteEntity, site);
// Serialization/deserialization is handled by the implemented ISerializable methods
// when the engine saves/loads components.
{{ This struct is intended for ECS-based tracking of accident-related events in Cities: Skylines 2. The conditional deserialization of m_SecuredFrame ensures compatibility across save versions that introduced police-related improvements. For more context, see the AccidentSiteFlags enum and Version constants used by the reader context. }}