PDA

View Full Version : Sal's useful scripts [wind speed from mission file]



Salmo
Mar-09-2014, 06:08
With TF4.2 on the horizon it's going to be important for mission builders to let players know the wind speed in their mission. That's fine if you set your wind speed & direction & don't change it, but what if you want to change the weather later, or perhaps your generating random weather, wind etc. How do you find out the wind speed?

Here's a nifty little function to put in your script code. It look's at your specified mission file, finds the 'wind' line, reads it, & calculates the wind speed, then returns a descriptor string for you to put into HUD message or a custom (tab-4 menu) type display.



public string GetWindSpeed(string missionfile, string returntype = "Beaufort")
#region Get the wind speed from the mission file
{
// --------------------------------------------------------------------------------
// Purpose: Gets the wind speed from the specified mission file & returns wind speed
// in one of three different formats.
//
// Use: GetWindSpeed(Full/Path/To/My/Mission.mis, "parameter")
// where parameter is one of these:
// Beaufort -> returns a descriptive string consistent with the Beaufort wind scale eg. moderate
// Speed -> returns a string with the wind speed in metres per second eg. 4 m/s
// Both -> returns a string with both a Beaufort scale descripter & the wind speed in m/s eg. moderate (6 m/s)
//
// Example syntax: string ws = GetWindSpeed(Full/Path/To/My/Mission.mis, "Beaufort");
// string msg = "Currently " + ws + " winds"; // eg. Currently moderate winds
// GamePlay.gpHUDLogCenter(msg);
//
// Copyright Salmo 9-3-2014
// --------------------------------------------------------------------------------

string line = null; // holds each mission file line of text
try
{
System.IO.StreamReader file = new System.IO.StreamReader(missionfile); // open the mission file for processing
while ((line = file.ReadLine()) != null) // read mission file one line at a time
{
if (line.TrimStart().StartsWith("Power")) // find the 'Power" (wind) line in the mis file
{
line = line.Trim(); // remove any extra spaces in the line
line = line.Substring(5); // get the 3 Power line parameters

string[] parts = line.Trim().Split(' '); // break the parameter line into it's parts
double uMET = Convert.ToDouble(parts[0]); // remember 1st wind vector
double vMET = Convert.ToDouble(parts[1]); // remember 2nd wind vector

// calculate wind speed in m/s from the Power line parameters
// ref: https://www.eol.ucar.edu/content/wind-direction-quick-reference
double WindSpeed = Math.Sqrt(Math.Pow(uMET, 2) + Math.Pow(vMET, 2)); // wind speed is in m/s

// Beaufort wind scale
// see http://en.wikipedia.org/wiki/Beaufort_scale#Modern_scale
string strBreeze = "calm";
if (WindSpeed >= 20.7) strBreeze = "storm force";
if (WindSpeed < 20.7) strBreeze = "strong gale";
if (WindSpeed < 17.1) strBreeze = "gale";
if (WindSpeed < 13.8) strBreeze = "strong";
if (WindSpeed < 10.7) strBreeze = "fresh";
if (WindSpeed < 7.9) strBreeze = "moderate";
if (WindSpeed < 4.4) strBreeze = "gentle";
if (WindSpeed < 3.4) strBreeze = "light";
if (WindSpeed < 1.5) strBreeze = "light";
if (WindSpeed < 0.3) strBreeze = "calm";
file.Close(); // close the mission file to processing

// construct the specified output string
string result = strBreeze; // default output
if (returntype.Contains("eau")) result = strBreeze; // Beaufort scale descriptor output
if (returntype.Contains("eed")) result = WindSpeed.ToString("0") + " m/s"; // output in m/s
if (returntype.Contains("oth")) result = strBreeze + " (" + WindSpeed.ToString() + "m/s)"; // both beaufirt scal descriptor & m/s
return result; // return the wind speed output

}
}
file.Close(); // close the mission file to processing
return null;
}
catch { return null; }
}
#endregion

No601_Swallow
Mar-09-2014, 06:38
Great! :):-)

(Just gets better, this game! I'm all Clodded up this morning!)

ATAG_Lolsav
Mar-09-2014, 13:19
Salmo i have not tryed to implement this one yet, but ive come to think i better ask if its compatible with "random mission weather" script, because it has some parameters with wind there also. Since both scripts attempt to apply changes to the mission, isnt there the "danger" of scrambling evrything?

Salmo
Mar-09-2014, 18:11
Salmo i have not tryed to implement this one yet, but ive come to think i better ask if its compatible with "random mission weather" script, because it has some parameters with wind there also. Since both scripts attempt to apply changes to the mission, isnt there the "danger" of scrambling evrything?

There shouldn't be any compatibility issues. This script just reads the mission file, the random weather script reads & rewrites the mission file. I recommend running this script at the start of the mission to get the wind info, then running the random weather script after that. Otherwise this script will pick up the wind ffrom the 'next' random mission weather. Of course, this is just a functyion, it's not an entire script so it does not include the library directives, but I've given some example code in the function comments section.

No.401_Wolverine
Mar-23-2014, 22:13
I'm thinking you could probably update this to include getting wind direction as well. Have you attempted that, Salmo?

Salmo
Mar-24-2014, 05:27
I'm thinking you could probably update this to include getting wind direction as well. Have you attempted that, Salmo?

You mean like this.... http://theairtacticalassaultgroup.com/forum/showthread.php?t=9606&p=105888#post105888 :salute:

No.401_Wolverine
Mar-24-2014, 09:47
Very much so! Cheers, Salmo!


S!