generated from Jaysyn/ModuleTemplate
237 lines
8.6 KiB
Plaintext
237 lines
8.6 KiB
Plaintext
//::///////////////////////////////////////////////
|
|
//:: Global Weather System V1.1
|
|
//:: s_icw_include
|
|
//:://////////////////////////////////////////////
|
|
/*
|
|
The purpose of this system is to create a global weather
|
|
system for your module. The weather changes after a
|
|
certain amount of time to a different type.
|
|
|
|
This is an include file, so if you make changes to this
|
|
script you must recompile the scripts which use it.
|
|
|
|
Latest updates at http://iceyboard.no-ip.org and the NWVault
|
|
|
|
Released under the GNU General Public License:
|
|
http://www.gnu.org/copyleft/gpl.html
|
|
*/
|
|
//:://////////////////////////////////////////////
|
|
//:: Created by: Icey <iceyicey@gmail.com>
|
|
//:: Created on: April 2004 (v1.0)
|
|
//:: Updated on: March 2005 (v1.1)
|
|
//:://////////////////////////////////////////////
|
|
|
|
//// NOTE ////
|
|
|
|
// valen story scripts from XP2 are used with the system.
|
|
// they save variables to the module during conversations, which
|
|
// i then check to see what action the user wants to perform.
|
|
// by using those scripts i can cut down the amount of scripts
|
|
// the system requires. without would require 12, but with is 5.
|
|
// however, this may cause problem if you're using those scripts
|
|
// somewhere else in the module, although that's very unlikely
|
|
|
|
//// CONSTANTS ////
|
|
|
|
// the weather will change after a random time between
|
|
// the minimum duration and the maximum duration.
|
|
const int WEATHER_MIN_DURATION = 10; // minutes
|
|
const int WEATHER_MAX_DURATION = 20; // minutes
|
|
|
|
// the variable used to disable the weather system.
|
|
const string IC_VAR_DISABLE_SYSTEM = "IC_DISABLE_WEATHER_SYSTEM";
|
|
// the variable used to store the current weather
|
|
const string IC_VAR_WEATHER_STORE = "IC_WEATHER";
|
|
|
|
// the chance of switching between one type of weather to another.
|
|
// this is a percent figure so each set must add up to 100.
|
|
|
|
// when it's clear
|
|
const int IC_WEATHER_CLEAR_TO_CLEAR = 50;
|
|
const int IC_WEATHER_CLEAR_TO_RAIN = 40;
|
|
const int IC_WEATHER_CLEAR_TO_SNOW = 10;
|
|
// when it's raining
|
|
const int IC_WEATHER_RAIN_TO_CLEAR = 40;
|
|
const int IC_WEATHER_RAIN_TO_RAIN = 40;
|
|
const int IC_WEATHER_RAIN_TO_SNOW = 20;
|
|
// when it's snowing
|
|
const int IC_WEATHER_SNOW_TO_CLEAR = 20;
|
|
const int IC_WEATHER_SNOW_TO_RAIN = 45;
|
|
const int IC_WEATHER_SNOW_TO_SNOW = 35;
|
|
|
|
//// DEFINITIONS ////
|
|
|
|
// this function contains exceptions in the weather system
|
|
void Exceptions();
|
|
// responsible for starting the system
|
|
// should be called from the module start script
|
|
void StartWeatherSystem();
|
|
// call this function to enable the system after it has been disabled
|
|
void EnableWeatherSystem();
|
|
// disables the system and sets the weather to a certain type
|
|
void ModifyWeather(object oPC=OBJECT_SELF);
|
|
// this function changes the weather if the system is enabled
|
|
void SetRandomWeather();
|
|
// changes the skybox in the current area depending on conversation checks
|
|
void ModifySkyBox();
|
|
|
|
//// FUNCTIONS ////
|
|
|
|
// function containing exceptions to global weather
|
|
void Exceptions()
|
|
{
|
|
// this is where you add specific areas in that you want to keep
|
|
// the same weather in at all times, for example deserts should
|
|
// be clear and mountains could have snow
|
|
|
|
// the GetObjectByTag() function should have the area tag in it
|
|
// you can get this from the properties window of the area
|
|
|
|
// examples:
|
|
//SetWeather(GetObjectByTag("AreaDesert"), WEATHER_CLEAR);
|
|
//SetWeather(GetObjectByTag("AreaBeach"), WEATHER_RAIN);
|
|
//SetWeather(GetObjectByTag("AreaMountain"), WEATHER_SNOW);
|
|
}
|
|
|
|
// this function starts the system
|
|
void StartWeatherSystem()
|
|
{
|
|
// call the random weather function
|
|
SetRandomWeather();
|
|
}
|
|
|
|
// this function re-enables the system if it is deactivated
|
|
void EnableWeatherSystem()
|
|
{
|
|
// destroy the disable system variable
|
|
DeleteLocalInt(GetModule(), IC_VAR_DISABLE_SYSTEM);
|
|
}
|
|
|
|
// this function is called from the weather wand conversation
|
|
// it disables the system and changes the weather to a certain type
|
|
void ModifyWeather(object oPC=OBJECT_SELF)
|
|
{
|
|
// get a handle to the module
|
|
object oMod = GetModule();
|
|
// the weather type that will be used
|
|
int nWeather;
|
|
|
|
// disable the system until the player re-enables it
|
|
SetLocalInt(oMod, IC_VAR_DISABLE_SYSTEM, TRUE);
|
|
|
|
// work out the type of weather selected by the user
|
|
if (GetLocalInt(oMod, "iValenStage1") == 1) // 1
|
|
nWeather = WEATHER_CLEAR;
|
|
else if (GetLocalInt(oMod, "iValenStage1") == 2) // 2
|
|
nWeather = WEATHER_RAIN;
|
|
else // 3
|
|
nWeather = WEATHER_SNOW;
|
|
|
|
// remove variables so it doesn't conflict later
|
|
DeleteLocalInt(oMod, "iValenStage1");
|
|
// save the type of weather we are setting it to
|
|
SetLocalInt(oMod, IC_VAR_WEATHER_STORE, nWeather);
|
|
|
|
// change the global weather to this type
|
|
SetWeather(oMod, nWeather);
|
|
// run any exceptions to the rule
|
|
Exceptions();
|
|
}
|
|
|
|
// this function calls itself a random time after it is run
|
|
// that way the weather can be changed periodically
|
|
void SetRandomWeather()
|
|
{
|
|
// time between changing wather
|
|
// random point between min time and max time
|
|
int nDuration = WEATHER_MIN_DURATION + Random(WEATHER_MAX_DURATION - WEATHER_MIN_DURATION);
|
|
// default weather
|
|
int nWeather = WEATHER_CLEAR;
|
|
// handle to the module
|
|
object oMod = GetModule();
|
|
// variables for storing weather chances
|
|
int nClearChance, nRainChance, nSnowChance;
|
|
|
|
// check if the weather system has been temporarily disabled.
|
|
// the correct way to write is to store if the weather system is enabled,
|
|
// but using a disabled variable less variables need to be used
|
|
if (!GetLocalInt(oMod, IC_VAR_DISABLE_SYSTEM))
|
|
{
|
|
// get the current weather of the module
|
|
switch (GetLocalInt(oMod, IC_VAR_WEATHER_STORE))
|
|
{
|
|
case WEATHER_RAIN:
|
|
// save types to move from if the weather is rain
|
|
nClearChance = IC_WEATHER_RAIN_TO_CLEAR;
|
|
nRainChance = IC_WEATHER_RAIN_TO_RAIN;
|
|
nSnowChance = IC_WEATHER_RAIN_TO_SNOW;
|
|
break;
|
|
case WEATHER_SNOW:
|
|
// save types to move from if the weather is snow
|
|
nClearChance = IC_WEATHER_SNOW_TO_CLEAR;
|
|
nRainChance = IC_WEATHER_SNOW_TO_RAIN;
|
|
nSnowChance = IC_WEATHER_SNOW_TO_SNOW;
|
|
break;
|
|
// if there is no current weather, use clear
|
|
default: // or WEATHER_CLEAR
|
|
nClearChance = IC_WEATHER_CLEAR_TO_CLEAR;
|
|
nRainChance = IC_WEATHER_CLEAR_TO_RAIN;
|
|
nSnowChance = IC_WEATHER_CLEAR_TO_SNOW;
|
|
break;
|
|
}
|
|
// add up different parts
|
|
// this is so we can use a d100() to determine the type
|
|
nRainChance += nClearChance;
|
|
nSnowChance += nRainChance;
|
|
|
|
// determine the weather type to change/stay with
|
|
// get a random number between 1 and 100
|
|
int nRandom = d100();
|
|
// below clear
|
|
if (nRandom < nClearChance) nWeather = WEATHER_CLEAR;
|
|
// above clear but below rain
|
|
else if (nRandom < nRainChance) nWeather = WEATHER_RAIN;
|
|
// above rain
|
|
else nWeather = WEATHER_SNOW;
|
|
|
|
// save the current weather type
|
|
SetLocalInt(oMod, IC_VAR_WEATHER_STORE, nWeather);
|
|
// set the global weather
|
|
SetWeather(oMod, nWeather);
|
|
// run exceptions function
|
|
Exceptions();
|
|
}
|
|
// run the weather function again after a certain amount of time
|
|
DelayCommand(60.0 * IntToFloat(nDuration), SetRandomWeather());
|
|
}
|
|
|
|
// this changes the skybox in the current area.
|
|
void ModifySkyBox()
|
|
{
|
|
// set the module to a variable
|
|
object oMod = GetModule();
|
|
// set the skybox to the corresponding variable
|
|
// check variable saved on the module
|
|
if (GetLocalInt(oMod, "iValenStage1") == 1) // 1
|
|
// set the current area to the specified skybox
|
|
SetSkyBox(SKYBOX_DESERT_CLEAR);
|
|
// the remaining code uses the same format as above
|
|
// so no comments are necessary
|
|
else if (GetLocalInt(oMod, "iValenStage1") == 2) // 2
|
|
SetSkyBox(SKYBOX_GRASS_CLEAR);
|
|
else if (GetLocalInt(oMod, "iValenStage2") == 1) // 3
|
|
SetSkyBox(SKYBOX_GRASS_STORM);
|
|
else if (GetLocalInt(oMod, "iValenStage2") == 2) // 4
|
|
SetSkyBox(SKYBOX_ICY);
|
|
else if (GetLocalInt(oMod, "iValenStage3") == 1) // 5
|
|
SetSkyBox(SKYBOX_WINTER_CLEAR);
|
|
// no variable is saved, which means they want to remove the skybox
|
|
else
|
|
SetSkyBox(SKYBOX_NONE);
|
|
|
|
// delete the variables so they don't conflict next time
|
|
DeleteLocalInt(oMod, "iValenStage1");
|
|
DeleteLocalInt(oMod, "iValenStage2");
|
|
DeleteLocalInt(oMod, "iValenStage3");
|
|
}
|