Game.Simulation.EventHelpers
Assembly: Game
Namespace: Game.Simulation
Type: static class
Base: none
Summary:
EventHelpers is a static container for small data/utility structs used by simulation systems to compute fire-related event data and building structural integrity. It provides two primary helper types:
- FireHazardData — contains lookups and runtime parameters used to compute fire hazard and risk for buildings and trees.
- StructuralIntegrityData — provides structural integrity values for prefabs (buildings / destructible objects) based on configuration and prefab data.
These helpers are intended to be constructed/updated from a SystemBase so they can obtain and refresh ComponentLookup/BufferLookup state for burst-friendly access in Jobs or deterministic simulation code.
Fields
- No top-level fields on Game.Simulation.EventHelpers. See nested structs below for the data members.
FireHazardData
Summary:
Holds lookup handles and runtime modifiers required to compute fire hazard and risk for buildings and trees. It caches ComponentLookup/BufferLookup instances (read-only) and exposes methods to update them and evaluate hazard values taking into account prefab data, services, district modifiers, local effects, damaged state and fire configuration.
Fields
-
public LocalEffectSystem.ReadData m_LocalEffectData
Local effect read data used to apply position-based modifiers (e.g., local forest-fire hazard / response-time modifiers). -
public float m_ForestFireHazardFactor
A multiplier applied to tree fire hazard based on environment (temperature, dry days) from FireConfigurationPrefab curve evaluation. -
public ComponentLookup<DestructibleObjectData> m_PrefabDestructibleObjectData
Component lookup for destructible object prefab data (read-only). Used to read prefab-level m_FireHazard and m_StructuralIntegrity for non-building objects. -
public ComponentLookup<SpawnableBuildingData> m_PrefabSpawnableBuildingData
Component lookup for spawnable building prefab data (read-only). Used to get building level, zone prefab, etc. -
public BufferLookup<Game.Net.ServiceCoverage> m_ServiceCoverages
Buffer lookup for road-edge service coverage buffers (read-only). Used to query fire/rescue coverage and reduce fire hazard. -
public BufferLookup<DistrictModifier> m_DistrictModifiers
Buffer lookup for district modifiers (read-only). Used to apply district-level modifiers such as BuildingFireHazard. -
public ComponentLookup<ZonePropertiesData> m_ZonePropertiesData
Component lookup for zone property prefabs (read-only). Used to apply zone-specific fire hazard multipliers.
Properties
- None (no C# properties other than fields).
Constructors
public FireHazardData(SystemBase system)
Initializes the FireHazardData instance by obtaining read-only ComponentLookup/BufferLookup references from the provided SystemBase. m_LocalEffectData and m_ForestFireHazardFactor are initialized to defaults; lookups are created but must be updated before use.
Notes: - Use GetComponentLookup/GetBufferLookup on the passed system to obtain lookups with isReadOnly: true.
Methods
-
public void Update(SystemBase system, LocalEffectSystem.ReadData localEffectData, FireConfigurationPrefab fireConfigurationPrefab, float temperature, float noRainDays)
Refreshes all ComponentLookup/BufferLookup instances against the current SystemBase state, updates m_LocalEffectData, and evaluates m_ForestFireHazardFactor by sampling curves on the provided FireConfigurationPrefab using temperature and number of dry days. Must be called each frame (or before use in jobs) to ensure lookups are valid. -
public bool GetFireHazard(PrefabRef prefabRef, Building building, CurrentDistrict currentDistrict, Damaged damaged, UnderConstruction underConstruction, out float fireHazard, out float riskFactor)
Computes fire hazard and risk for a building instance: - Starts from prefab-level fire hazard (from DestructibleObjectData or default).
- If building is under construction and uses a new prefab but not fully built, hazard may be set to 0.
- Applies building-level modifiers: spawnable building level (slight reduction by level), zone fire hazard multiplier if available.
- Applies service coverage reduction using the building's road edge buffer (CoverageService.FireRescue). A minimum multiplier of 0.01 is enforced.
- Applies district modifiers of type BuildingFireHazard.
- Computes riskFactor as hazard divided by (1 + serviceCoverage * 0.5).
- Applies damage-based multiplier (GetFireHazardFactor) to final hazard.
-
Returns true if hazard > 0 (i.e., meaningful for simulation), otherwise false.
-
public bool GetFireHazard(PrefabRef prefabRef, Tree tree, Transform transform, Damaged damaged, out float fireHazard, out float riskFactor)
Computes fire hazard and risk for a tree: - Starts from prefab-level fire hazard.
- Multiplies by m_ForestFireHazardFactor (set from FireConfigurationPrefab curves).
- Applies local modifiers (m_LocalEffectData) at the tree position for ForestFireHazard and ForestFireResponseTime.
- Sets riskFactor to the (possibly modified) hazard after applying the local forest response-time modifier.
- Applies damage-based multiplier (GetFireHazardFactor).
-
Returns true if hazard > 0, otherwise false.
-
private float GetFireHazard(PrefabRef prefabRef)
Helper that returns the base fire hazard for a prefab: - If the prefab has DestructibleObjectData, returns its m_FireHazard.
-
Otherwise returns a default of 100f.
-
private float GetFireHazardFactor(Damaged damaged)
Computes a multiplicative factor (0..1) based on the damaged component: - Uses the damage vector components y and z: num = max(0, 1 - sum(damaged.m_Damage.yz)).
- Squares num twice (num2 = numnum; return num2num2) producing a fourth-power falloff so partially damaged objects have much lower hazard contribution.
Usage Example
// In a SystemBase:
private EventHelpers.FireHazardData m_FireHazardData;
protected override void OnCreate()
{
base.OnCreate();
m_FireHazardData = new EventHelpers.FireHazardData(this);
}
protected override void OnUpdate()
{
// Assume we have LocalEffectSystem.ReadData localEffectData, FireConfigurationPrefab fireConfigPrefab,
// float temperature and float noRainDays from simulation state:
m_FireHazardData.Update(this, localEffectData, fireConfigPrefab, temperature, noRainDays);
// Use m_FireHazardData.GetFireHazard(...) inside jobs or main thread to evaluate hazard for buildings/trees.
}
StructuralIntegrityData
Summary:
Provides methods to get structural integrity values for a prefab, using either explicit DestructibleObjectData on the prefab or fallbacks for buildings based on spawnable building level and global fire configuration values.
Fields
-
public ComponentLookup<SpawnableBuildingData> m_PrefabSpawnableBuildingData
Read-only lookup for spawnable building prefab data (used to read building level and zone prefab). -
public ComponentLookup<DestructibleObjectData> m_PrefabDestructibleObjectData
Read-only lookup for destructible object prefab data (used when prefabs explicitly define structural integrity). -
public FireConfigurationData m_FireConfigurationData
Cached FireConfigurationData values (struct) containing default structural integrity values and per-level building structural integrity values.
Properties
- None.
Constructors
public StructuralIntegrityData(SystemBase system)
Initializes component lookups for SpawnableBuildingData and DestructibleObjectData (read-only). m_FireConfigurationData is initialized to default and should be set via Update before use.
Methods
-
public void Update(SystemBase system, FireConfigurationData fireConfigurationData)
Updates lookup instances against the current SystemBase and caches the provided FireConfigurationData for later queries. -
public float GetStructuralIntegrity(Entity prefab, bool isBuilding)
Returns the structural integrity for the given prefab: - If DestructibleObjectData exists on the prefab, returns its m_StructuralIntegrity.
- If isBuilding is true and a SpawnableBuildingData entry exists, returns a level-specific structural integrity value using the building level (levels 1–5 map to specific fields in FireConfigurationData; default fallback to m_BuildingStructuralIntegrity).
- If isBuilding is false, returns m_DefaultStructuralIntegrity from FireConfigurationData.
- If no specific data exists for a building prefab, falls back to m_BuildingStructuralIntegrity.
Usage Example
// In a SystemBase:
private EventHelpers.StructuralIntegrityData m_StructuralIntegrityData;
protected override void OnCreate()
{
base.OnCreate();
m_StructuralIntegrityData = new EventHelpers.StructuralIntegrityData(this);
}
protected override void OnUpdate()
{
// Assume fireConfigurationData is obtained from simulation settings:
m_StructuralIntegrityData.Update(this, fireConfigurationData);
// Query for a prefab:
float integrity = m_StructuralIntegrityData.GetStructuralIntegrity(prefabEntity, isBuilding: true);
// Use integrity in damage / collapse calculations.
}
Notes and Modding Tips
- Always call Update(...) on these helper structs each frame (or before scheduling jobs that will use them). ComponentLookup/BufferLookup must be refreshed against the current SystemBase to be valid in the current frame.
- The FireHazardData methods return a boolean indicating whether the computed hazard is meaningful (false when base hazard is zero). Check return value before using output hazard/risk.
- Fire hazard and structural integrity combine prefab-declared values and global configuration (FireConfigurationPrefab/Data). When modding prefabs, provide DestructibleObjectData or SpawnableBuildingData to control results instead of relying on defaults.
- Damage-based scaling uses a strong fourth-power falloff; small amounts of remaining health produce disproportionately small hazard contribution. If you want different behavior, adjust calculations in your own helper or override data on prefabs.
- LocalEffectSystem.ReadData is used to apply position-based modifiers — ensure you supply proper local effect read data from the LocalEffectSystem when evaluating forest-fire hazard for trees.