Skip to content

Game.Agents.TaxPayer

Assembly: Game
Namespace: Game.Agents

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary: TaxPayer is a simple ECS component used to track an agent's untaxed income and their average tax rate. It is a blittable value-type component (two ints) intended to be attached to entities representing taxpayers within the game's simulation. The type implements Colossal.Serialization's ISerializable so it can be saved/loaded with the game's save system and IQueryTypeParameter so it can be used in entity queries.


Fields

  • public System.Int32 m_UntaxedIncome Stores the taxpayer's untaxed income as an integer in the game's internal currency units. This value is serialized first. When the component is default-constructed, this value will be 0.

  • public System.Int32 m_AverageTaxRate Stores the taxpayer's average tax rate as an integer percentage (typical range 0–100). This value is serialized after m_UntaxedIncome. For older save versions that do not include this field, the code falls back to a default value of 10 during deserialization.

Properties

  • None (this type exposes public fields and implements behavior via interfaces)

Constructors

  • public TaxPayer()
    Value-type implicit default constructor — fields are zero-initialized (m_UntaxedIncome = 0, m_AverageTaxRate = 0) unless set explicitly. The save deserialization may set a different default for m_AverageTaxRate when reading older versions.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter : System.Void
    Writes the component data to the provided writer in the following order: m_UntaxedIncome, then m_AverageTaxRate. Both are written as integers.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader : System.Void
    Reads component data from the provided reader. Always reads m_UntaxedIncome. Reads m_AverageTaxRate only if reader.context.version >= Version.averageTaxRate; otherwise sets m_AverageTaxRate = 10 as a compatibility fallback for older save versions.

Usage Example

// Create and add the TaxPayer component to an entity (using the EntityManager)
var taxpayer = new TaxPayer {
    m_UntaxedIncome = 50000,   // e.g. game currency units
    m_AverageTaxRate = 12      // percent
};
entityManager.AddComponentData(entity, taxpayer);

// The game's serialization system will call Serialize/Deserialize automatically
// when saving/loading. Note the Deserialize logic:
    // - m_UntaxedIncome is always read from the saved data.
    // - m_AverageTaxRate is read only when the save version includes it.
    //   For older saves, m_AverageTaxRate will be initialized to 10.