Skip to content

Game.Citizens.CitizenSelectedSoundData

Assembly: (assembly not specified in source; defined in game codebase — search for the Game. assembly that contains Game.Citizens)
Namespace:* Game.Citizens

Type: struct (value type)

Base: System.ValueType, implements Unity.Entities.IBufferElementData, System.IEquatable

Summary:
Represents a buffer element used to store which sound Entity should be played for a selected citizen given their state. The struct contains the citizen's sickness/injury flag, age, happiness and the Entity reference for the selected sound. Marked with InternalBufferCapacity(0) meaning it is a dynamic (overflow) buffer element with no static inline capacity.


Fields

  • public bool m_IsSickOrInjured
    Whether the citizen is sick or injured. This flag alters equality behavior: when true, happiness is not considered when comparing two instances.

  • public CitizenAge m_Age
    CitizenAge (likely an enum elsewhere in the codebase) indicating the age group of the citizen.

  • public CitizenHappiness m_Happiness
    CitizenHappiness (likely an enum elsewhere in the codebase) indicating the happiness state of the citizen.

  • public Entity m_SelectedSound
    A Unity.Entities.Entity that references the sound prefab/asset to be played for this citizen selection state.

Properties

  • This type has no properties; it exposes all data via public fields.

Constructors

  • public CitizenSelectedSoundData(bool isSickOrInjured, CitizenAge age, CitizenHappiness happiness, Entity selectedSound)
    Constructs an instance, initializing the sickness/injury flag, age, happiness and the selected sound entity.

Methods

  • public bool Equals(CitizenSelectedSoundData other)
    Equality comparison implementing IEquatable. Logic:
  • First compares m_IsSickOrInjured and m_Age; if either differs, returns false.
  • If m_IsSickOrInjured is false (i.e., citizen not sick/injured), also requires m_Happiness to be equal.
  • If m_IsSickOrInjured is true, happiness is ignored and instances with the same m_IsSickOrInjured and m_Age are considered equal regardless of m_Happiness.

Note: This conditional equality is intentional for comparing selection keys based on citizen state, but see the GetHashCode note below.

  • public override int GetHashCode()
    Returns the hash code produced from the tuple (m_IsSickOrInjured, m_Age, m_Happiness). Important: this hash code includes m_Happiness even though Equals ignores m_Happiness when m_IsSickOrInjured is true. That creates a potential equality/hashcode contract violation — objects considered equal by Equals might produce different hash codes. If this type is used as a key in hash-based collections, this mismatch can cause bugs; consider adjusting GetHashCode to match Equals semantics (e.g., ignore m_Happiness when m_IsSickOrInjured is true).

Usage Example

// Example of creating and adding this buffer element to an entity's dynamic buffer.
// Requires using Unity.Entities and that the entity has a DynamicBuffer<CitizenSelectedSoundData>.

var data = new CitizenSelectedSoundData(
    isSickOrInjured: false,
    age: CitizenAge.Adult,             // example enum value
    happiness: CitizenHappiness.Happy, // example enum value
    selectedSound: soundEntity         // an Entity referencing the sound prefab/asset
);

// In a system where 'entity' has the buffer:
var buffer = EntityManager.GetBuffer<CitizenSelectedSoundData>(entity);
buffer.Add(data);

// When comparing two entries, be aware:
// - If m_IsSickOrInjured == true, equality ignores m_Happiness.
// - If m_IsSickOrInjured == false, equality requires m_Happiness to match.

Additional notes: - The struct is intended to be used as an IBufferElementData in Unity DOTS (ECS) code for Cities: Skylines 2 modding. - CitizenAge and CitizenHappiness are types defined elsewhere in the game's code; treat them as enum-like keys for selecting the appropriate sound. - Pay attention to the Equals/GetHashCode inconsistency if you plan to use instances in hash-based collections — consider updating GetHashCode to reflect the same fields used by Equals.