Game.Simulation.ZoneAmbiences
Assembly:
Assembly-CSharp
Namespace:
Game.Simulation
Type:
struct
Base:
System.ValueType
Implements: Colossal.Serialization.Entities.IStrideSerializable, Colossal.Serialization.Entities.ISerializable
Summary:
Represents a collection of ambient sound/ambience weights for different zone group types used by the simulation (residential/commercial/industrial subclasses, forestry, waterfront, seagulls, etc.). Each field is a float weight that can be queried, accumulated, combined or serialized. The struct provides convenience methods to get or add ambience by GroupAmbienceType, arithmetic operators (+ and /) for combining and averaging, and serialization logic that is version- and format-aware.
Fields
-
public float m_ResidentialLow
Holds the ambient weight for low residential zones. -
public float m_CommercialLow
Holds the ambient weight for low commercial zones. -
public float m_Industrial
Holds the ambient weight for industrial zones. -
public float m_Agriculture
Holds the ambient weight for agriculture zones. -
public float m_Forestry
Holds the ambient weight for forestry-related zones. -
public float m_Oil
Holds the ambient weight for oil industry zones. -
public float m_Ore
Holds the ambient weight for ore/mining zones. -
public float m_OfficeLow
Holds the ambient weight for low office zones. -
public float m_OfficeHigh
Holds the ambient weight for high office zones. -
public float m_ResidentialMedium
Holds the ambient weight for medium-density residential zones. -
public float m_ResidentialHigh
Holds the ambient weight for high-density residential zones. -
public float m_ResidentialMixed
Holds the ambient weight for mixed residential zones. -
public float m_CommercialHigh
Holds the ambient weight for high commercial zones. -
public float m_ResidentialLowRent
Holds the ambient weight for low-rent residential zones. -
public float m_Forest
Holds ambient weight contributed by forest tiles/areas. Note: older save formats are corrected during deserialization (see Deserialize). -
public float m_WaterfrontLow
Holds ambient weight for low waterfront zones (added in a later format/version). -
public float m_AquacultureLand
Holds ambient weight for aquaculture land (present only when format tag AquacultureLandAmbience is set). -
public float m_SeagullAmbience
Holds seagull-specific ambience weight (present only when format tag SeagullAmbience is set).
Properties
- None. All data are public fields and accessed directly or via the provided methods.
Constructors
public ZoneAmbiences()
Default value-type constructor (implicit). All fields default to 0f. No custom initialization exists in the source.
Methods
public float GetAmbience(GroupAmbienceType type)
Returns the float ambience value corresponding to the specified GroupAmbienceType. If the type is not represented (or is an ignored type such as Traffic/Rain/NightForest), returns 0f.
Behavior highlights: - Uses a C# switch expression to map GroupAmbienceType to the corresponding field. - Supported types include ResidentialLow, CommercialLow, Industrial, Agriculture, Forestry, Oil, Ore, OfficeLow, OfficeHigh, ResidentialMedium, ResidentialHigh, ResidentialMixed, CommercialHigh, ResidentialLowRent, Forest, WaterfrontLow, AquacultureLand, and SeagullAmbience.
public void AddAmbience(GroupAmbienceType type, float value)
Adds (increments) the float value to the field corresponding to the provided GroupAmbienceType. Several ambient types are intentionally ignored (Traffic, Rain, NightForest) — in those cases the method is a no-op.
Notes: - Useful for accumulating ambience contributions when iterating over tiles/objects. - Direct field modification is also possible since fields are public.
-
public static ZoneAmbiences operator +(ZoneAmbiences a, ZoneAmbiences b)
Returns a new ZoneAmbiences whose fields are the element-wise sums of a and b. Useful to combine ambience contributions from multiple sources. -
public static ZoneAmbiences operator /(ZoneAmbiences a, float b)
Returns a new ZoneAmbiences whose fields are each divided by b. Useful for averaging (e.g., divide summed ambience by count). -
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the struct's float fields to the provided writer. The order of writes is important for compatibility with saved data and older formats.
Important details: - The serialization order in source: m_ResidentialLow, m_CommercialHigh, m_Industrial, m_Agriculture, m_Forestry, m_Oil, m_Ore, m_OfficeLow, m_OfficeHigh, m_ResidentialMedium, m_ResidentialHigh, m_ResidentialMixed, m_CommercialHigh (written a second time), m_ResidentialLowRent, m_Forest, m_WaterfrontLow, m_AquacultureLand, m_SeagullAmbience. - Note: m_CommercialHigh is written twice (positions 2 and 13 in the write sequence) — this reflects the source implementation and is likely important for compatibility with specific reader implementations or historic layouts.
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads float values from reader into the struct fields while respecting reader.context.version and reader.context.format flags. Handles compatibility with older save formats.
Compatibility & logic highlights: - The initial reads map into m_ResidentialLow, m_CommercialHigh, m_Industrial, m_Agriculture, m_Forestry, m_Oil, m_Ore. - If reader.context.version is not greater than Version.zoneAmbience, the method returns early (older format: only those initial values are present). - Later reads populate office/medium/high/mixed/commercialHigh/residentialLowRent when the version is newer. - Forest and waterfront fields are read only when version exceeds Version.forestAmbience and Version.waterfrontAmbience respectively. - For very old versions (reader.context.version < Version.forestAmbientFix), m_Forest is scaled by 0.0625f to apply a legacy fix. - aquaculture and seagull fields are read only when the context.format contains FormatTags.AquacultureLandAmbience and FormatTags.SeagullAmbience respectively. - Because of duplicated writes in Serialize, Deserialize reads m_CommercialHigh twice (the second read maps to the same field), mirroring the serialized layout.
public int GetStride(Context context)
Implements IStrideSerializable. Returns the stride/size in bytes when the struct is used in stride/packed buffers. The source returns 72, which corresponds to 18 floats × 4 bytes each.
Usage Example
// Create and accumulate ambience values
ZoneAmbiences total = new ZoneAmbiences();
ZoneAmbiences cell = new ZoneAmbiences();
// add some contributions (direct field access or AddAmbience)
cell.m_ResidentialLow += 1.2f;
cell.AddAmbience(GroupAmbienceType.Forest, 0.5f);
// combine into totals
total += cell;
// average across N samples
int samples = 4;
ZoneAmbiences average = total / (float)samples;
// query a specific ambience
float forestAmbience = average.GetAmbience(GroupAmbienceType.Forest);
Notes and tips for modders: - Fields are public for direct access, but using GetAmbience / AddAmbience helps keep logic consistent with GroupAmbienceType enum mapping. - Be mindful of serialization compatibility — Deserialize has version- and format-based branching and applies a legacy scaling fix for forest ambience. - The struct is small (72 bytes stride) and intended to be used in aggregation over many tiles/objects; prefer struct operations (operator + and /) for efficient combining and averaging.