Weather

version 3/080914 by Ish McGravin

  • Home page
  • Beginning
  • Next



  • Documentation


    This extension is intended to model a number of natural systems with a modicum of accuracy where I could manage. The four parts are fairly interwoven and are all based on the Table of Months.

    The date model moves the day number forward at midnight, resets the day to 1 and moves the month forward at the end of the month, and resets the month to 1 and moves the year forward at the end of the year.

    The day/night cycle model simply determines if it is night based upon average sunrise and sunset times calculated for each month.

    The weather model operates on a randomly generated weather value between 1 and 10, and on a randomly modified temperature based on the average temperature for each month. The weather value generates a description of current conditions, with 1 through 3 being "sunny", 4 and 5 being "partly cloudy", 6 through 8 being "cloudy", and 9 and 10 being precipitation. Precipitation is decided to be either "raining" or "snowing" depending on the temperature.

    The moon phase model calculates the current moon phase (new, full, and the stages in between) based upon running the current game date through a complicated algorithm.

    I'm ALWAYS looking for ways to improve this extension. If you find any bugs or typos, or if you have a suggestion, please contact me at McGravin (at) Gmail (dot) com.

    ::: Usage :::

    - "Year", "Month", "Day" variables give the date. See "precautions" for a note on the month variable.

    - "Name in row Month of Table of Months" will give the name of the current month.

    - "Weather" variable gives the weather value between 1 and 10 as described above.

    - "DTemp" and "NTemp" give the daytime temperature and nighttime temperature, respectively. Temperatures are in Fahrenheit.

    - "MoonN" variable gives the moon phase as a number between 0 and 7, with 0 being new, 4 being full, and other numbers representing intermediate phases.

    - "WDesc" and "MoonP" text variables give the description of the weather and moon phase, respectively.

    - Several fairly self-explanatory conditionals you can use in if statements: "if it is night", "if it is winter", "if it is spring", "if it is summer", "if it is fall", and "if there is snow on the ground".

    ::: Defaults :::

    - The default time and date are 12:01 AM, January 1, 1900.

    - The default moon phase is a new moon, which should be the phase on the default date. If you use a new date, it is a good idea to run through the moon phase algorithm once with your game's start date and include the new moon phase variables MoonN and MoonP with your resultant phase.

    - The default sunrise, sunset, and average temperatures are for Rolla, MO, which is the population center of the United States. It should therefore hopefully approximate the numbers for an average number of Inform users, or else for the setting of our game. For consistency, the times are also based on Daylight Savings Time for the entire year (rather than only for the months during which DST is used).

    - The sunrise, sunset, and average temperatures are for the middle of each month (the 15th) rather than modified for each day.


    ::: Limitations :::

    - The date simulator does not currently take into account the extra day in February during leap years, which is a simple improvement I intend to make in the future.

    - The moon phase simulator is currently slightly inacurrate and limitted to the range of years from 1900 to 2100 inclusive. If a future version of Inform 7 ever allows for decimal numbers, a more accurate algorithm can be implemented.

    - Wind and wind speed are not simulated currently.

    - Moonrise and moonset are not currently simulated, so the moon is always up when it is night.

    - If the default sunrise and sunset times are replaced and the new sunrise is after or the new sunset is before 12:00AM for any month or months (ie, in far northern latitudes), special consideration will have to be made in the "To decide whether it is night" definition.

    - Sunrise and sunset times are approximated as a monthly average based on the middle of the month. If a simple enough algorithm can be found, times will be calculated daily.

    - Twilight times are not currently included, but may be in a future version.

    - "snow is on the ground" is true always if the temperature is below 33 degrees, regardless of any recent precipitation.


    ::: Precautions :::

    - Avoid using "increase Time of Day by <x number of minutes or hours>". It is possible to accidentally skip the hourly weather changes and daily date changes. Instead use "repeat with X running from 1 to <a number of minutes> begin; follow the turn sequence rules; end repeat". This method will artificially inflate the player's turn count, but will avoid the possibility of accidentally skipping the "At 12:00 AM" check and making the game remain on the same date.

    - "Month" is funky and needs to be used carefully. In most cases, you'll want the name of the month which is easily determined (see "usage"). Otherwise, keep in mind that month 1 is December and months 2 through 12 are January through November.


    ::: Suggestions :::

    - Assuming we have a region called "the outdoors" which includes all the rooms from which we want the player to be able to see the sky and celestial objects, I recommend adding the following snippet to the game:

        The sky is a backdrop in the outdoors. The description is "It is [if it is night]dark[otherwise]bright[end if] and [WDesc]."
        The stars are a backdrop. The description is "The stars shine brightly, like jewels in the night sky."
        The sun is a backdrop. The description is "[if Weather is less than 4]You are momentarily blinded by the shining sun.[otherwise]The sun shines through the clouds.[end if]".
        The moon is a backdrop. The description is "[MoonP]".
        The clouds are a backdrop. The description is "[if Weather is less than 6]The clouds are scattered in the sky[otherwise]The clouds cover the sky[end if][if it is night]. The stars are obscured.[otherwise], and that one looks like a bunny. The sky is obscured.[end if]".

        Every turn:
            if it is night begin;
                if Weather is less than 4 begin;
                    if the stars are off-stage then move the stars to the outdoors;
                    if the sun is on-stage then remove the sun from play;
                    if the moon is on-stage then remove the moon from play;
                    if the clouds are on-stage then remove the clouds from play;
                otherwise if Weather is less than 6;
                    if the stars are on-stage then remove the stars from play;
                    if the sun is on-stage then remove the sun from play;
                    if the moon is off-stage then move the moon to the outdoors;
                    if the clouds are off-stage then move the clouds to the outdoors;
                otherwise;
                    if the stars are on-stage then remove the stars from play;
                    if the sun is on-stage then remove the sun from play;
                    if the moon is on-stage then remove the moon from play;
                    if the clouds are off-stage then move the clouds to the outdoors;
                end if;
            otherwise;
                if Weather is less than 4 begin;
                    if the stars are on-stage then remove the stars from play;
                    if the sun is off-stage then move the sun to the outdoors;
                    if the moon is on-stage then remove the moon from play;
                    if the clouds are on-stage then remove the clouds from play;
                otherwise if Weather is less than 6;
                    if the stars are on-stage then remove the stars from play;
                    if the sun is off-stage then move the sun to the outdoors;
                    if the moon is on-stage then remove the moon from play;
                    if the clouds are off-stage then move the clouds to the outdoors;
                otherwise;
                    if the stars are on-stage then remove the stars from play;
                    if the sun is on-stage then remove the sun from play;
                    if the moon is on-stage then remove the moon from play;
                    if the clouds are off-stage then move the clouds to the outdoors;
                end if;
            end if.