-
Notifications
You must be signed in to change notification settings - Fork 7
Weather and Climate System
The ClimateController
is a class that contains all of the climate information for the GameArea
. It manages so called WeatherEvent
s, 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 WeatherEvent
s will add additional temperature and humidity modifiers on top of the base temperature and humidity stats.
ClimateController
instances will be properties of GameArea
s rather than the ServiceLocator
, as the climate should only affect entities of the given GameArea
.
The ClimateController
keeps track of a List
of WeatherEvent
s, representing WeatherEvent
s that are either currently happening, or scheduled to happen within a finite amount of time.
Of the WeatherEvent
s 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 WeatherEvent
s 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 a AcidShowerEvent
or a SolarSurgeEvent
. These events will have the following random stats:
-
numHoursUntil
1 -> 6 (integer) -
duration
2 -> 5 (integer) -
priority
0 -> 3 (integer) -
severity
0 -> 1 (float)
A WeatherEvent
can be added by calling the ClimateController
’s addWeatherEvent()
method passing in an instance of WeatherEvent
.
All tracked WeatherEvents
will be updated every hour using their updateTime()
method. Then, for each active WeatherEvent
s, 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 WeatherEvent
s will be updated every hour, regardless of which WeatherEvent
s are active or occurring.
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 WeatherEvent
s to trigger additional miscellaneous in-game effects (see the section on WeatherEvent
s 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 WeatherEvent
s.
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.
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.
WeatherEvent
s have the following properties, which are initialised when a WeatherEvent
is created:
-
numHoursUntil
- The number of hours until theWeatherEvent
becomes active -
duration
- The duration of theWeatherEvent
once it becomes active. Note that aWeatherEvent
’s duration will decrement while it is active, even if it is not occurring -
priority
- An integer representing the importance of theWeatherEvent
. For instance, if there are 3 activeWeatherEvent
s, theWeatherEvent
with the highestpriority
will occur. In the instance where at least 2WeatherEvent
s are active simultaneously, theWeatherEvent
added to theClimateController
first will occur -
severity
- A float representing how ‘severe’ theWeatherEvent
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
WeatherEvent
s also have the following publicly accessible methods which can be invoked by the ClimateController
:
-
updateTime()
- Will decrement thenumHoursUntil
property if theWeatherEvent
is inactive, or decrement theduration
property -
isActive()
- Returns a boolean value representing whether theWeatherEvent
is active (that is, ifnumHoursUntil
is 0, butduration
is not) -
getTemperatureModifier()
- Returns a temperature to be added on top of theClimateController
’s temperature -
getHumidityModifier()
- Returns a humidity amount to be added on top of theClimateController
’s humidity
There are also a number of getter methods to access the priority, the temperature and humidity modifiers, and the severity.
Effects
- UI renderer will listen to
weatherUpdate
event, then when they get the effect from theClimateController
then pass to renderer.
- 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.