Game.Simulation.CollectedCityServiceUpkeepData
Assembly: Game
Namespace: Game.Simulation
Type: struct
Base: IBufferElementData, ISerializable
Summary:
Represents a single entry of city service upkeep data used by the simulation. Stored as a buffer element (IBufferElementData) so multiple entries can be attached to an entity's DynamicBuffer. Implements Colossal.Serialization.Entities.ISerializable to allow compact binary serialization/deserialization for save/load or network transfer. Fields track the resource type, the full cost, the amount kept/used, and the effective cost.
Fields
-
public Resource m_Resource
Type: Game.Economy.Resource enum. Indicates which resource this upkeep entry is for (e.g., money, electricity, water, etc.). Serialized as an int. -
public int m_FullCost
Stores the full (base) upkeep cost for this entry before any adjustments. -
public int m_Amount
Represents the amount (units) relevant to this upkeep entry (for example, units of service or quantity affecting cost). -
public int m_Cost
The actual cost applied (after modifiers) for this entry.
Properties
- (none)
This struct exposes only public fields and no properties.
Constructors
public CollectedCityServiceUpkeepData()
Default value-type constructor generated by the runtime. All fields initialize to their default values (m_Resource = default enum value, ints = 0). Typically instances are populated by setting fields or via serialization.
Methods
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads fields from a binary reader in the fixed order used by Serialize. The method:- Reads an int and casts it to Resource into m_Resource.
-
Reads m_FullCost, m_Amount, then m_Cost (each as int) into the respective fields. Important: order must match Serialize for correct round-trip.
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes fields to a binary writer in a fixed order: - Writes (int)m_Resource
- Writes m_FullCost
- Writes m_Amount
- Writes m_Cost This compact representation is used for saving/loading and requires Deserialize to read the same ordering and types.
Usage Example
// Add an entry to an entity's buffer (inside a system)
var buffer = EntityManager.GetBuffer<CollectedCityServiceUpkeepData>(someEntity);
buffer.Add(new CollectedCityServiceUpkeepData {
m_Resource = Game.Economy.Resource.Money,
m_FullCost = 1000,
m_Amount = 1,
m_Cost = 900
});
// Example pseudo-serialization using a writer (actual writer type from Colossal.Serialization.Entities):
var entry = buffer[0];
writer.Write((int)entry.m_Resource);
writer.Write(entry.m_FullCost);
writer.Write(entry.m_Amount);
writer.Write(entry.m_Cost);
// Corresponding deserialize (reader must read in same order):
CollectedCityServiceUpkeepData readEntry = default;
reader.Read(out int resourceValue);
readEntry.m_Resource = (Game.Economy.Resource)resourceValue;
reader.Read(out readEntry.m_FullCost);
reader.Read(out readEntry.m_Amount);
reader.Read(out readEntry.m_Cost);
Notes:
- Because this is an IBufferElementData, prefer using DynamicBuffer