Game.Citizens.Criminal
Assembly:
Game
Namespace:
Game.Citizens
Type:
public struct Criminal : IComponentData, IQueryTypeParameter, ISerializable
Base:
System.ValueType
Implements: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents a criminal component used by the game's ECS to track a citizen as a criminal. Holds a reference to an associated event entity, remaining jail time, and bitflags describing criminal state. Implements custom serialization/deserialization that is version-aware (handles older save formats where flags were stored as a byte and jail time was not present).
Fields
-
public Entity m_Event
Holds an Entity reference for the crime-related event associated with this criminal (for example, the ongoing crime incident or police event). When serialized this Entity is written/read first. -
public ushort m_JailTime
Remaining jail time (in whatever unit the game uses). The constructor initializes this to 0. This field is only present in serialized data for saves at or after Version.policeImprovement2 — older save versions do not store jail time. -
public CriminalFlags m_Flags
Bitflags describing the criminal's state (defined by the CriminalFlags enum). When serializing for current versions this value is written as a ushort; in older versions the flags were stored as a byte and are upgraded accordingly during deserialization.
Properties
- This struct has no properties.
Constructors
public Criminal(Entity _event, CriminalFlags flags)
Initializes a new Criminal instance with the supplied event Entity and flags. Sets m_JailTime to 0.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component to a writer in the following order: m_Event, m_JailTime, and m_Flags (flags are written as a ushort). Use this when saving component state into a save stream. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the component from a reader. Behavior is version-aware: - For reader.context.version >= Version.policeImprovement2:
- Reads m_Event (Entity), then reads m_JailTime (ushort), then reads flags as a ushort and casts into CriminalFlags.
- For older versions:
- Reads m_Event, then reads a single byte for flags and casts that byte into CriminalFlags. (m_JailTime is not present in older formats, so it remains default/previous value.)
Usage Example
// Create a criminal component and add it to an entity in ECS world (pseudo-code)
Entity criminalEvent = /* obtain or create an Entity representing the crime event */;
CriminalFlags flags = CriminalFlags.None | CriminalFlags.SomeFlag;
var criminal = new Criminal(criminalEvent, flags);
// Example: adding to an entity (pattern depends on modding API)
// entityManager.AddComponentData(entity, criminal);
// Serialization is handled by the game's serializer via the Serialize<TWriter>/Deserialize<TReader> methods.