Skip to content

Game.Prefabs.EmergencyGeneratorData

Assembly: Game
Namespace: Game.Prefabs

Type: struct (value type)

Base: System.ValueType (struct); implements IComponentData, IQueryTypeParameter, ICombineData, ISerializable

Summary:
EmergencyGeneratorData is an ECS component struct used to describe an emergency generator prefab's runtime data. It stores the amount of electricity the generator can produce and a 1D bounds threshold that controls activation behavior. The type supports combining (aggregation across multiple sources) and custom binary serialization/deserialization for the game's entity serialization system.


Fields

  • public int m_ElectricityProduction
    Holds the amount of electricity (integer) produced by this emergency generator component. Used when aggregating production or when deciding power contribution at runtime.

  • public Bounds1 m_ActivationThreshold
    A Bounds1 representing the activation threshold range (min and max) for the generator. The exact semantics depend on game logic (for example, the generator may activate when city power levels fall within/outside this range). Bounds1 is from Colossal.Mathematics and exposes .min and .max float fields.

Properties

  • This type has no properties. All data members are exposed as public fields.

Constructors

  • public EmergencyGeneratorData()
    Default parameterless constructor provided by the value type. Fields are initialized to their default values (m_ElectricityProduction = 0, m_ActivationThreshold with default float values, typically 0).

Methods

  • public void Combine(EmergencyGeneratorData otherData)
    Merges another EmergencyGeneratorData into this instance:
  • Adds otherData.m_ElectricityProduction to this.m_ElectricityProduction.
  • Sets m_ActivationThreshold to a new Bounds1 where:

    • min = math.max(otherData.m_ActivationThreshold.min, this.m_ActivationThreshold.min)
    • max = math.max(otherData.m_ActivationThreshold.max, this.m_ActivationThreshold.max) This effectively accumulates production and takes the larger/minimally more restrictive min and the larger max when combining thresholds.
  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component data to a writer in this order: m_ElectricityProduction (int), m_ActivationThreshold.min (float), m_ActivationThreshold.max (float). Use when persisting component state.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads component data from a reader in the same order as Serialize and stores values into the struct's fields. Uses ref locals to read directly into the struct fields.

Usage Example

// Create and initialize
var genA = new EmergencyGeneratorData
{
    m_ElectricityProduction = 50,
    m_ActivationThreshold = new Bounds1(0.0f, 0.25f)
};

var genB = new EmergencyGeneratorData
{
    m_ElectricityProduction = 30,
    m_ActivationThreshold = new Bounds1(0.1f, 0.5f)
};

// Combine genB into genA (e.g., aggregating multiple sources)
genA.Combine(genB);
// genA.m_ElectricityProduction == 80
// genA.m_ActivationThreshold.min == math.max(0.1f, 0.0f) == 0.1f
// genA.m_ActivationThreshold.max == math.max(0.5f, 0.25f) == 0.5f

// Serialization example (pseudo-code; depends on game writer implementation)
TWriter writer = /* obtain writer */;
genA.Serialize(writer);

// Deserialization example (pseudo-code)
TReader reader = /* obtain reader */;
var genRead = new EmergencyGeneratorData();
genRead.Deserialize(reader);

{{ This component is intended for use with the game's ECS systems. When combining multiple generator components (for example, when summing contributions from linked prefabs or aggregated instances), note that activation thresholds are merged by taking the larger of mins and the larger of maxes — adjust logic if different merging semantics are required. }}