Caveweather
Overview
The Caveweather component simulates the complete weather cycle for the cave world. Attached to TheWorld entity, it functions as a global system managing moisture accumulation, precipitation (rain and acid rain), and the overall wetness level of the environment. It also controls associated audio-visual effects, such as rain sounds, rain particle effects, and puddle ground overlays. This system operates independently of the surface world's weather.
Dependencies & Tags
None identified.
Properties
The component's state is primarily managed through private and networked variables rather than public properties on the self table.
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | The entity this component is attached to. | A reference to the entity instance, which is TheWorld. |
Main Functions
OnUpdate(dt)
- Description: The core update loop for the weather simulation. This function is called every frame to advance the state of moisture, precipitation, and wetness. It also manages all associated sound and visual effects based on the current weather conditions.
- Parameters:
dt(number): The time elapsed since the last update (delta time).
LongUpdate(dt)
- Description: An alias for
OnUpdate(dt). It performs the exact same function. - Parameters:
dt(number): The time elapsed since the last update (delta time).
OnSave()
- Description: Serializes the current state of the cave weather system into a data table for saving the game. This function is only available on the master simulation (server).
- Parameters: None.
OnLoad(data)
- Description: Loads the weather system's state from a previously saved data table. This function is only available on the master simulation (server).
- Parameters:
data(table): The saved data table generated byOnSave().
GetDebugString()
- Description: Generates a formatted string containing debug information about the current weather state, including temperature, moisture levels, precipitation rate, and wetness.
- Parameters: None.
OnPostInit()
- Description: A post-initialization function called when a player becomes active. It is used to initialize the rain visual effects prefabs. This function is only defined on the client.
- Parameters: None.
OnRemoveEntity()
- Description: Cleans up and removes the visual effect prefabs (
caverain,caveacidrain) when the component's parent entity is removed. This function is only defined on the client. - Parameters: None.
Events & Listeners
This component listens for the following events:
seasontick: Updates internal season and progress values, which influence moisture rates.temperaturetick: Caches the current world temperature.phasechanged: Tracks whether it is currently day or night.playeractivated: Attaches rain visual effects to the newly active player and starts listening for theirchangeareaevent.playerdeactivated: Detaches rain visual effects from the deactivated player.moistureceildirty: Fired when the networked moisture ceiling value changes.preciptypedirty: Fired when the networked precipitation type value changes.wetdirty: Fired when the networked_wetboolean value changes.ms_playerjoined(Master Sim): Begins tracking player area changes to manage acid rain logic.ms_playerleft(Master Sim): Stops tracking player area changes.ms_forceprecipitation(Master Sim): Forces precipitation to start or stop.ms_setprecipitationmode(Master Sim): Sets the precipitation mode (e.g., "dynamic", "always", "never").ms_setmoisturescale(Master Sim): Adjusts the moisture accumulation rate multiplier.ms_deltamoisture(Master Sim): Directly adds or removes a value from the current moisture level.ms_deltamoistureceil(Master Sim): Directly adds or removes a value from the moisture ceiling.ms_deltawetness(Master Sim): Directly adds or removes a value from the current wetness level.ms_simunpaused(Master Sim): Forces a resynchronization of networked variables after the game is unpaused.
This component pushes the following events to TheWorld:
weathertick: Pushed every frame (OnUpdate) with a data table containing the currentmoisture,pop(probability of precipitation),precipitationrate,wetness, and other weather data.moistureceilchanged: Pushed when the moisture ceiling changes, broadcasting the new value.precipitationchanged: Pushed when the precipitation type changes (e.g., from "none" to "rain"), broadcasting the new type as a string.wetchanged: Pushed when the world's wet status crosses theDRY_THRESHOLDorWET_THRESHOLD, broadcasting a boolean indicating if it is now "wet".