Skip to content

Game.Companies.Workplaces

Assembly: Assembly-CSharp
Namespace: Game.Companies

Type: struct

Base: System.ValueType, IAccumulable, ISerializable

Summary: Workplaces is a small value-type container that tracks counts of company workplaces by education level. It provides convenience properties for totals and simple/complex workplace categories, supports indexed access (0..4) per education tier, can copy its values into a NativeArray, can accumulate counts from another Workplaces instance, and supports serialization/deserialization via the Colossal.Serialization entities (IWriter / IReader). This is used by the companies system to aggregate and persist workplace distributions.


Fields

  • public int m_Uneducated
    Count of workplaces requiring uneducated workers (education level index 0).

  • public int m_PoorlyEducated
    Count of workplaces requiring poorly educated workers (education level index 1).

  • public int m_Educated
    Count of workplaces requiring educated workers (education level index 2).

  • public int m_WellEducated
    Count of workplaces requiring well-educated workers (education level index 3).

  • public int m_HighlyEducated
    Count of workplaces requiring highly educated workers (education level index 4).

Properties

  • public int TotalCount { get; }
    Returns the sum of all five education-level workplace counts (m_Uneducated + m_PoorlyEducated + m_Educated + m_WellEducated + m_HighlyEducated).

  • public int SimpleWorkplacesCount { get; }
    Returns the number of "simple" workplaces = m_Uneducated + m_PoorlyEducated (education indices 0 and 1).

  • public int ComplexWorkplacesCount { get; }
    Returns the number of "complex" workplaces = m_Educated + m_WellEducated + m_HighlyEducated (education indices 2..4).

  • public int this[int index] { get; set; }
    Indexer providing get/set access by education-level index:

  • 0 -> m_Uneducated
  • 1 -> m_PoorlyEducated
  • 2 -> m_Educated
  • 3 -> m_WellEducated
  • 4 -> m_HighlyEducated
    Throws IndexOutOfRangeException for indexes outside 0..4.

Constructors

  • public Workplaces() (implicit default)
    No explicit constructor is defined; the default parameterless struct constructor zero-initializes all fields. Instantiate with new Workplaces() or default(Workplaces).

Methods

  • public void ToArray(NativeArray<int> array)
    Copies the five counts into the provided NativeArray at indices 0..4 in the same order: uneducated, poorly educated, educated, well educated, highly educated. The caller is responsible for providing an array of sufficient length.

  • public void Accumulate(Workplaces other)
    Adds the counts from another Workplaces instance into this instance, component-wise (m_Uneducated += other.m_Uneducated, etc.). Implements the IAccumulable contract.

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the five integer counts to the provided writer in the order: uneducated, poorly educated, educated, well educated, highly educated. Used for persistence.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads five integers from the provided reader and assigns them to the fields in the same order. Used to restore saved state.

Usage Example

// Create and initialize
Workplaces wp = new Workplaces();
wp[0] = 10; // uneducated
wp[1] = 5;  // poorly educated
wp[2] = 8;  // educated
wp[3] = 3;  // well educated
wp[4] = 1;  // highly educated

// Accumulate another Workplaces
Workplaces other = new Workplaces();
other[0] = 2;
other[2] = 4;
wp.Accumulate(other); // wp counts are incremented

// Copy to a NativeArray<int> (length must be >= 5)
using (var arr = new Unity.Collections.NativeArray<int>(5, Unity.CollectionsAllocator.Temp))
{
    wp.ToArray(arr);
    // arr[0]..arr[4] now contain the workplace counts
}

// Serialization (pseudo-code; uses game's IWriter/IReader implementations)
// writer could be a game save writer
// wp.Serialize(writer);
// and later
// wp.Deserialize(reader);

If you need, I can also provide a small helper to convert between Workplaces and common collections (e.g., int[]), or a safe accessor that returns 0 for out-of-range indices instead of throwing.