Game.WeatherDamageSystem
Assembly: Assembly-CSharp
Namespace: Game.Simulation
Type: public class
Base: GameSystemBase
Summary:
WeatherDamageSystem is a game simulation system that processes entities with the FacingWeather component and applies weather-related damage to objects (typically buildings). It schedules a Burst-compiled IJobChunk (WeatherDamageJob) to run in parallel over chunks of entities, calculates severity using WeatherPhenomenon data and prefab-specific WeatherPhenomenonData, factors in object structural integrity and city modifiers, and produces Damage or Destroy events as appropriate. The system also manages icon notifications via IconCommandSystem and defers structural changes through an EndFrameBarrier command buffer. It runs at a fixed update interval (64 ticks) and requires relevant configuration singletons (FireConfigurationData, DisasterConfigurationData) to operate.
Fields
-
private const uint UPDATE_INTERVAL = 64u
Controls the update frequency of the system (returned by GetUpdateInterval). The system updates every 64 ticks. -
private IconCommandSystem m_IconCommandSystem
Reference to the IconCommandSystem used to enqueue icon notifications and removals related to weather damage. -
private CitySystem m_CitySystem
Reference to the CitySystem used to obtain the city entity and city-specific modifiers. -
private EndFrameBarrier m_EndFrameBarrier
Barrier system used to create an EntityCommandBuffer.ParallelWriter to create Damage/Destroy event entities and remove components safely at end of frame. -
private EntityQuery m_FacingQuery
Query used to find entities with FacingWeather (and excluding Deleted/Temp) — the primary query that drives updates. -
private EntityQuery m_FireConfigQuery
Query to obtain FireConfigurationData singleton used to update structural integrity data. -
private EntityQuery m_DisasterConfigQuery
Query to obtain DisasterConfigurationData singleton used for notification prefabs and other disaster config. -
private EntityArchetype m_DamageEventArchetype
Archetype used when creating Damage event entities. -
private EntityArchetype m_DestroyEventArchetype
Archetype used when creating Destroy event entities. -
private EventHelpers.StructuralIntegrityData m_StructuralIntegrityData
Helper data for querying and computing structural integrity of prefabs (used to scale damage). -
private TypeHandle __TypeHandle
Generated helper holding various Entity/Component type handles and lookups used when scheduling the job.
Properties
- This type does not expose public properties.
Constructors
public WeatherDamageSystem()
Default constructor (preserved). Initialization of runtime fields is done in OnCreate.
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
Returns 64 — this system runs every 64 ticks (value provided by UPDATE_INTERVAL). Used by the scheduling framework. -
[Preserve] protected override void OnCreate()
Registers required queries, retrieves/creates references to other systems (IconCommandSystem, CitySystem, EndFrameBarrier), constructs event archetypes, and initializes the StructuralIntegrityData helper. Also calls RequireForUpdate for the queries needed for the system to run (FacingWeather, FireConfigurationData, DisasterConfigurationData). -
[Preserve] protected override void OnUpdate()
Main update method. Reads FireConfigurationData and DisasterConfigurationData singletons, updates the structural integrity helper, then schedules the Burst-compiled WeatherDamageJob in parallel across the m_FacingQuery. It supplies component lookups/type handles and command buffers (EndFrameBarrier and IconCommandSystem). The produced JobHandle is registered with IconCommandSystem and EndFrameBarrier, and assigned back to base.Dependency. -
private void __AssignQueries(ref SystemState state)
Compiler-generated helper for certain query assignments used when compiling. No meaningful runtime logic beyond internal setup. -
protected override void OnCreateForCompiler()
Compiler helper invoked to assign handles and queries for the generated TypeHandle structure. -
Inner type:
WeatherDamageJob : IJobChunk
(Burst compiled) - Iterates entities in chunks that match the m_FacingQuery (entities with FacingWeather).
- For each entity: reads PrefabRef, Transform, FacingWeather, (and optional Damaged/Building/Destroyed flags), computes the current severity using EventUtils.GetSeverity (if the referenced weather event entity still exists and has WeatherPhenomenon data).
- Converts severity into damage factor by dividing by prefab structural integrity and clamping / scaling (includes a multiplier and caps). If structural integrity is effectively infinite, it skips damage.
- Applies city disaster damage rate modifiers (if applicable).
- If the target has a Damaged buffer/component, it increments the damage and, if total damage reaches 1.0, creates a Destroy event entity and enqueues removal/addition of icons (destroy notification). If the target doesn't track accumulated damage, it creates a Damage event entity with the damage delta.
- Adds or removes weather-damage-specific icon notifications depending on whether severity > 0.
- Removes FacingWeather component when severity drops to 0 (via command buffer).
- Uses EntityCommandBuffer.ParallelWriter for entity creation and removal and an IconCommandBuffer for icon operations.
- The job uses a number of component lookups and component type handles (PrefabRef, Building, Transform, Destroyed, Damaged, WeatherPhenomenon data, etc.) provided by the outer system.
Notes: - The job is Burst-compiled and works on chunked data for performance. - Structural integrity values >= 1e8 are treated as "immortal" for the purpose of weather damage (no damage applied). - Damage creation vs. direct Damaged accumulation behavior depends on whether the object type has a Damaged component. - Icon notifications use different priorities depending on severity (>= 30 -> MajorProblem; otherwise Problem). Destroy notifications use FatalProblem priority.
Usage Example
// The system runs automatically when present in the World.
// Example: adding FacingWeather to an entity so WeatherDamageSystem will evaluate it.
Entity weatherEvent = /* some existing weather event entity */;
Entity buildingEntity = /* some existing building entity */;
var facingWeather = new FacingWeather
{
m_Event = weatherEvent,
m_Severity = 0f // initial severity; the system will compute the current severity each update
};
entityManager.AddComponentData(buildingEntity, facingWeather);
// Ensure the required singletons exist (FireConfigurationData, DisasterConfigurationData)
// The WeatherDamageSystem will be scheduled every 64 ticks and will process entities with FacingWeather.
If you want more detail about any specific field, the inner job, or how the structural integrity / damage math is computed, tell me which part you'd like expanded and I can add calculations and example scenarios.