Game.Buildings.ElectricityConsumer
Assembly: Assembly-CSharp
Namespace: Game.Buildings
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents an ECS component attached to building instances that consume electricity. Tracks the building's wanted and fulfilled electricity consumption values, a cooldown counter (used for flashing/notification timing), and flags describing the consumer state (for example whether it is connected). Implements serialization/deserialization with backwards compatibility logic for older save/game versions. Intended for use inside Unity.Entities systems that process building electricity consumption and notifications.
Fields
-
public int m_WantedConsumption
Stores the target/desired electricity consumption for the building (units are the game's internal electricity units). This is the amount the building attempts to draw. -
public int m_FulfilledConsumption
Stores the actual amount of electricity that was fulfilled/supplied to the building. Can be less than m_WantedConsumption if supply is constrained. -
public short m_CooldownCounter
A small counter (short) used for timing-related behavior such as flashing/notification cooldowns. Note: older save formats stored a different size here and Deserialize contains compatibility checks. -
public ElectricityConsumerFlags m_Flags
Bitflags describing consumer state. At minimum the enum contains a Connected flag used to indicate electricity connectivity. See the ElectricityConsumerFlags enum for all possible flags.
Properties
public bool electricityConnected { get; }
Returns true when the Connected bit is set on m_Flags: Implementation: (m_Flags & ElectricityConsumerFlags.Connected) != 0
This is the simplest way to check whether the consumer is currently considered electrically connected.
Constructors
public ElectricityConsumer()
No explicit constructor is defined in the source; the struct uses the default parameterless constructor. Default values: m_WantedConsumption = 0, m_FulfilledConsumption = 0, m_CooldownCounter = 0, m_Flags = 0.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Serializes the component's state into the provided writer. The serialization order is:- m_WantedConsumption (int)
- m_FulfilledConsumption (int)
- m_CooldownCounter (short)
- m_Flags cast to a byte
Note: m_Flags is written as a byte (so the storage assumes the enum fits in a byte).
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Deserializes component state from reader with several version-gated compatibility branches:- Reads m_WantedConsumption and m_FulfilledConsumption (ints).
- For versions older than Version.electricityFlashFix, an extra integer is read and discarded (legacy layout). For newer versions, m_CooldownCounter (short) is read.
- For versions >= Version.notificationData:
- If version >= Version.bottleneckNotification, reads a byte and casts to ElectricityConsumerFlags.
- Else (legacy path) reads a bool. The legacy code treats a false boolean by setting m_Flags = ElectricityConsumerFlags.Connected. (This reflects an older storage/semantics — consult save format version constants for precise meaning.)
- For versions older than Version.buildingEfficiencyRework, additional legacy fields related to utility/electricity fees may be present and are read & discarded depending on intermediate version thresholds:
- If version >= Version.utilityFeePrecision: reads a float (discarded).
- Else if version >= Version.electricityFeeEffect: reads an int (discarded).
These branches ensure backward compatibility with saved games from older versions by consuming legacy fields and mapping legacy values into the current m_Flags / counters.
Usage Example
// Example: create an ElectricityConsumer, set values and check connectivity.
// In real mod code this component would be added to an Entity via ECS APIs.
var consumer = new Game.Buildings.ElectricityConsumer();
consumer.m_WantedConsumption = 120; // building wants 120 units
consumer.m_FulfilledConsumption = 80; // only 80 units were supplied
consumer.m_CooldownCounter = 0;
// Set the Connected flag (assumes ElectricityConsumerFlags.Connected exists)
consumer.m_Flags = ElectricityConsumerFlags.Connected;
// Query connectivity
bool isConnected = consumer.electricityConnected; // true
// Serialization example (pseudo-code: actual writer type depends on game's serializer)
void SaveComponent<TWriter>(TWriter writer, Game.Buildings.ElectricityConsumer c) where TWriter : IWriter
{
c.Serialize(writer);
}
{{ This component is a lightweight ECS data container used by building electricity systems. The Deserialize method contains multiple version checks (Version.electricityFlashFix, Version.notificationData, Version.bottleneckNotification, Version.buildingEfficiencyRework, Version.utilityFeePrecision, Version.electricityFeeEffect) to maintain compatibility with legacy save data; modders interacting with save data or implementing custom serialization should be aware of these branches. For flag meanings beyond Connected, consult the ElectricityConsumerFlags enum definition in the codebase. }}