New time and weather mod in the works
by Bil Simser · in Torque Game Engine · 07/20/2004 (7:24 pm) · 9 replies
Not sure if I should have posted this as a .plan or a message. In any case, it'll end up as a new resource by the end of the week.
Amongst the dozens of Torque projects I have on the go, I wanted to build a nice, pluggable time and weather system into Torque for would-be RPG creators to use. I didn't see anything that I really liked already so I built this one.
Not much to see but screenies are always nice to have.

Features:
* configurable game time system that handles time and weather advancement (you can use it for any game management you want like bots, spell recharge times, whatever but this mod just gives you time and weather)
* you determine how fast (or slow) time advances (real time, 1 game time hour = 75 seconds, whatever)
* weather system tracks atmospheric pressure and changes accordingly (based on values and the time of year)
* time system is streamed out to the file system on the server and can be reloaded to keep a pseudo persistant world going (at least as far as keeping track of time goes)
* weather system initiates clouds, rain, fog, lightning and cleans up when the cycle stops (pressure builds and declines so it's not constant)
* time and weather system can be queried by user to get information (yes, they can look up into the sky but someone people like to know what's going on through messages).
A lot of extendability here but it's a fully working time keeper and weather system for someone to use in a single player or multiplayer game. For example you could build a calendar gui component to display on the screen and have it update as time advances in your game. Whatever your imagine takes you I guess.
I haven't plugged in a real day/night system as that involves engine changes and wanted to keep this as a scripting mod only so you're welcome to do that. The system keeps track of the hour of the game time day so you can still use it (like only allowing certain things to happen at night or the automatic opening and closing of stores during business hours).
Like I said, I'll put this up as a resource for the end of the week. Need to do some more testing and leave the server running for a day or so to make sure nothing goes kabam. Cheers!
Amongst the dozens of Torque projects I have on the go, I wanted to build a nice, pluggable time and weather system into Torque for would-be RPG creators to use. I didn't see anything that I really liked already so I built this one.
Not much to see but screenies are always nice to have.

Features:
* configurable game time system that handles time and weather advancement (you can use it for any game management you want like bots, spell recharge times, whatever but this mod just gives you time and weather)
* you determine how fast (or slow) time advances (real time, 1 game time hour = 75 seconds, whatever)
* weather system tracks atmospheric pressure and changes accordingly (based on values and the time of year)
* time system is streamed out to the file system on the server and can be reloaded to keep a pseudo persistant world going (at least as far as keeping track of time goes)
* weather system initiates clouds, rain, fog, lightning and cleans up when the cycle stops (pressure builds and declines so it's not constant)
* time and weather system can be queried by user to get information (yes, they can look up into the sky but someone people like to know what's going on through messages).
A lot of extendability here but it's a fully working time keeper and weather system for someone to use in a single player or multiplayer game. For example you could build a calendar gui component to display on the screen and have it update as time advances in your game. Whatever your imagine takes you I guess.
I haven't plugged in a real day/night system as that involves engine changes and wanted to keep this as a scripting mod only so you're welcome to do that. The system keeps track of the hour of the game time day so you can still use it (like only allowing certain things to happen at night or the automatic opening and closing of stores during business hours).
Like I said, I'll put this up as a resource for the end of the week. Need to do some more testing and leave the server running for a day or so to make sure nothing goes kabam. Cheers!
#2
Sounds nifty. There's a few things I'd like to try this out in :)
Tom.
07/21/2004 (4:48 am)
Hey Bil,Sounds nifty. There's a few things I'd like to try this out in :)
Tom.
#3
07/21/2004 (5:21 am)
I would like to try this as well, cool plan.
#4
David
07/21/2004 (7:05 am)
Looks good...how are the specifications made to change the 'weather pattern' if you will? Via settings in a file somewhere, script, ?David
#5
Sounds like some cookbook recipes could be gleaned from here too. ;)
07/21/2004 (7:13 am)
Nice, Bil. :)Sounds like some cookbook recipes could be gleaned from here too. ;)
#6
07/21/2004 (7:33 am)
Looks like I'll be slamming this in to. Will really help our code base.
#7
07/21/2004 (8:18 am)
@David: The weather is driven by atmospheric pressure values, the current sky conditions and some random chance. It's all in one script function but parts of it could be externalized or become data driven. It's pretty basic so nothing really magical here, just easy to use. Here's the weather function as it is right now://-----------------------------------------------------------------------------
// This updates the weather changes based on time, pressure
// and a random value. It also tells the engine to create the
// effects for the weather changes (rain, lightning, fog, etc.)
//-----------------------------------------------------------------------------
function GameManager::weather_change(%this)
{
%diff = 0;
// Later months in year don't need as much pressure to create a change
// (or you can change this to suit your environment)
if(($time_info.month >= 9) && ($time_info.month <= 12))
%diff = ($weather_info.pressure > 985 ? -2 : 2);
else
%diff = ($weather_info.pressure > 1015 ? -2 : 2);
$weather_info.change += (dice(1, 4) * %diff + dice(2, 6) - dice(2, 6));
// Cap the changes so weather isn't too drastic
$weather_info.change = min($weather_info.change, 12);
$weather_info.change = max($weather_info.change, -12);
$weather_info.pressure += $weather_info.change;
// Cap the pressure values so we don't go crazy with weather changes
$weather_info.pressure = min($weather_info.pressure, 1040);
$weather_info.pressure = max($weather_info.pressure, 960);
%change = 0;
// Based on the current sky conditions and the change
// value, determine what the new weather should be
switch($weather_info.sky)
{
case $sky_cloudless:
if($weather_info.pressure < 990)
%change = 1;
else if($weather_info.pressure < 1010)
if(dice(1, 4) == 1)
%change = 1;
case $sky_cloudy:
if($weather_info.pressure < 970)
{
%change = 2;
}
else if($weather_info.pressure < 990)
{
if(dice(1, 4) == 1)
%change = 2;
else
%change = 0;
}
else if($weather_info.pressure > 1030)
{
if(dice(1, 4) == 1)
%change = 3;
}
case $sky_raining:
if($weather_info.pressure < 970)
{
if(dice(1, 4) == 1)
%change = 4;
else
%change = 0;
}
else if($weather_info.pressure > 1030)
%change = 5;
else if($weather_info.pressure > 1010)
if(dice(1, 4) == 1)
%change = 5;
case $sky_lightning:
if($weather_info.pressure > 1010)
%change = 6;
else if(weather_info.pressure > 990)
if(dice(1, 4) == 1)
%change = 6;
default:
$weather_info.sky = $sky_cloudless;
%change = 0;
}
// Implement the weather change now
switch(%change)
{
case 1:
messageAll("weather", "The sky starts to get cloudy.");
Sky.stormClouds(1, $time_to_storm);
$weather_info.sky = $sky_cloudy;
case 2:
messageAll("weather", "It stars to rain");
$weather_info.sky = $sky_raining;
%this.startRain();
case 3:
messageAll("weather", "The clouds disappear");
Sky.stormClouds(0, $time_to_storm);
$weather_info.sky = $sky_cloudless;
case 4:
messageAll("weather", "Lighting starts to show in the sky");
$weather_info.sky = $sky_lightning;
%this.startLightning();
case 5:
messageAll("weather", "The rain stops");
$weather_info.sky = $sky_cloudy;
%this.stopRain();
case 6:
messageAll("weather", "The lightning stops");
$weather_info.sky = $sky_raining;
%this.stopLightning();
}
}I may split out the actual execution of the weather change with the code to initiate it to handle when you first load the mission and have to immediately alter the world to match what was previously stored.
#8
07/21/2004 (8:30 am)
Thanks for the info, Bil. I'll be on the lookout for it.
#9
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6107
Enjoy.
07/23/2004 (11:15 am)
This is now an approved resource which can be found here:www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6107
Enjoy.
Torque Owner Eustacia Green