private void WindDirWriteTimer_Tick(object sender, EventArgs e) { try { this.fsuipcDirWrite.Value = GeoClass.BearingAdd(GeoClass.BearingAdd(GeoClass.BearingAdd(this._wind.dirWrite, this._windgusts.dir), this._windvar.dir), this._wind.magVar); } catch { } }
public string WxInject(Microsoft.FlightSimulator.SimConnect.SimConnect simconnect, List <WxGridClass.wxStruct> wxGrid, Form1.dataPosStruct acPos, string type, double radius, int maxstations, uint seconds, bool firstInject) { List <WxGridClass.wxStruct> source1 = new List <WxGridClass.wxStruct>(); WxGridClass.wxStruct wxStruct1 = new WxGridClass.wxStruct(); bool flag1 = false; bool flag2 = false; int num1 = 0; int millisecondsTimeout = 0; string str1 = (string)this._regKeys.GetValue("EzdokGlobalEnable"); string str2 = "Injection mode: " + type + " - "; foreach (WxGridClass.wxStruct wxStruct2 in wxGrid) { WxGridClass.wxStruct wxStruct3 = wxStruct2; wxStruct3.dist_from_ac = GeoClass.Dist(acPos.lat, acPos.lon, (double)wxStruct2.lat, (double)wxStruct2.lon); if (wxStruct3.dist_from_ac <= radius) { source1.Add(wxStruct3); } } List <WxGridClass.wxStruct> source2 = source1.OrderBy <WxGridClass.wxStruct, double>((Func <WxGridClass.wxStruct, double>)(o => o.dist_from_ac)).ToList <WxGridClass.wxStruct>(); if (!(type == "ovconly")) { if (!(type == "ovcdist")) { if (!(type == "ovctime")) { if (!(type == "ovcgrnd")) { if (!(type == "all")) { return("Invalid injection type"); } flag1 = true; flag2 = true; millisecondsTimeout = 5000; } else { num1 = 1; foreach (WxGridClass.wxStruct wxStruct2 in source2) { str2 = str2 + wxStruct2.station_id + " nearby - "; Regex regex = new Regex("\\b[345678](AS|CU)(\\d\\d\\d)", RegexOptions.Compiled); if (regex.Matches(wxStruct2.sky_fsx_smooth).Count > 0 && Convert.ToInt32(regex.Match(wxStruct2.sky_fsx_smooth).Groups[2].Value) < 100) { str2 = str2 + regex.Match(wxStruct2.sky_fsx_smooth).Groups[0].ToString() + " - "; flag1 = true; flag2 = false; millisecondsTimeout = 0; break; } } } } else { num1 = 1; double num2 = (double)GeoClass.BearingSub((int)acPos.hdg, 100); double num3 = (double)GeoClass.BearingAdd((int)acPos.hdg, 100); foreach (WxGridClass.wxStruct wxStruct2 in source2) { double num4 = GeoClass.DegreeBearing(acPos.lat, acPos.lon, (double)wxStruct2.lat, (double)wxStruct2.lon); if (num3 > num2 && num4 >= num2 && num4 <= num3 || num3 < num2 && (num4 >= num2 || num4 <= num3)) { str2 = str2 + wxStruct2.station_id + " ahead - "; Regex regex = new Regex("\\b[345678](AS|CU)(\\d\\d\\d)", RegexOptions.Compiled); if (regex.Matches(wxStruct2.sky_fsx_smooth).Count > 0 && Convert.ToInt32(regex.Match(wxStruct2.sky_fsx_smooth).Groups[2].Value) < 100) { str2 = str2 + regex.Match(wxStruct2.sky_fsx_smooth).Groups[0].ToString() + " - "; flag1 = true; flag2 = false; millisecondsTimeout = 0; break; } } } } } else { num1 = 1; double num2 = (double)GeoClass.BearingSub((int)acPos.hdg, 100); double num3 = (double)GeoClass.BearingAdd((int)acPos.hdg, 100); foreach (WxGridClass.wxStruct wxStruct2 in source2) { double num4 = GeoClass.DegreeBearing(acPos.lat, acPos.lon, (double)wxStruct2.lat, (double)wxStruct2.lon); if (num3 > num2 && num4 >= num2 && num4 <= num3 || num3 < num2 && (num4 >= num2 || num4 <= num3)) { str2 = str2 + wxStruct2.station_id + " ahead - "; Regex regex = new Regex("\\b[5678](AS|CU)(\\d\\d\\d)", RegexOptions.Compiled); if (regex.Matches(wxStruct2.sky_fsx_smooth).Count > 0 && Convert.ToInt32(regex.Match(wxStruct2.sky_fsx_smooth).Groups[2].Value) < 100) { str2 = str2 + regex.Match(wxStruct2.sky_fsx_smooth).Groups[0].ToString() + " - "; flag1 = true; flag2 = false; millisecondsTimeout = 0; break; } } } } } else { List <WxGridClass.wxStruct> wxStructList = new List <WxGridClass.wxStruct>(); num1 = 1; double num2 = (double)GeoClass.BearingSub((int)acPos.hdg, 100); double num3 = (double)GeoClass.BearingAdd((int)acPos.hdg, 100); foreach (WxGridClass.wxStruct wxStruct2 in source2) { double num4 = GeoClass.DegreeBearing(acPos.lat, acPos.lon, (double)wxStruct2.lat, (double)wxStruct2.lon); if (num3 > num2 && num4 >= num2 && num4 <= num3 || num3 < num2 && (num4 >= num2 || num4 <= num3)) { str2 = str2 + wxStruct2.station_id + " ahead - "; Regex regex = new Regex("\\b[5678](AS|CU)(\\d\\d\\d)", RegexOptions.Compiled); if (regex.Matches(wxStruct2.sky_fsx_smooth).Count > 0 && Convert.ToInt32(regex.Match(wxStruct2.sky_fsx_smooth).Groups[2].Value) < 100) { str2 = str2 + regex.Match(wxStruct2.sky_fsx_smooth).Groups[0].ToString() + " - "; flag1 = true; flag2 = false; millisecondsTimeout = 0; wxStructList.Add(wxStruct2); } } } source2.Clear(); source2 = wxStructList; } int num5 = 0; foreach (WxGridClass.wxStruct wxStruct2 in source2) { if (!this._createdWxStations.Contains(wxStruct2.station_id)) { simconnect.WeatherCreateStation((Enum)Form1.DATA_REQUESTS.WEATHERSTATIONNEW, wxStruct2.station_id, wxStruct2.station_id, wxStruct2.lat, wxStruct2.lon, (float)(wxStruct2.elevation_m + 60)); this._createdWxStations.Add(wxStruct2.station_id); this._removedWxStations.Remove(wxStruct2.station_id); ++num5; } } string str3 = str2 + num5.ToString() + " new stations created - "; if (str1 == "" | firstInject) { flag2 = false; } if (flag1) { if (flag2) { Process.Start(this._ezdokExe); str3 += "EZdok disabled - "; } if (source2.Count > maxstations) { source2 = source2.GetRange(0, maxstations); } List <WxGridClass.wxStruct> list = source2.OrderBy <WxGridClass.wxStruct, string>((Func <WxGridClass.wxStruct, string>)(o => o.station_id)).ToList <WxGridClass.wxStruct>(); for (int index = 0; index <= num1; ++index) { num5 = 0; foreach (WxGridClass.wxStruct wxStruct2 in list) { simconnect.WeatherSetObservation(seconds, wxStruct2.fsx); ++num5; } } if (flag2) { Thread.Sleep(millisecondsTimeout); Process.Start(this._ezdokExe); } } string str4 = str3 + num5.ToString() + " stations injected" + (num1 > 0 ? " - " + num1.ToString() + " repeats" : ""); simconnect.WeatherSetDynamicUpdateRate(0U); return(str4); }
public void CollectWindData(WxGridClass wxGridObj) { try { Random random = new Random(); List <WxGridClass.wxStruct> wxStructList = new List <WxGridClass.wxStruct>(); List <WxGridClass.wxStruct> wxData = wxGridObj.FetchWxDataNearest(wxGridObj.wxGrid, this._acPos.lat, this._acPos.lon, 4); if (wxData.Count <= 0) { return; } this._acPos.altGnd = Math.Max(this.fsuipcAlt.Value - (double)this.fsuipcGndAlt.Value, 0.0) * 3.28; this._acPos.lat = this.fsuipcLat.Value; this._acPos.lon = this.fsuipcLon.Value; double num1 = (double)this.fsuipcCloudTurb.Value; double num2 = (double)this.fsuipcWindTurb.Value; if (num1 == 0.0) { this._windinfo.turbCloudStrength = 0.0; } else if (num1 == 72.0) { this._windinfo.turbCloudStrength = 1.0; } else if (num1 == 144.0) { this._windinfo.turbCloudStrength = 2.0; } else if (num1 == 216.0) { this._windinfo.turbCloudStrength = 3.0; } else if (num1 == 252.0) { this._windinfo.turbCloudStrength = 4.0; } if (num2 == 0.0) { this._windinfo.turbWindStrength = 0.0; } else if (num2 == 64.0) { this._windinfo.turbWindStrength = 1.0; } else if (num2 == 128.0) { this._windinfo.turbWindStrength = 2.0; } else if (num2 == 192.0) { this._windinfo.turbWindStrength = 3.0; } else if (num2 == (double)byte.MaxValue) { this._windinfo.turbWindStrength = 4.0; } this._windinfo.var = wxData[0].wind_variance; this._windinfo.dirDiff = GeoClass.BearingDiffAbs(wxData[0].wind_dir_degrees, wxData[1].wind_dir_degrees); this._windinfo.gusts = wxData[0].wind_gusts; this._windinfo.vrb = wxData[0].wind_vrb; this._windinfo.windSpdGnd = (double)wxData[0].winds_aloft_ext[0][3]; List <int[]> numArrayList1 = new List <int[]>(); WxGridClass.weightingStruct weighting = new WxGridClass.weightingStruct(); List <double> doubleList = new List <double>(); weighting.sum_dist = 0.0; weighting.sum_weights = 0.0; doubleList.Clear(); for (int index = 0; index < wxData.Count; ++index) { weighting.sum_dist += wxData[index].dist_from_ac; } for (int index = 0; index < wxData.Count; ++index) { doubleList.Add(1.0 - wxData[index].dist_from_ac / weighting.sum_dist); } weighting.sum_weights = doubleList.Sum(); List <int[]> numArrayList2 = wxGridObj.InterpolateWindsAloft(wxData, weighting, doubleList, 1.0, 1.0); int[] last = numArrayList2.FindLast((Predicate <int[]>)(n => (double)(n[0] * 100) <= Math.Max(0.0, this._acPos.altGnd))); int[] numArray = numArrayList2.Find((Predicate <int[]>)(n => (double)(n[0] * 100) > Math.Max(1.0, this._acPos.altGnd))); this._wind.spd = Math.Round(((double)numArray[3] - (double)last[3]) / ((double)numArray[0] - (double)last[0]) * (Math.Max(0.0, this._acPos.altGnd) / 100.0 - (double)last[0]) + (double)last[3]); if (GeoClass.BearingDiff(numArray[2], last[2]) <= 180) { int num3 = GeoClass.BearingDiff(numArray[2], last[2]); this._wind.dir = (double)GeoClass.BearingAdd(last[2], (int)Math.Round((Math.Max(0.0, this._acPos.altGnd) / 100.0 - (double)last[0]) / ((double)numArray[0] - (double)last[0]) * (double)num3)); } else { int num3 = 360 - GeoClass.BearingDiff(numArray[2], last[2]); this._wind.dir = (double)GeoClass.BearingAdd(numArray[2], (int)Math.Round((Math.Max(0.0, this._acPos.altGnd) / 100.0 - (double)last[0]) / ((double)numArray[0] - (double)last[0]) * (double)num3)); } WxGridClass.wxStruct wxStruct1 = new WxGridClass.wxStruct(); double num4 = 9999.0; WxGridClass.wxStruct wxStruct2 = new WxGridClass.wxStruct(); double num5 = 9999.0; WxGridClass.wxStruct wxStruct3 = new WxGridClass.wxStruct(); double num6 = 9999.0; WxGridClass.wxStruct wxStruct4 = new WxGridClass.wxStruct(); double num7 = 9999.0; if (wxData.Exists((Predicate <WxGridClass.wxStruct>)(i => i.station_id == wxGridObj.adep))) { wxStruct1 = wxData.Find((Predicate <WxGridClass.wxStruct>)(i => i.station_id == wxGridObj.adep)); num4 = wxStruct1.dist_from_ac; } if (wxData.Exists((Predicate <WxGridClass.wxStruct>)(i => i.station_id == wxGridObj.ades))) { wxStruct2 = wxData.Find((Predicate <WxGridClass.wxStruct>)(i => i.station_id == wxGridObj.ades)); num5 = wxStruct2.dist_from_ac; } if (wxData.Exists((Predicate <WxGridClass.wxStruct>)(i => i.station_id == wxGridObj.altn))) { wxStruct3 = wxData.Find((Predicate <WxGridClass.wxStruct>)(i => i.station_id == wxGridObj.altn)); num6 = wxStruct3.dist_from_ac; } if (num4 <= num5 && num4 <= num6) { wxStruct4 = wxStruct1; num7 = num4; } else if (num5 <= num4 && num5 <= num6) { wxStruct4 = wxStruct2; num7 = num5; } else if (num6 <= num4 && num6 <= num5) { wxStruct4 = wxStruct3; num7 = num6; } if (num7 <= 100.0) { double num3 = Math.Max(1.0 - num7 / 100.0, 0.0) * Math.Max(1.0 - this._acPos.altGnd / 10000.0, 0.0) * (double)GeoClass.BearingDiffAbs((int)this._wind.dir, wxStruct4.wind_dir_degrees); double num8 = Math.Max(1.0 - num7 / 100.0, 0.0) * Math.Max(1.0 - this._acPos.altGnd / 10000.0, 0.0) * ((double)wxStruct4.wind_speed_kt - this._wind.spd); this._wind.dir = GeoClass.BearingDiff((int)this._wind.dir, wxStruct4.wind_dir_degrees) <= 180 ? (this._wind.dir = (double)GeoClass.BearingSub((int)this._wind.dir, (int)num3)) : (this._wind.dir = (double)GeoClass.BearingAdd((int)this._wind.dir, (int)num3)); this._wind.spd = Math.Round(this._wind.spd + num8); } if (GeoClass.BearingDiffAbs(this._wind.dirLast, this._wind.dir) > 4.0) { this._wind.dir = GeoClass.BearingDiff(this._wind.dirLast, this._wind.dir) <= 180.0 ? GeoClass.BearingSub(this._wind.dirLast, 2.0) : GeoClass.BearingAdd(this._wind.dirLast, 2.0); } if (Math.Abs(this._wind.spdLast - this._wind.spd) > 4.0) { this._wind.spd = this._wind.spd > this._wind.spdLast ? this._wind.spdLast + 2.0 : this._wind.spdLast - 2.0; } this._wind.dirLast = this._wind.dir; this._wind.spdLast = this._wind.spd; this._wind.spdWrite = this._wind.spd; this._wind.dirWrite = this._wind.dir; } catch { } }