Skip to content

Game.Companies.ServiceCompanyData

Assembly: Assembly-CSharp (game code / modding assembly)
Namespace: Game.Companies

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
ServiceCompanyData is a plain data component used by the game's ECS to describe service-company parameters (how much service a company provides, how many workers it needs, worker density per cell, and an optional service-consuming value). It implements Unity.Entities.IComponentData so it can be attached to entities, IQueryTypeParameter for use in entity queries, and ISerializable to participate in the game's serialization system. The Deserialize method contains a version check so older saves remain compatible with the optional m_ServiceConsuming field.


Fields

  • public int m_MaxService
    This is the maximum service amount (capacity) provided by the company/entity. Used by game logic to cap the total service output.

  • public int m_WorkPerUnit
    Number of workers required per unit of service (worker consumption per provided service unit). Affects workforce calculations for the service company.

  • public float m_MaxWorkersPerCell
    Maximum number of workers allowed per map cell for this company type. Expressed as a float to allow fractional densities if the simulation uses them.

  • public int m_ServiceConsuming
    Optional/extended field that indicates how much service is consumed (or an alternative consumption parameter). This field is only read from saves when the reader's context version is at or above Version.serviceCompanyConsuming — it was added later to preserve backward compatibility.

Properties

  • None. This struct exposes only public fields and no C# properties.

Constructors

  • public ServiceCompanyData()
    Implicit default constructor (value-type). Initializes numeric fields to their default values (0 for ints, 0f for float). Typical usage is to assign field values after construction.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the struct fields to the provided writer in the following order: m_MaxService, m_WorkPerUnit, m_MaxWorkersPerCell, m_ServiceConsuming. Used by the game's save/serialization pipeline (Colossal.Serialization). All fields are written unconditionally.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads values back into the struct fields from the provided reader in the same order. The method reads m_MaxService, m_WorkPerUnit, and m_MaxWorkersPerCell unconditionally. The m_ServiceConsuming field is only read if reader.context.version >= Version.serviceCompanyConsuming to maintain compatibility with older save versions that do not include this field.

Notes: - reader.context.version refers to the serialization/versioning context used by the game's persistence system. Version.serviceCompanyConsuming is a version constant that marks when m_ServiceConsuming was introduced. - Uses ref locals to pass fields to reader.Read, matching the code pattern expected by the serialization API.

Usage Example

// Example: creating and populating the component, then (conceptually) serializing it.
// Actual serialization requires a proper IWriter implementation from the game's save system.

using Game.Companies;
using Colossal.Serialization.Entities;

public void ExampleUsage(IWriter writer)
{
    var data = new ServiceCompanyData
    {
        m_MaxService = 1200,
        m_WorkPerUnit = 4,
        m_MaxWorkersPerCell = 2.5f,
        m_ServiceConsuming = 1
    };

    // Serialize to writer (provided by the game's serialization pipeline)
    data.Serialize(writer);
}

// Example deserialization (requires an IReader from the game's load pipeline)
public void ExampleRead(IReader reader)
{
    var data = new ServiceCompanyData();
    data.Deserialize(reader);
    // Now data contains the values from the save, with m_ServiceConsuming only populated
    // if the save version supports it.
}