PDA

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



Salmo
Mar-24-2014, 05:25
Wolverine asked for it, here it is. Returns wind direction as specified in mission file.



public double GetWindAngleDegrees(string missionfile)
{
// --------------------------------------------------------------------
// Get the wind angle (in degrees) from the mission file
// --------------------------------------------------------------------
// example mis file line - Power -0.70 -0.25 0 .... Power x y z
// missionfile is the full path to the mission file
// Ref: https://www.eol.ucar.edu/content/wind-direction-quick-reference
// --------------------------------------------------------------------
System.IO.StreamReader file = new System.IO.StreamReader(missionfile); // open the mission file for processing
string line;
string key = "Power"; // we want to look for the "Power" line in the mission file
while ((line = file.ReadLine()) != null) // read mission file one line at a time
{
if (line.TrimStart().StartsWith(key)) // we found the 'Power' line in the mis file
{
string[] parts = line.Split(' '); // break the line up into parts
for (int i = 0; i < parts.GetLength(0); i++)
{
if (parts[i] != null && parts[i] != "" && parts[i] != key) // we've got the line parameters y & x
{
double DperR = 180 / Math.PI; // radians to degrees
// get meteorological wind coordinates, right handed with respect to an upward +Wmet.
double uMET = Convert.ToDouble(parts[i]); // 1st parameter is uMET; positive uMET is wind blowing to the East.
double vMET = Convert.ToDouble(parts[i + 1]); // 2nd parameter is vMET; positive vMET is wind blowing to the North.
double DirMET = Math.Atan2(-uMET, -vMET) * DperR; // get direction wind blowing FROM -180 to +180 as in game GUI
// the actual wind angle in degrees
Double WindAngleDegrees = DirMET;
if (DirMET < 0) WindAngleDegrees = 180 - Math.Abs(DirMET) + 180;

file.Close(); // close the mission file to processing

// troubleshoot negative values
if (WindAngleDegrees < 0 || WindAngleDegrees > 360)
{
Console.WriteLine("Windangledegrees invalid value " + WindAngleDegrees.ToString("##0.00") + "[GetWindAngleDegrees]");
}
return WindAngleDegrees; // return the wind angle in degrees
}
}
}
}
file.Close(); // close the mission file to processing
return -1; // default to minus 1 if we can't find the 'Power' line in the mis file
}

No.401_Wolverine
Mar-24-2014, 09:53
Lovely!

I've set up a TAB 4 menu item that allows you to contact the tower for wind conditions. Sometimes the sock's direction is hard to gauge and sometimes you can't even see the sock!

Maybe I'll even have a go at inventorying all the English airfield runway vectors. Set up a proximity to airfield condition for contacting towers and you can request the most appropriate runway for each field for take-off and land! Or even if there's no runway with an appropriate runway angle based on the wind direction, they could even report closed to general traffic.

Cheers Salmo!

No601_Swallow
Mar-26-2014, 08:14
Lovely!

I've set up a TAB 4 menu item that allows you to contact the tower for wind conditions. Sometimes the sock's direction is hard to gauge and sometimes you can't even see the sock!

Maybe I'll even have a go at inventorying all the English airfield runway vectors. Set up a proximity to airfield condition for contacting towers and you can request the most appropriate runway for each field for take-off and land! Or even if there's no runway with an appropriate runway angle based on the wind direction, they could even report closed to general traffic.

Cheers Salmo!

I got the runway headings for all runways (although the "open field" airfields like Hawkinge or Westhampnet are a bit more problematical) from Vo101_Tom's excellent airfield pdfs. I was able to stick them in a spreadsheet and - even with my limited mathematical ability and non-existent excel skills, was able to convert the headings to "runway angles" that the game seems to use. See: http://www.tangmerepilots.co.uk/NewForum/viewtopic.php?p=106725#p106725 and http://theairtacticalassaultgroup.com/forum/showthread.php?t=9358&p=103834&viewfull=1#post103834

I also, for what it's worth did a spreadsheet that will do the runway angle, and convert compass headings to ingame wind angles. It's also got the list of runways on it. It's embarrassingly hamfisted as an excel sheet, but it does seem to work. It's here: https://app.box.com/s/t16fir7u5od7oif369mx

Edit: I've found a runway that's a degree out! One of the runways at Eastchurch. It's either the spreadsheet or (more likely) the original data from the airfield pdfs. It just shows, though, the need to check everything in clod!

No.401_Wolverine
Mar-26-2014, 12:58
Awesome. Thanks Swallow. I'll definitely check it out!

Ivank
Apr-01-2014, 21:44
Wolverine asked for it, here it is. Returns wind direction as specified in mission file.



public double GetWindAngleDegrees(string missionfile)
{
// --------------------------------------------------------------------
// Get the wind angle (in degrees) from the mission file
// --------------------------------------------------------------------
// example mis file line - Power -0.70 -0.25 0 .... Power x y z
// missionfile is the full path to the mission file
// Ref: https://www.eol.ucar.edu/content/wind-direction-quick-reference
// --------------------------------------------------------------------
System.IO.StreamReader file = new System.IO.StreamReader(missionfile); // open the mission file for processing
string line;
string key = "Power"; // we want to look for the "Power" line in the mission file
while ((line = file.ReadLine()) != null) // read mission file one line at a time
{
if (line.TrimStart().StartsWith(key)) // we found the 'Power' line in the mis file
{
string[] parts = line.Split(' '); // break the line up into parts
for (int i = 0; i < parts.GetLength(0); i++)
{
if (parts[i] != null && parts[i] != "" && parts[i] != key) // we've got the line parameters y & x
{
double DperR = 180 / Math.PI; // radians to degrees
// get meteorological wind coordinates, right handed with respect to an upward +Wmet.
double uMET = Convert.ToDouble(parts[i]); // 1st parameter is uMET; positive uMET is wind blowing to the East.
double vMET = Convert.ToDouble(parts[i + 1]); // 2nd parameter is vMET; positive vMET is wind blowing to the North.
double DirMET = Math.Atan2(-uMET, -vMET) * DperR; // get direction wind blowing FROM -180 to +180 as in game GUI
// the actual wind angle in degrees
Double WindAngleDegrees = DirMET;
if (DirMET < 0) WindAngleDegrees = 180 - Math.Abs(DirMET) + 180;

file.Close(); // close the mission file to processing

// troubleshoot negative values
if (WindAngleDegrees < 0 || WindAngleDegrees > 360)
{
Console.WriteLine("Windangledegrees invalid value " + WindAngleDegrees.ToString("##0.00") + "[GetWindAngleDegrees]");
}
return WindAngleDegrees; // return the wind angle in degrees
}
}
}
}
file.Close(); // close the mission file to processing
return -1; // default to minus 1 if we can't find the 'Power' line in the mis file
}


So how does one use this in game and what does it actually look like in game when it gives the wind speed and direction ?

No.401_Wolverine
Apr-02-2014, 12:22
It simply returns the direction, in compass degrees, where the wind is coming from. Ie, the heading you should best take to take off into the wind.

I've added a rounding function to it to make sure it only gives degrees in 10s like a real wind heading is given (you don't get a heading of 83.5 for example).

So when I call my tab 4-1 menu to 'Get Wind Conditions' this script, in concert with Salmo's code for getting the beaufort scale wind will end up replying to the player something like this
"This is the tower. Wind is currently gentle (3m/s) coming from 80 degrees."

So you take off on a heading as close to 80 degrees as you can manage. We've tested it. It works well. Windsock registers the same wind direction, though there may be a 10degree magnetic variance for some reason between these.

I'm thinking of changing it so that it can also give you a directional reference instead of degrees as an option, ie. '... coming from the East'. or both '... coming from the East (80degrees).'

Ivank
Apr-04-2014, 17:56
Great stuff .... so how do you incorporate this ?