Skip to content

Game.City.XP

Assembly: Assembly-CSharp (game runtime)
Namespace: Game.City

Type: struct

Base: System.ValueType
Implements: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents the XP-related state stored on an entity for Cities: Skylines 2. Contains the current XP value, historical maximums for population and income (used for XP calculations or display), and a compact record of XP rewards (stored as an enum backed by a byte). The struct provides custom binary serialization/deserialization with save-version checks to keep backward compatibility across game versions.


Fields

  • public int m_XP
    Current XP value for the entity (city).

  • public int m_MaximumPopulation
    Highest recorded population value. This field is conditionally serialized/deserialized depending on save version (see Deserialize notes).

  • public int m_MaximumIncome
    Highest recorded income value. Also conditionally serialized/deserialized depending on save version.

  • public XPRewardFlags m_XPRewardRecord
    Flags recording which XP rewards have been granted. Serialized as a single byte.

Properties

  • None. This struct exposes public fields rather than properties.

Constructors

  • public XP() (implicit default)
    Struct has the default parameterless constructor; initialize fields via object initializer or by setting fields directly.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the member data to a writer in the following order:
  • m_XP (int)
  • m_MaximumPopulation (int)
  • m_MaximumIncome (int)
  • m_XPRewardRecord written as a byte (cast (byte)m_XPRewardRecord) Notes:
  • Serialization writes the maximum fields and the reward record unconditionally; the reader side decides whether to read them depending on the save version.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads member data from a reader. Behavior:

  • Always reads m_XP.
  • If reader.context.version >= Version.xpMaximumStats, reads m_MaximumPopulation and m_MaximumIncome.
  • If reader.context.version >= Version.xpRewardRecord, reads a byte and casts it to XPRewardFlags into m_XPRewardRecord. Notes:
  • The method relies on the reader.context.version to handle backward compatibility with older save formats that did not include the maximum statistics or reward-record fields.
  • For older versions where fields are absent, those members remain at their default values unless the caller initializes them beforehand.

Usage Example

// Add an XP component to an entity (ECS):
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
var e = em.CreateEntity(typeof(Game.City.XP));
em.SetComponentData(e, new Game.City.XP {
    m_XP = 125,
    m_MaximumPopulation = 4800,
    m_MaximumIncome = 56000,
    m_XPRewardRecord = XPRewardFlags.None
});

// Manual serialization example (pseudo-usage; concrete writer depends on modding API):
var writer = /* obtain an IWriter implementation */;
var xp = new Game.City.XP {
    m_XP = 125,
    m_MaximumPopulation = 4800,
    m_MaximumIncome = 56000,
    m_XPRewardRecord = XPRewardFlags.None
};
xp.Serialize(writer);

// Manual deserialization example:
var reader = /* obtain an IReader implementation with reader.context.version set appropriately */;
var xpRead = default(Game.City.XP);
xpRead.Deserialize(reader);
// Now xpRead contains data read according to reader.context.version

Additional notes: - Because XP is an IComponentData, prefer using ECS APIs (EntityManager / SystemBase) to manipulate instances on entities. - The serialization/deserialization methods are generic over IWriter/IReader; use the game's provided implementations when saving/loading mod data.