First, I made 4 new rules, this first one being the ZoneServer Timer for how often to check for weather changes (every minute)
Code: Select all
RULE_INIT(R_Zone, WeatherTimer, "60000");Code: Select all
RULE_INIT(R_Zone, MinWeatherSeverity, "0.5");
RULE_INIT(R_Zone, MaxWeatherSeverity, "1.0");
RULE_INIT(R_Zone, WeatherChangeFrequency, "900000");
RULE_INIT(R_Zone, WeatherChangeInterval, "0.1");
RULE_INIT(R_Zone, WeatherChangeChance, "0.5");The weather stays at this (max) setting until the WeatherChangeChance tells it to start going in the reverse direction.
In ZoneServer::Process() I added:
Code: Select all
if(weatherTimer.Check())
ProcessWeather();Code: Select all
void ZoneServer::ProcessWeather()
{
LogWrite(ZONE__DEBUG, 0, "Zone", "Checking for weather changes in zone '%s' (id: %u)", zone_name, zoneID);
int32 weather_frequency = rule_manager.GetGlobalRule(R_Zone, WeatherChangeFrequency)->GetInt32();
LogWrite(ZONE__DEBUG, 0, "Zone", "Weather changes can only occur every %u seconds...", weather_frequency/1000);
// check frequency first, if it's time to change, then do the Chance roll
if( GetLastWeatherChange() <= (Timer::GetUnixTimeStamp() - weather_frequency) )
{
float weather_chance = rule_manager.GetGlobalRule(R_Zone, WeatherChangeChance)->GetFloat();
int8 weather_random = MakeRandomInt(0, weather_chance*100);
LogWrite(ZONE__DEBUG, 0, "Zone", "WeatherChangeChange: %2f, Random Roll: %i", weather_chance, weather_random);
if( weather_random <= weather_chance )
{
LogWrite(ZONE__DEBUG, 0, "Zone", "Changing weather in zone '%s' (id: %u)", zone_name, zoneID);
float minWeatherSeverity = rule_manager.GetGlobalRule(R_Zone, MinWeatherSeverity)->GetFloat();
float maxWeatherSeverity = rule_manager.GetGlobalRule(R_Zone, MaxWeatherSeverity)->GetFloat();
// this will be replaced by incremental weather changes eventually
float weather_severity = MakeRandomFloat(minWeatherSeverity, maxWeatherSeverity);
LogWrite(ZONE__DEBUG, 0, "Zone", "Random weather changed to %2f in zone '%s' (id: %u)", weather_severity, zone_name, zoneID);
this->SetRain(weather_severity);
SetLastWeatherChanged(Timer::GetUnixTimeStamp());
}
else
LogWrite(ZONE__DEBUG, 0, "Zone", "Random weather change delayed in zone '%s' (id: %u)", zone_name, zoneID);
}
else
LogWrite(ZONE__DEBUG, 0, "Zone", "Not yet time to change weather in zone '%s' (id: %u)", zone_name, zoneID);
}So, my question is --
Since each zone is instantiated separately, does that mean there is 1 weatherTimer.Check() per active zone, thus all the functions in ProcessWeather() will be restricted to that 1 zone? or do I have to start messing with Mutex and lists and crap? If so, this will quickly become above my head.
Wanted to get this out for opinions though. Jab, this is as simple as I could come up with