Skip to content

Game.UI.InGame.EmploymentData

Assembly: Game

Namespace: Game.UI.InGame

Type: readonly struct

Base: System.ValueType, IJsonWritable

Summary:
EmploymentData is an immutable value type that holds counts of workers/employees split by education level plus the number of open positions and an aggregate total. It is serializable to JSON via IJsonWritable and provides helpers to build employment data from workplace definitions or from a DynamicBuffer (ECS). It is intended for use in UI contexts (e.g., charts and info panels) to present employment distributions in Cities: Skylines 2 mods.


Fields

  • None (all data exposed via readonly auto-properties)
    This struct uses read-only auto-implemented properties; there are no explicit user-declared fields.

Properties

  • public int uneducated { get; }
    Count of uneducated-level workers/employees (education level 0).

  • public int poorlyEducated { get; }
    Count of poorly educated workers/employees (education level 1).

  • public int educated { get; }
    Count of educated workers/employees (education level 2).

  • public int wellEducated { get; }
    Count of well-educated workers/employees (education level 3).

  • public int highlyEducated { get; }
    Count of highly educated workers/employees (education level 4).

  • public int openPositions { get; }
    Number of currently open positions at the workplace(s).

  • public int total { get; }
    Total of all counts (sum of the five education-level counts plus openPositions). Computed in the constructor.

Constructors

  • public EmploymentData(int uneducated, int poorlyEducated, int educated, int wellEducated, int highlyEducated, int openPositions)
    Constructs a new EmploymentData instance with the provided counts and calculates the total property as the sum of the five education counts plus openPositions.

Methods

  • public static EmploymentData operator +(EmploymentData left, EmploymentData right)
    Returns a new EmploymentData whose counts are the component-wise sums of left and right. Useful for aggregating employment data across multiple buildings/areas.

  • public void Write(IJsonWriter writer)
    Implements IJsonWritable. Emits a JSON object with:

  • Type begin "selectedInfo.ChartData"
  • Property "values" : array of 6 integers in this order: uneducated, poorlyEducated, educated, wellEducated, highlyEducated, openPositions
  • Property "total" : total This format is suitable for the game's UI chart data.

  • public static EmploymentData GetWorkplacesData(int maxWorkers, int buildingLevel, WorkplaceComplexity complexity)
    Creates EmploymentData for a workplace by calling EconomyUtils.CalculateNumberOfWorkplaces(maxWorkers, complexity, buildingLevel), then mapping the returned Workplaces counts into the education-level properties. openPositions is set to 0 in this factory. Use this when you have workplace configuration (max workers, building level, and complexity) and need the distribution of workplace slots.

  • public static EmploymentData GetEmployeesData(DynamicBuffer<Employee> employees, int openPositions)
    Creates EmploymentData by iterating the supplied DynamicBuffer (Unity.Entities) and counting employees by their m_Level (0..4). The provided openPositions value is used for the openPositions property. Use this when you want to build current employee counts from an entity's employee buffer.

Notes and details: - The method GetEmployeesData interprets Employee.m_Level numeric values as education levels 0..4 (matching the property order). - The struct is readonly and immutable once constructed. - Dependencies/imports used in the original source: Colossal.UI.Binding, Game.Companies, Game.Economy, Game.Prefabs, Unity.Entities.

Usage Example

// Constructing directly
var dataA = new EmploymentData(10, 5, 8, 3, 1, 2);
var dataB = new EmploymentData(4, 2, 1, 0, 0, 1);

// Aggregating
var totalData = dataA + dataB; // component-wise sum

// Creating from workplace definition
WorkplaceComplexity complexity = WorkplaceComplexity.Medium;
int maxWorkers = 50;
int buildingLevel = 2;
var workplaceData = EmploymentData.GetWorkplacesData(maxWorkers, buildingLevel, complexity);

// Creating from employees buffer (ECS)
DynamicBuffer<Employee> employees = /* fetched from an entity */;
int openPositions = 5;
var employeesData = EmploymentData.GetEmployeesData(employees, openPositions);

// Writing to a JSON writer (IJsonWriter provided by the game's UI/serialization)
IJsonWriter writer = /* obtained from calling context */;
totalData.Write(writer);