[an error occurred while processing this directive]
[<a href="index.shtml">Package Index</a></code> | <a href="index_std.shtml">Mudlib Index</a></code> | <a href="index_eff.shtml">Effect Index</a></code>]<br><h2>File /obj/handlers/weather.c</h2>
An attempt at a new weather handler for Discworld.
Ceres@Discworld 14/4/96

Having thought about the way weather works (and Discworlds interesting
meteorology) I decided not to try and implement some model of realworld
weather. Instead regional variations in weather are handled by
regional climate properties. This system will handle diurnal and seasonal
variations and that's about it. Hopefully that will make it more
understandable, usable and efficient.<p>

Basic Operation<br>
---------------<br>
The weather is based on weather 'pattern's. The pattern lasts for several
hours and is calculated from the 'seasonal' norm and the 'variance'. The
'current' weather will tend towards the pattern weather.<p>

The pattern depends on the climate. The climates are taken from the Koppen
Climate Classification system. The possible climates are:<br>
tropical<br>
- rainforest 'Af' eg. amazon, congo, malaysia<br>
- monsoon 'Am' <br>
- savanna 'Aw' eg. caribbean, tropical africa, central america<br>
desert<br>
- arid 'Bw'<br>
- semi-arid 'Bs' <br>
mediterranean (aka Moist Subtropical Mid-Latitude Climates)<br>
- humid subtropical 'Cfa' eg. Souteast US (florida)<br>
- mediterranean 'Cs' eg. california, south africa, western/central australia<br>
- marine 'Cfb' eg. US west coast, nw europe<br>
continental<br>
- dry winters 'Dw' <br>
- dry summers 'Ds'<br>
- wet 'Df'<br>
polar<br>
- tundra 'Et'<br>
- frozen 'Ef'<br>
highland 'H' <p>

The default for a room is mediterranean marine (Cfb).<p>

The actual temparture in a room will depend on the current weather for that
climate, local modifiers (climate property), diurnal variations and
variance.<p>

Thus update_patttern() is called once every hour (CYCLE_SPEED) and
update_weather() is called every 5 minutes (UPDATE_SPEED).<p>

Decisions<br>
---------<br>
Calculation of the general weather has been moved into
update_weather. Rather than doing it on a room by room basis everytime
someone looks! Instead, local climate controls will be added verbatim to
the current global weather. This will improve efficiency massively, but will
reduce the overall weather variations.<p>

Principles<br>
----------<br>
Rain/sleet/snow depends on cloud density and temperature.<br>
If it's windy and lots of cloud density we might get a thunder storm.
Cloud cover should lower temperature as should wind.<p>

Usage<br>
-----<br>
To alter the weather in a given room the easiest approach is to set the
climate. Individual room or area variations can be done by adding a
climate property.<br>
The property should contain three integers, temperature, cloud cover and
wind speed. These modify the default values for the room.<p>
For example:<br>
add_property("climate", ({10, -50, 0});<br>
This will increase the temperature by 10C, reduce the cloud cover
by 50% and make no change to the wind speed.<p>

To completely alter the weather in a room you need to define the function
room_weather() as follows:<br>
  int *room_weather(int temp, int cloud, int wind, int rain);<br>
Your room_weather function will be called with the values the room would
ordinarily receive and should return the new temperature, cloud cover,
wind speed and rain type values that you desire.<p>

If you need to make your room react to changes in the weather you can use
the weather_notify() system to be told when the weather changes.<br>
This should only be done for a small number of rooms or the lag will be
excessive Also note that after a notification has been done, you will need
to register if you want another one.<p>

Changed Jun 3 1996 by Grampa to include weather notifications for rooms.<p><h2>Includes</h2>
This class includes the following files /include/climate.h, /include/weather.h and /include/am_time.h<h2>Method index</h2>
<ul>
<li><a href="#check_umbrella">check_umbrella</a>(object)<li><a href="#cloud_string">cloud_string</a>(object)<br/>
A string giving a nice description of the cloud types.
<li><a href="#day_number">day_number</a>()<br/>
Find out which day of the Disc (common) year it is.
<li><a href="#minute_number">minute_number</a>()<br/>
Find out which minute of the day (0 - 1439) it is.
<li><a href="#query_cloud">query_cloud</a>(object)<br/>
Find out the cloud cover of a given room

<li><a href="#query_darkness">query_darkness</a>(object)<br/>
return percentage of light
should be dependant on the base amount of light, day or night time and
cloud cover.
<li><a href="#query_moon_phase">query_moon_phase</a>()<br/>
Find out which phase of the moon we're currently in.
<li><a href="#query_moon_state">query_moon_state</a>()<br/>
Query the state of the moon.
<li><a href="#query_moon_string">query_moon_string</a>(object)<br/>
Get the appropriate moon string.
<li><a href="#query_raining">query_raining</a>(object)<br/>
Find out if its raining in a given room.
<li><a href="#query_season">query_season</a>()<br/>
Return which of the 4 seasons we are in.
<li><a href="#query_snowing">query_snowing</a>(object)<br/>
Find out if its snowing in a given room.
<li><a href="#query_star_string">query_star_string</a>(object)<br/>
Returns a string describing the current visible stars.
<li><a href="#query_stars">query_stars</a>(object)<br/>
Return the number of currently visible stars as a percentage.
<li><a href="#query_sunrise">query_sunrise</a>(int)<br/>
Find out when sunrise will be on a given day of the year.
<li><a href="#query_sunset">query_sunset</a>(int)<br/>
Find out when sunset will be on a given day of the year.
<li><a href="#query_temperature">query_temperature</a>(object)<br/>
Find out the temperature of a given room

<li><a href="#query_tod">query_tod</a>()<br/>
Return a string for the period of the day

<li><a href="#query_visibility">query_visibility</a>(object)<br/>
return percentage of visibility.
<li><a href="#query_windsp">query_windsp</a>(object)<br/>
Find out the wind speed in a given room

<li><a href="#rain_string">rain_string</a>(object)<br/>
Creates a string showing how heavily it is raining.
<li><a href="#sleet_string">sleet_string</a>(object)<br/>
Creates a string showing how heavily it is sleeting.
<li><a href="#snow_string">snow_string</a>(object)<br/>
Creates a string showing how heavily it is snowing.
<li><a href="#temp_string">temp_string</a>(int)<br/>
Return a temperature string equating to the temperature passed
<li><a href="#weather_notify">weather_notify</a>(object, int)<br/>
Add a room to the list of rooms to notify about weather.
<li><a href="#weather_string">weather_string</a>(object, string)<br/>
Creates the weather string which is put into room descs.
</ul>
<h2>Public Functions</h2>
These are functions that everyone can access.<p>
<dl>
<dt class="autodocfuncname"><a name="check_umbrella">
check_umbrella</a><pre class="autodocfuncdef">
int check_umbrella(object ob)
</pre>
<dt class="autodocfuncname"><a name="cloud_string">
cloud_string</a><pre class="autodocfuncdef">
string cloud_string(object env)
</pre><dd><br />
A string giving a nice description of the cloud types.<br />
<br /><dl>
<dd><b>Parameters:</b><br />
env - the environment to find the clouds for<br />
<br />
<dd><b>Returns:</b>
<br />the current clouds
<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="day_number">
day_number</a><pre class="autodocfuncdef">
int day_number()
</pre><dd><br />
Find out which day of the Disc (common) year it is.<br />
<br /><dl>
<dd><b>Returns:</b>
<br />the day of the year.
<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="minute_number">
minute_number</a><pre class="autodocfuncdef">
int minute_number()
</pre><dd><br />
Find out which minute of the day (0 - 1439) it is.<br />
<br /><dl>
<dd><b>Returns:</b>
<br />the minute.
<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="query_cloud">
query_cloud</a><pre class="autodocfuncdef">
int query_cloud(object env)
</pre><dd><br />
Find out the cloud cover of a given room
<br />
<br /><dl>
<dd><b>Parameters:</b><br />
env - the room<br />
<br />
<dd><b>Returns:</b>
<br />an open ended percentage. Greater than 100 means heavier cover.
<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="query_darkness">
query_darkness</a><pre class="autodocfuncdef">
int query_darkness(object env)
</pre><dd><br />
return percentage of light
should be dependant on the base amount of light, day or night time and
cloud cover.
<br />
<br /><dl>
<dd><b>Parameters:</b><br />
the - room<br />
<br />
<dd><b>Returns:</b>
<br />a percentage
<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="query_moon_phase">
query_moon_phase</a><pre class="autodocfuncdef">
string query_moon_phase()
</pre><dd><br />
Find out which phase of the moon we're currently in.
<br />
<br /><dl>
<dd><b>Returns:</b>
<br />a string for the phase of the moon.
<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="query_moon_state">
query_moon_state</a><pre class="autodocfuncdef">
int query_moon_state()
</pre><dd><br />
Query the state of the moon.
<br />
<br /><dl>
<dd><b>Returns:</b>
<br />an integer indicating the state of the moon.
0 - no moon, 1 - crescent, 2 - quarter, 3 - half, 4 - three quarter,
5 - gibbous, 6 - full.
<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="query_moon_string">
query_moon_string</a><pre class="autodocfuncdef">
string query_moon_string(object env)
</pre><dd><br />
Get the appropriate moon string. This is almost completely from the old
system. I don't understand the moon.
<br />
<br /><dl>
<dd><b>Parameters:</b><br />
env - the room to check<br />
<br />
<dd><b>Returns:</b>
<br />the moon string.
<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="query_raining">
query_raining</a><pre class="autodocfuncdef">
int query_raining(object env)
</pre><dd><br />
Find out if its raining in a given room.
<br />
<br /><dl>
<dd><b>Parameters:</b><br />
env - the room<br />
<br />
<dd><b>Returns:</b>
<br />1 or 0 for true or false.
<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="query_season">
query_season</a><pre class="autodocfuncdef">
string query_season()
</pre><dd><br />
Return which of the 4 seasons we are in.<br />
<br /><dl>
<dd><b>Returns:</b>
<br />spring, summer, autumn or winter.
<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="query_snowing">
query_snowing</a><pre class="autodocfuncdef">
int query_snowing(object env)
</pre><dd><br />
Find out if its snowing in a given room.
<br />
<br /><dl>
<dd><b>Parameters:</b><br />
env - the room<br />
<br />
<dd><b>Returns:</b>
<br />1 or 0 for true or false.
<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="query_star_string">
query_star_string</a><pre class="autodocfuncdef">
string query_star_string(object env)
</pre><dd><br />
Returns a string describing the current visible stars.<br />
<br /><dl>
<dd><b>Returns:</b>
<br />a string for the visible stars.
<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="query_stars">
query_stars</a><pre class="autodocfuncdef">
int query_stars(object env)
</pre><dd><br />
Return the number of currently visible stars as a percentage.<br />
<br /><dl>
<dd><b>Returns:</b>
<br />A number 0-100, 0 being no stars.
<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="query_sunrise">
query_sunrise</a><pre class="autodocfuncdef">
int query_sunrise(int doy)
</pre><dd><br />
Find out when sunrise will be on a given day of the year.
<br />
<br /><dl>
<dd><b>Parameters:</b><br />
doy - Day of the Discworld common year.<br />
<br />
<dd><b>Returns:</b>
<br />sunrise time (in seconds past midnite).<br /><br />
<dd><b>See also:</b>
<br /><a href="#minute_number">minute_number()</a> and <a href="#day_number">day_number()
</a><br /><br /><br /></dl>

<dt class="autodocfuncname"><a name="query_sunset">
query_sunset</a><pre class="autodocfuncdef">
int query_sunset(int doy)
</pre><dd><br />
Find out when sunset will be on a given day of the year.
<br />
<br /><dl>
<dd><b>Parameters:</b><br />
doy - Day of the Discworld common year.<br />
<br />
<dd><b>Returns:</b>
<br />sunset time (in seconds past midnite).
<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="query_temperature">
query_temperature</a><pre class="autodocfuncdef">
int query_temperature(object env)
</pre><dd><br />
Find out the temperature of a given room
<br />
<br /><dl>
<dd><b>Parameters:</b><br />
env - the room<br />
<br />
<dd><b>Returns:</b>
<br />a temperature in Celcius
<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="query_tod">
query_tod</a><pre class="autodocfuncdef">
string query_tod()
</pre><dd><br />
Return a string for the period of the day
<br />
<br /><dl>
<dd><b>Returns:</b>
<br />night, morning, midday, afternoon or evening.
<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="query_visibility">
query_visibility</a><pre class="autodocfuncdef">
int query_visibility(object env)
</pre><dd><br />
return percentage of visibility.
It should also depend on things like rain/snow etc, anything which
will effect visibility.
<br />
<br /><dl>
<dd><b>Parameters:</b><br />
the - room<br />
<br />
<dd><b>Returns:</b>
<br />a percentage
<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="query_windsp">
query_windsp</a><pre class="autodocfuncdef">
int query_windsp(object env)
</pre><dd><br />
Find out the wind speed in a given room
<br />
<br /><dl>
<dd><b>Parameters:</b><br />
env - the room<br />
<br />
<dd><b>Returns:</b>
<br />the wind speed in miles per hour.
<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="rain_string">
rain_string</a><pre class="autodocfuncdef">
string rain_string(object env)
</pre><dd><br />
Creates a string showing how heavily it is raining.<br />
<br /><dl>
<dd><b>Parameters:</b><br />
env - the room room to check in
<br />
<br />
<dd><b>Returns:</b>
<br />the rain string<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="sleet_string">
sleet_string</a><pre class="autodocfuncdef">
string sleet_string(object env)
</pre><dd><br />
Creates a string showing how heavily it is sleeting.<br />
<br /><dl>
<dd><b>Parameters:</b><br />
env - the room room to check in
<br />
<br />
<dd><b>Returns:</b>
<br />the sleet string<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="snow_string">
snow_string</a><pre class="autodocfuncdef">
string snow_string(object env)
</pre><dd><br />
Creates a string showing how heavily it is snowing.<br />
<br /><dl>
<dd><b>Parameters:</b><br />
env - the room room to check in
<br />
<br />
<dd><b>Returns:</b>
<br />the snow string<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="temp_string">
temp_string</a><pre class="autodocfuncdef">
string temp_string(int temp)
</pre><dd><br />
Return a temperature string equating to the temperature passed<br />
<br /><dl>
<dd><b>Parameters:</b><br />
int - The temperature in Celcius<br />
<br />
<dd><b>Returns:</b>
<br />string a temperature string.
<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="weather_notify">
weather_notify</a><pre class="autodocfuncdef">
int weather_notify(object which_room,
                   int notifications)
</pre><dd><br />
Add a room to the list of rooms to notify about weather.  Notifications
are an ORed (|) combination of the #defines in /include/climate.h
IE: To inform about temperature and rain changes, call
weather_notify( room, (NOTIFY_TEMPERATURE | NOTIFY_RAIN) );
<br />
<br /><dl>
<dd><b>Parameters:</b><br />
which_room - the room to be notified<br />
notifications - a bitmap of notifications<br />
<br />
<dd><b>Returns:</b>
<br />success or failure (1 or 0)
<br /><br />
<br /></dl>

<dt class="autodocfuncname"><a name="weather_string">
weather_string</a><pre class="autodocfuncdef">
varargs string weather_string(object env,
                              string obscured)
</pre><dd><br />
Creates the weather string which is put into room descs.
<br />

</dl>
[an error occurred while processing this directive]

