Skip to content

Game.School

Assembly:
Namespace: Game.Buildings

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary: Represents per-building runtime data for a school in the game's ECS. Tracks aggregated student statistics such as average graduation time and average failure probability, plus compact wellbeing and health values stored as signed bytes. Implements custom serialization/deserialization to persist these values; deserialization conditionally reads wellbeing/health depending on the saved data version (compatibility with older saves).


Fields

  • public float m_AverageGraduationTime Average time for students to graduate for this school, stored as a floating-point value. Used by simulation code to compute progression/throughput.

  • public float m_AverageFailProbability Average probability (0..1 range) that a student will fail, aggregated for the building. Used to influence graduation outcomes.

  • public sbyte m_StudentWellbeing Compact wellbeing value for students at this school (stored as signed byte). Introduced/used starting from a specific version (see Deserialize).

  • public sbyte m_StudentHealth Compact health value for students at this school (stored as signed byte). Also conditionally deserialized depending on save version.

Properties

  • This struct has no properties.

Constructors

  • public School() Default value-type constructor (implicit). All numeric fields are initialized to zero when using the default constructor or default(School).

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter Writes the fields to the provided writer in the following order:
  • m_AverageGraduationTime
  • m_AverageFailProbability
  • m_StudentWellbeing
  • m_StudentHealth All fields are written unconditionally (the writer side does not check save version).

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader Reads fields back from a reader. The method always reads average graduation time and average fail probability. The wellbeing and health fields are read only if the reader's context version is at least Version.happinessAdjustRefactoring; this preserves compatibility with older save files that did not include these fields.

Notes: - TWriter must implement IWriter and TReader must implement IReader (from Colossal.Serialization.Entities). - The version check uses reader.context.version, so deserialization depends on the save file/game version metadata.

Usage Example

// Create and populate a School instance
var school = new Game.Buildings.School {
    m_AverageGraduationTime = 120f,
    m_AverageFailProbability = 0.15f,
    m_StudentWellbeing = 50,
    m_StudentHealth = 60
};

// Serialize using an IWriter implementation
IWriter writer = /* obtain a writer from the game's save system or serializer */;
school.Serialize(writer);

// Deserialize using an IReader implementation
Game.Buildings.School loaded = default;
IReader reader = /* obtain a reader that wraps save data */;
loaded.Deserialize(reader);

// After Deserialize, loaded will have its averages always set.
// m_StudentWellbeing and m_StudentHealth will be populated only if
// reader.context.version >= Version.happinessAdjustRefactoring.