Game.Creatures.Domesticated
Assembly: Assembly-CSharp
Namespace: Game.Creatures
Type: struct
Base: System.ValueType, IComponentData, IQueryTypeParameter, ISerializable
Summary: Domesticated is a value-type ECS component used by the game's creature system to mark and store basic domestication state for an entity. It holds a bitmask of flags plus two small timers/counters. The struct implements Colossal.Serialization.Entities.ISerializable so it can be written to and read from the game's save/serialization system.
Fields
-
public DomesticatedFlags m_Flags
This field is a bitmask (enum with Flags) representing the domestication state(s) of the creature. The exact meaning of individual bits is defined by the DomesticatedFlags enum in the codebase; typical uses are to indicate specific statuses or toggles related to domestication. -
public ushort m_StateTime
A 16-bit unsigned counter representing a state-related timer. Units are determined by game logic (e.g., frames, ticks, or seconds converted to internal units). Used to track how long the creature has been in the current domesticated state. -
public ushort m_LifeTime
A 16-bit unsigned counter representing a lifetime or age-related measure for the domesticated creature. As with m_StateTime, the unit semantics depend on the surrounding game logic.
Properties
- This type does not declare any public properties. It exposes only public fields and implements several interfaces for ECS and serialization.
Constructors
public Domesticated()
No explicit constructors are declared in the source; the compiler-provided default struct constructor initializes numeric fields to 0 and enum fields to their default value.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component data to a writer for saving. Implementation writes the m_Flags (cast to uint), followed by m_StateTime and m_LifeTime in that order. This order must be preserved by Deserialize. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads component data from a reader. Implementation reads a uint (flags) first, then reads m_StateTime and m_LifeTime into their respective fields, and finally casts the uint into DomesticatedFlags and assigns to m_Flags. Note the read order matches the write order used in Serialize.
Remarks: - The Serialize/Deserialize implementations use generic writer/reader interfaces from Colossal.Serialization.Entities, which are used by the game's save/load pipeline. When creating custom save logic or patches, maintain the same read/write ordering and types to ensure compatibility. - As an ECS IComponentData, this struct is meant to be stored on the EntityManager and accessed from systems; mutate through Add/SetComponentData or IComponentData APIs rather than direct references to avoid race conditions and to respect job safety constraints.
Usage Example
// Create and add a Domesticated component to an entity
var domesticated = new Domesticated {
m_Flags = DomesticatedFlags.None, // or other flag combination
m_StateTime = 0,
m_LifeTime = 0
};
entityManager.AddComponentData(entity, domesticated);
// Later, update the lifetime safely from a system (pseudo-code)
Domesticated d = entityManager.GetComponentData<Domesticated>(entity);
d.m_LifeTime += 1; // increment (watch for overflow)
entityManager.SetComponentData(entity, d);
// The Serialize/Deserialize methods are called by the game's save system.
// If implementing custom serialization tests, ensure the writer/reader order matches:
writer.Write((uint)d.m_Flags);
writer.Write(d.m_StateTime);
writer.Write(d.m_LifeTime);
{{ Notes }} - Domesticated is lightweight and suitable for frequent reads/writes in ECS systems, but as with any component, avoid excessive boxing or copying in hot paths. - Pay attention to units of m_StateTime and m_LifeTime when integrating with gameplay logic—convert to/from seconds or frames consistently.