Skip to content

Weather and Climate System

Lucas Hicks edited this page Sep 10, 2023 · 14 revisions

ClimateController

The ClimateController is a class that contains all of the climate information for the GameArea. It manages so called WeatherEvents, which occur periodically on top of the standard daily weather cycle. There are two main stats that the ClimateController tracks and modifies:

  • Temperature - The temperature of the GameArea’s environment.
  • Humidity - The relative humidity of the GameArea’s environment. Humidity ranges between 0 and 1 inclusive

Both temperature and humidity will change throughout the course of an in-game day sinusoidally, with a minimum temperature being reached just before sunrise, and a maximum being reached in the mid to late afternoon. The presence of WeatherEvents will add additional temperature and humidity modifiers on top of the base temperature and humidity stats.

ClimateController instances will be properties of GameAreas rather than the ServiceLocator### , as the climate should only affect entities of the given GameArea.

Handling WeatherEvents

The ClimateController keeps track of a List of WeatherEvents, representing WeatherEvents that are either currently happening, or scheduled to happen within a finite amount of time.

Of the WeatherEvents that are active at any given moment, only one will occur at a given time (this WeatherEvent is referenced by the private member variable currentWeatherEvent). The currentWeatherEvent will apply a humidity and temperature modifier to the current temperature and humidity.

Random Weather Events

Random WeatherEvents by default have a chance to occur once every in-game day. Every in-game day the 'addDailyEvent()method is called, determining whether or not an event should be added, its stats and the type of event to be added. There is a **75%** chance every in-game day that an event will be created. For the creation of events, it is equally likely that this event will be aAcidShowerEventor aSolarSurgeEvent`. These events will have the following random stats:

  • numHoursUntil 1 -> 6 (integer)
  • duration 2 -> 5 (integer)
  • priority 0 -> 3 (integer)
  • severity 0 -> 1 (float)

Adding Weather Events

A WeatherEvent can be added by calling the ClimateController’s addWeatherEvent() method passing in an instance of WeatherEvent.

Updated Weather Events

All tracked WeatherEvents will be updated every hour using their updateTime() method. Then, for each active WeatherEvents, the ClimateController will determine which has the highest priority, and assign this WeatherEvent to be the currentWeatherEvent (which in turn will affect the temperature and humidity). Note that all tracked WeatherEvents will be updated every hour, regardless of which WeatherEvents are active or occurring.

Climate’s Effects

The current temperature and humidity of the entire climate can be accessed through the public methods getTemperature() and getHumidity(), by any Entity or Component with access to the ClimateController (which can be accessed through the GameArea).

The ClimateController also has an EventHandler, which can be accessed through the getEvents() method. This EventHandler will be used by certain WeatherEvents to trigger additional miscellaneous in-game effects (see the section on WeatherEvents for more information). Hence, other components and entities may provide event listeners to this EventHandler in order to trigger miscellaneous changes to their state based on certain WeatherEvents.

For instance, a Solar Flare may cause certain types of plants to singe or be destroyed. To accommodate this behaviour, plant components could add an event listener to the ClimateController’s EventHandler when created, which will be triggered by a Solar Flare when it becomes active.

WeatherEvent

A WeatherEvent is an abstract class representing any form of weather event beyond the typical daily temperature and humidity changes. These could include storms, geological activity, or off-world events such as solar flares or meteor showers.

WeatherEvents have the following properties, which are initialised when a WeatherEvent is created:

  • numHoursUntil - The number of hours until the WeatherEvent becomes active
  • duration - The duration of the WeatherEvent once it becomes active. Note that a WeatherEvent’s duration will decrement while it is active, even if it is not occurring
  • priority - An integer representing the importance of the WeatherEvent. For instance, if there are 3 active WeatherEvents, the WeatherEvent with the highest priority will occur. In the instance where at least 2 WeatherEvents are active simultaneously, the WeatherEvent added to the ClimateController first will occur
  • severity - A float representing how ‘severe’ the WeatherEvent is. That is, how extreme their temperature and humidity modifiers will be. For instance, if a rain event can have a temperature modifier between -4 and -10, and a humidity modifier between 0.05 and 0.2, a severity of 1 will result in -10 and 0.2, while a severity of 0 will result in -4 and 0.05

WeatherEvents also have the following publicly accessible methods which can be invoked by the ClimateController:

  • updateTime() - Will decrement the numHoursUntil property if the WeatherEvent is inactive, or decrement the duration property
  • isActive() - Returns a boolean value representing whether the WeatherEvent is active (that is, if numHoursUntil is 0, but duration is not)
  • getTemperatureModifier() - Returns a temperature to be added on top of the ClimateController’s temperature
  • getHumidityModifier() - Returns a humidity amount to be added on top of the ClimateController’s humidity

There are also a number of getter methods to access the priority, the temperature and humidity modifiers, and the severity.

Visuals

Effects

  • UI renderer will listen to weatherUpdate event, then when they get the effect from the ClimateController then pass to renderer.

Implementations

  • Solar flare - will increase the temperature of the world drastically
  • Raining - humidity increase - rain can also have a severity which will determine the relative humidity increase.

UML Diagrams

Clone this wiki locally