Jump to content
Sign in to follow this  
drgullen

drgullen's Weather Configuration

Recommended Posts

I have played around with the weather configuration quite a bit lately and have had a lot of success with it.  I've seen a lot of posts on here, on Steam and other sites on the Internet asking "Why is it always raining on this server?"  I have figured out the main reason why.  It is mostly related to this line in the init.c file:

    weather.GetRain().SetForecastChangeLimits(0.0, 0.1);

What that says essentially is change the weather either not at all or by no more than 10%.  So, depending on what you have the forecast time limits set to, if they are high (meaning the weather doesn't change that often) and it's already raining and you have the limits set to a value similar to this, it's gonna rain for a long, long time.  That second value there, the 0.1, needs to be 1.0 so that the rain can stop with a single change.

So, I've coded a little configuration section that you would put at the top of your init.c file to control the weather on your server exactly as you like.  I've placed a lot of comments in the code, so I won't repeat myself here, but essentially all you have to change are 5 variables to get exactly the weather you want on your server.  I've included a spot to set the exact date and time for your server as well.  As is, the code defaults to basically no weather at all, just clear skies and a random amount of wind, so if you want clouds and/or rain and/or fog and/or storms, change the appropriate value.

Here's the code for the init.c:

void main()
{
	//INIT ECONOMY--------------------------------------
	Hive ce = CreateHive();
	if ( ce )
		ce.InitOffline();
	
    Weather weather = g_Game.GetWeather();

    weather.MissionWeather(true);  // leave this set to true if you are about to configure the weather here in the init.c

	// drgullen's Weather Configuration
	// ================================
	// Change the 5 integer values down below (CloudCover, POP, ReallyFoggy, Thunderstorm and TimeChange) to control the weather on your server.
	//
	// CloudCover: The percentage of the sky that might be covered in clouds (0 = Clear sky all day; 100 = Potential for completely overcast)
	// POP: The probability of precipitation as a percentage (0 = No Rain all day; 100 = Will definitely rain at some point, but not constantly)
	// (Note: Set CloudCover and/or POP to -1 for a random amount of clouds and rain to start with that will change over time)
	// ReallyFoggy: Set the chance of fog occuring (-1 = Never any fog; 0 = Chance of some fog; 1 = Very foggy; 2 = Extremely foggy)
	// Thunderstorm: The percentage chance that lightning and thunder will accompany the rain (0 = No Chance; 100 = Storm always present if raining)
	// TimeChange: The minimum number of seconds until the weather changes (the maximum will be up to twice as long as this number) (Default is 300 which is 5 minutes)
	//
	// Examples
	// ========
	// If you want it to eventually be cloudy, perhaps completely overcast over time, but with no rain at all and maybe some fog, set them like this:
	// CloudCover = 100; POP = 0; ReallyFoggy = 0; Thunderstorm = 0
	//
	// If you want no clouds and no rain, but a very foggy day:
	// CloudCover = 0; POP = 0; ReallyFoggy = 1; Thunderstorm = 0
	//
	// If you want the chance of some clouds, rain and the slight chance of a storm, but no fog:
	// CloudCover = 50; POP = 30; ReallyFoggy = -1; Thunderstorm = 10
	//
	// If you want a random chance of clouds and rain (could still result in clear skies), but no chance of storms or fog:
	// CloudCover = -1; POP = -1; ReallyFoggy = -1; Thunderstorm = 0
	//
	// If you want the most extreme weather possible, with lots of clouds, rain, storms and fog:
	// CloudCover = 100; POP = 100; ReallyFoggy = 2; Thunderstorm = 100
	//
	// If you want basically no weather at all, just always clear skies (THIS WAS THE DEFAULT SETTING FROM THE POST ON THE FORUM):
	// CloudCover = 0; POP = 0; ReallyFoggy = -1; Thunderstorm = 0
	//
	// As for wind, a random maximum amount is generated down below.  You can change the higher number for a different maximum if you like.
	//
	// Keep in mind that it's the POP value that dictates if the weather engine will make it rain or not.
	// For example, you would think setting it to CloudCover = 0 and POP = 100 would result in clear skies,
	// but because you're asking for a 100% chance of rain there, it produces clouds to account for the rain.
	// For the sake of realism, if you want the chance of rain, the CloudCover value should be at least 50 or higher with POP at least 10 or higher.
	// Also remember that POP is a probability, meaning even with a value greater than 0, it still might not rain.  The closer to 100 you get, the more likely it will rain.
	//
	// The default for TimeChange is 300 which means the weather will change every 5 to 10 minutes.
	// If you wanted it to change on average about every 45 minutes, you would change this number to 1800, meaning it would change every 30 to 60 minutes.
	// If you wanted it to change on average about every 2 minutes, you would change this number to 90, meaning it would change every 1.5 to 3 minutes.
	//
	// IMPORTANT NOTE: Remember that the weather changes slowly over time.  No matter what you set these values to, it may take a few cycles of changing weather
	// for it to look as you've requested it here.  So, if you set it for rain and there isn't a cloud in the sky, give it 2 or 3 change cycles before thinking there's an issue.
	// It's the same the other way around -- if it's raining now and you set your POP to 30, it'll stop raining shortly and then may go hours without raining again.
	//
	// ==================================================== CHANGE THE 5 VARIABLES BELOW TO CONTROL THE WEATHER =================================================================
	int CloudCover = 0;
	int POP = 0;
	int ReallyFoggy = -1;
	int Thunderstorm = 0;
	int TimeChange = 300;
	// ==================================================== CHANGE THE 5 VARIABLES ABOVE TO CONTROL THE WEATHER =================================================================

	float rndMinOvercast;
	float rndMaxOvercast;
	float rndMaxRain;
	float rndMinFog;
	float rndMaxFog;
	float rndTS = (Thunderstorm / 100);

	if ( POP == -1 )
	{
		rndMaxRain = Math.RandomFloat( 0.0, 1.0 );
	}
	else
	{
		rndMaxRain = (POP / 100);
	}
	if ( rndMaxRain > 0.3 )
	{
		rndMinOvercast = Math.RandomFloat( 0.4, 1.0 );
		rndMaxOvercast = 1.0;
	}
	else if ( CloudCover == -1 )
	{
		rndMinOvercast = 0.0
		rndMaxOvercast = Math.RandomFloat( 0.0, 1.0 );
	}
	else
	{
		rndMinOvercast = 0.0
		rndMaxOvercast = (CloudCover / 100);
	}
	if ( ReallyFoggy == -1 )
	{
		rndMinFog = 0.0;
		rndMaxFog = 0.0;
	}
	else if ( ReallyFoggy == 2 )
	{
		rndMinFog = 0.9;
		rndMaxFog = 1.0;
	}
	else if ( ReallyFoggy == 1 )
	{
		rndMinFog = 0.6;
		rndMaxFog = 1.0;
	}
	else
	{
		rndMinFog = 0.0;
		rndMaxFog = 1.0;
	}
    weather.GetOvercast().SetLimits(rndMinOvercast, rndMaxOvercast);	
    weather.GetRain().SetLimits(0.0, rndMaxRain);
    weather.GetFog().SetLimits(rndMinFog, rndMaxFog);

    weather.GetOvercast().SetForecastChangeLimits(0.1, 0.25);
    weather.GetRain().SetForecastChangeLimits(0.25, 1.0);
    weather.GetFog().SetForecastChangeLimits(0.0, 0.1);

    weather.GetOvercast().SetForecastTimeLimits(TimeChange, TimeChange * 2);
    weather.GetRain().SetForecastTimeLimits(TimeChange, TimeChange * 2);
    weather.GetFog().SetForecastTimeLimits(TimeChange, TimeChange * 2);

    weather.GetOvercast().Set(Math.RandomFloatInclusive(0.0, 0.0), 0, 0);
    weather.GetRain().Set(Math.RandomFloatInclusive(0.0, 0.0), 0, 0);
    weather.GetFog().Set(Math.RandomFloatInclusive(0.0, 0.0), 0, 0);

	// Change the second number on the next line for a different maximum possible wind value (THE DEFAULT ON THE FORUM POST WAS 50).
	int WindMax = Math.RandomInt( 0, 50 );

    weather.SetWindMaximumSpeed(WindMax);
	weather.SetStorm(rndTS,rndTS,TimeChange);

	int year, month, day, hour, minute;

	year = 2023;
	month = 05;
	day = 06;
	hour = 6;
	minute = 0;
	
	GetGame().GetWorld().SetDate( year, month, day, hour, minute );
}

 

Give that a try and let me know how it goes for you.  If you have any questions about this, feel free to post them here.

Hopefully now, it stops f****** raining on your server! lol

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×