Skip to content

Game.Prefabs.WorkplaceData

Assembly: (likely Assembly-CSharp / Game)
Namespace: Game.Prefabs

Type: struct

Base: IComponentData, IQueryTypeParameter, ICombineData, ISerializable

Summary:
Represents workplace-related configuration data for a prefab in the ECS world. Contains complexity/tier, worker counts, and shift probabilities. Implemented as a value-type component that can be combined with other WorkplaceData instances (for example when merging prefab data) and serialized/deserialized for save/load and entity streaming. Note: the struct serializes complexity as a byte and conditionally reads/writes the minimum-workers-limit field depending on the saved-version.


Fields

  • public WorkplaceComplexity m_Complexity
    Represents the workplace complexity/tier (enum). Serialized as a byte.

  • public int m_MaxWorkers
    Maximum number of workers for the workplace. Used as a weight when combining shift probabilities from multiple data sources.

  • public float m_EveningShiftProbability
    Probability (0..1) that workers will take the evening shift. Combined using a weighted linear interpolation when merging data.

  • public float m_NightShiftProbability
    Probability (0..1) that workers will take the night shift. Combined using a weighted linear interpolation when merging data.

  • public int m_MinimumWorkersLimit
    A minimum-workers limit introduced in a later version. Only read from the serialized stream when the reader context version is newer than Version.addMinimumWorkersLimit.

Properties

  • (none)
    This struct exposes no properties; all data is via public fields.

Constructors

  • public WorkplaceData() (implicit default)
    No explicit constructors are declared. As a struct, WorkplaceData can be created with default values or with field initializers.

Methods

  • public void Combine(WorkplaceData other)
    Merges another WorkplaceData instance into this one. Behavior in source:
  • Stores the current m_MaxWorkers in a local maxWorkers.
  • Adds other.m_MaxWorkers into this.m_MaxWorkers.
  • Attempts to add minimum worker limits, but the current implementation contains a bug: it does m_MinimumWorkersLimit += m_MinimumWorkersLimit; which doubles the current value instead of adding other.m_MinimumWorkersLimit. It should be m_MinimumWorkersLimit += other.m_MinimumWorkersLimit;.
  • Blends evening and night shift probabilities using math.lerp with weight (maxWorkers / m_MaxWorkers), so the existing probabilities are weighted by the previous maxWorkers and the other's by the newly added workers. Example weight calculation: if this had 10 workers and other has 30, the lerp uses 10 / 40 = 0.25 to bias toward the other's values accordingly.

Recommended fix for the minimum-workers bug: - Replace m_MinimumWorkersLimit += m_MinimumWorkersLimit; with m_MinimumWorkersLimit += other.m_MinimumWorkersLimit;.

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the struct to the provided writer in this order:
  • m_MaxWorkers (int)
  • m_EveningShiftProbability (float)
  • m_NightShiftProbability (float)
  • m_Complexity as a byte
  • m_MinimumWorkersLimit (int)

Note: complexity is cast to byte for compact storage.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the struct from the provided reader in the same order as Serialize:
  • Reads m_MaxWorkers
  • Reads m_EveningShiftProbability
  • Reads m_NightShiftProbability
  • Reads a byte and casts it to WorkplaceComplexity for m_Complexity
  • Conditionally reads m_MinimumWorkersLimit only if reader.context.version > Version.addMinimumWorkersLimit

The version check ensures backward compatibility with saves that predate the minimum-workers-limit addition.

Usage Example

// Create two workplace data entries and combine them.
// NOTE: The original Combine implementation contains a bug for m_MinimumWorkersLimit;
// this example shows correct combining to avoid that bug.

WorkplaceData a = new WorkplaceData {
    m_Complexity = WorkplaceComplexity.Small,
    m_MaxWorkers = 10,
    m_EveningShiftProbability = 0.2f,
    m_NightShiftProbability = 0.1f,
    m_MinimumWorkersLimit = 1
};

WorkplaceData b = new WorkplaceData {
    m_Complexity = WorkplaceComplexity.Medium,
    m_MaxWorkers = 30,
    m_EveningShiftProbability = 0.6f,
    m_NightShiftProbability = 0.4f,
    m_MinimumWorkersLimit = 2
};

// Correct combine logic (fixed minimum-workers line)
int originalMax = a.m_MaxWorkers;
a.m_MaxWorkers += b.m_MaxWorkers;
a.m_MinimumWorkersLimit += b.m_MinimumWorkersLimit; // fixed
a.m_EveningShiftProbability = math.lerp(b.m_EveningShiftProbability, a.m_EveningShiftProbability, originalMax / (float)a.m_MaxWorkers);
a.m_NightShiftProbability = math.lerp(b.m_NightShiftProbability, a.m_NightShiftProbability, originalMax / (float)a.m_MaxWorkers);

If you plan to rely on Combine in the game's code path, consider auditing or patching the m_MinimumWorkersLimit line to ensure correct accumulation. Also be mindful of the conditional deserialization of m_MinimumWorkersLimit when working with older save versions.