Re: /rain
Posted: Fri Dec 07, 2012 4:33 pm
I needed a break from home improvements, so I thought I'd tackle adding dynamic weather to the zones. I'm posting this as a review, because I am 99% certain I am forgetting something - or designing this badly. I'm not done yet, but this is the direction I am going.
First, I made 4 new rules, this first one being the ZoneServer Timer for how often to check for weather changes (every minute)
These rules are the min/max weather severity per zone, along with how often the weather changes and by how much per change interval
For example, it's a sunny day in Commonlands. Weather is checked every minute. At 3:15pm, a WeatherChangeChance is rolled, and if passed, a weather change is triggered. Since MinWeatherSeverity = 0.5, that's where we start out... the clouds roll in. Every 15 mins after that, the weather increases in severity by 0.1 until it reaches MaxWeatherSeverity.
The weather stays at this (max) setting until the WeatherChangeChance tells it to start going in the reverse direction.
In ZoneServer::Process() I added:
The new function will do all the work:
(right now this is a very simple example, as I have yet to test any of this)
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
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