-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvSIDPlugin.cpp
More file actions
5794 lines (5021 loc) · 203 KB
/
vSIDPlugin.cpp
File metadata and controls
5794 lines (5021 loc) · 203 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "pch.h"
#include "vSIDPlugin.h"
#include "flightplan.h"
#include "timeHandler.h"
#include "messageHandler.h"
#include "area.h"
#include "Psapi.h"
#include <set>
#include <algorithm>
#include "display.h"
#include "airport.h"
#include "crashhandler.h"
// DEV
#include <thread>
#include <iostream> // for debugging in detectPlugins()
// END DEV
vsid::VSIDPlugin* vsidPlugin; // pointer needed for ES
vsid::VSIDPlugin::VSIDPlugin() : EuroScopePlugIn::CPlugIn(EuroScopePlugIn::COMPATIBILITY_CODE, pluginName.c_str(), pluginVersion.c_str(), pluginAuthor.c_str(), pluginCopyright.c_str()) {
this->detectPlugins();
this->configParser.loadMainConfig();
this->configParser.loadGrpConfig();
this->configParser.loadRnavList();
this->gsList = "STUP,PUSH,TAXI,DEPA";
/* takes over pointer control of vsidPlugin - no deletion needed for unloading*/
this->shared = std::shared_ptr<vsid::VSIDPlugin>(this);
messageHandler->setLevel("INFO");
RegisterTagItemType("SID", TAG_ITEM_VSID_SIDS);
RegisterTagItemFunction("Set/Reset suggested SID", TAG_FUNC_VSID_SIDS_AUTO);
RegisterTagItemFunction("SIDs Menu", TAG_FUNC_VSID_SIDS_MAN);
RegisterTagItemType("Departure Transition", TAG_ITEM_VSID_TRANS);
RegisterTagItemFunction("Transition Menu", TAG_FUNC_VSID_TRANS);
RegisterTagItemType("Initial Climb", TAG_ITEM_VSID_CLIMB);
RegisterTagItemFunction("Climb Menu", TAG_FUNC_VSID_CLMBMENU);
RegisterTagItemType("Departure Runway", TAG_ITEM_VSID_RWY);
RegisterTagItemFunction("Runway Menu", TAG_FUNC_VSID_RWYMENU);
RegisterTagItemType("Squawk", TAG_ITEM_VSID_SQW);
RegisterTagItemType("Request", TAG_ITEM_VSID_REQ);
RegisterTagItemFunction("Request Menu", TAG_FUNC_VSID_REQMENU);
RegisterTagItemType("Request Timer", TAG_ITEM_VSID_REQTIMER);
RegisterTagItemType("Cleared to land flag", TAG_ITEM_VSID_CTLF);
RegisterTagItemFunction("Set cleared to land flag", TAG_FUNC_VSID_CTL);
RegisterTagItemType("Cleared to land flag (local)", TAG_ITEM_VSID_CTLF_LOCAL);
RegisterTagItemFunction("Set cleared to land flag (local)", TAG_FUNC_VSID_CTL_LOCAL);
RegisterTagItemType("Clearance received flag (CRF)", TAG_ITEM_VSID_CLR);
RegisterTagItemFunction("Set CRF and SID", TAG_FUNC_VSID_CLR_SID);
RegisterTagItemFunction("Set CRF, SID and Startup state", TAG_FUNC_VSID_CLR_SID_SU);
RegisterTagItemType("Intersection", TAG_ITEM_VSID_INTS);
RegisterTagItemFunction("Set runway intersection", TAG_FUNC_VSID_INTS_SET);
RegisterTagItemFunction("Select runway intersection as able", TAG_FUNC_VSID_INTS_ABLE);
RegisterTagItemFunction("Auto-Assign Squawk (TopSky)", TAG_FUNC_VSID_TSSQUAWK);
this->loadEse(); // load and parse ese file
UpdateActiveAirports(); // preload rwy settings
if (curl_global_init(CURL_GLOBAL_DEFAULT) != 0)
messageHandler->writeMessage("ERROR", "Failed to init curl_global");
else this->curlInit = true;
DisplayUserMessage("Message", "vSID", std::string("Version " + pluginVersion + " loaded").c_str(), true, true, false, false, false);
}
vsid::VSIDPlugin::~VSIDPlugin()
{
messageHandler->writeMessage("DEBUG", "VSIDPlugin destroyed.", vsid::MessageHandler::DebugArea::Menu);
};
/*
* BEGIN OWN FUNCTIONS
*/
void vsid::VSIDPlugin::detectPlugins()
{
HMODULE hmods[1024];
HANDLE hprocess;
DWORD cbneeded;
unsigned int i;
hprocess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, GetCurrentProcessId());
if (hprocess == NULL) return;
if (EnumProcessModules(hprocess, hmods, sizeof(hmods), &cbneeded))
{
for (i = 0; i < (cbneeded / sizeof(HMODULE)); i++)
{
TCHAR szModName[MAX_PATH];
if (GetModuleFileNameEx(hprocess, hmods[i], szModName, sizeof(szModName) / sizeof(TCHAR)))
{
std::string modname = vsid::utils::tolower(szModName);
//if (modname == "CCAMS.dll")
if (modname.find("ccams.dll") != std::string::npos)
{
this->ccamsLoaded = true;
}
//if (modname == "TopSky.dll")
if (modname.find("topsky.dll") != std::string::npos)
{
this->topskyLoaded = true;
}
}
}
}
CloseHandle(hprocess);
}
std::string vsid::VSIDPlugin::findSidWpt(EuroScopePlugIn::CFlightPlan FlightPlan)
{
std::string callsign = FlightPlan.GetCallsign();
std::string adep = FlightPlan.GetFlightPlanData().GetOrigin();
std::string filedSid = FlightPlan.GetFlightPlanData().GetSidName();
std::vector<std::string> filedRoute = vsid::utils::split(FlightPlan.GetFlightPlanData().GetRoute(), ' ');
if (filedRoute.size() == 0) return "";
if (!this->activeAirports.contains(adep)) return "";
if (filedSid != "")
{
std::string esWpt = filedSid.substr(0, filedSid.length() - 2);
for (const vsid::Sid& sid : this->activeAirports[adep].sids)
{
if (esWpt == sid.waypoint && std::any_of(filedRoute.begin(), filedRoute.end(), [&](std::string wpt)
{
try
{
if (esWpt == vsid::utils::split(wpt, '/').at(0)) return true;
else return false;
messageHandler->removeFplnError(callsign, ERROR_FPLN_SIDWPT);
}
catch (std::out_of_range)
{
if (!messageHandler->getFplnErrors(callsign).contains(ERROR_FPLN_SIDWPT))
{
messageHandler->writeMessage("ERROR", "[" + callsign +
"] Failed to split waypoint during SID waypoint checking. Waypoint was: " + wpt +
". Code: " + ERROR_FPLN_SIDWPT);
messageHandler->addFplnError(callsign, ERROR_FPLN_SIDWPT);
}
return false;
}
})) return esWpt;
}
}
// continue checks if esWpt hasn't been returned
std::set<std::string> sidWpts = {};
for (const vsid::Sid &sid : this->activeAirports[adep].sids)
{
if(sid.waypoint != "XXX") sidWpts.insert(sid.waypoint);
for (auto& [base, _] : sid.transition)
{
sidWpts.insert(base);
}
}
for (std::string &wpt : filedRoute)
{
if (wpt.find("/") != std::string::npos)
{
try
{
wpt = vsid::utils::split(wpt, '/').at(0);
messageHandler->removeFplnError(callsign, ERROR_FPLN_SIDWPT);
}
catch (std::out_of_range)
{
if (!messageHandler->getFplnErrors(callsign).contains(ERROR_FPLN_SIDWPT))
{
messageHandler->writeMessage("ERROR", "[" + callsign + "] Failed to get the waypoint of a waypoint"
" and speed/level group. Waypoint is: " + wpt + ". Code: " + ERROR_FPLN_SIDWPT);
messageHandler->addFplnError(callsign, ERROR_FPLN_SIDWPT);
}
}
}
if (std::any_of(sidWpts.begin(), sidWpts.end(), [&](std::string sidWpt)
{
return sidWpt == wpt;
}))
{
return wpt;
}
}
return "";
}
vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, std::string atcRwy)
{
EuroScopePlugIn::CFlightPlanData fplnData = FlightPlan.GetFlightPlanData();
std::string icao = fplnData.GetOrigin();
std::string dest = fplnData.GetDestination();
std::string callsign = FlightPlan.GetCallsign();
std::vector<std::string> filedRoute = vsid::utils::split(std::string(fplnData.GetRoute()), ' ');
std::string sidWpt = vsid::VSIDPlugin::findSidWpt(FlightPlan);
vsid::Sid setSid = {};
int prio = 99;
bool customRuleActive = false;
std::set<std::string> wptRules = {};
std::set<std::string> actTSid = {};
bool validEquip = true;
if (!this->activeAirports.contains(icao))
{
messageHandler->writeMessage("DEBUG", "[" + icao + "] is not an active airport. Skipping all SID checks", vsid::MessageHandler::DebugArea::Sid);
return vsid::Sid();
}
std::set<std::string> depRwys = this->activeAirports[icao].depRwys; // dep rwys to merge with arr rwys if needed
// determine if a rule is active
if (this->activeAirports[icao].customRules.size() > 0)
{
customRuleActive = std::any_of(
this->activeAirports[icao].customRules.begin(),
this->activeAirports[icao].customRules.end(),
[](auto item)
{
return item.second;
}
);
}
if (customRuleActive) // #evaluate - arrrwy check for areas below ~ 325
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] [" + icao +
"] Custom rules active. Checking for avbl areas and possible arr as dep rwys.",
vsid::MessageHandler::DebugArea::Sid);
std::map<std::string, bool> customRules = this->activeAirports[icao].customRules;
for (auto it = this->activeAirports[icao].sids.begin(); it != this->activeAirports[icao].sids.end();)
{
if (it->customRule == "" ||
(this->activeAirports[icao].customRules.contains(it->customRule) &&
!this->activeAirports[icao].customRules[it->customRule]))
{
++it; continue;
}
if (it->area != "")
{
for (std::string area : vsid::utils::split(it->area, ','))
{
if (this->activeAirports[icao].areas.contains(area) &&
this->activeAirports[icao].areas[area].isActive &&
this->activeAirports[icao].areas[area].arrAsDep)
{
std::set<std::string> arrRwys = this->activeAirports[icao].arrRwys;
depRwys.merge(arrRwys);
}
}
}
++it;
}
}
// determining "night" SIDs (any SID with a set time frame)
if (this->activeAirports[icao].settings["time"] &&
this->activeAirports[icao].timeSids.size() > 0 &&
std::any_of(this->activeAirports[icao].timeSids.begin(),
this->activeAirports[icao].timeSids.end(),
[&](auto item)
{
return sidWpt == item.waypoint;
}
))
{
for (const vsid::Sid& sid : this->activeAirports[icao].timeSids)
{
if (sid.waypoint != sidWpt) continue;
if (vsid::time::isActive(this->activeAirports[icao].timezone, sid.timeFrom, sid.timeTo))
{
actTSid.insert(sid.waypoint);
}
}
}
// include atc set rwy if present as dep rwy
std::string actAtcRwy = "";
if (atcRwy != "" && this->processed.contains(callsign) && this->processed[callsign].atcRWY) actAtcRwy = atcRwy;
else if (atcRwy != "" && !this->processed.contains(callsign) &&
this->activeAirports[icao].settings["auto"] &&
(vsid::fplnhelper::findRemarks(FlightPlan, "VSID/RWY") || fplnData.IsAmended())) actAtcRwy = atcRwy;
for (vsid::Sid& currSid : this->activeAirports[icao].sids)
{
if (actAtcRwy != "") depRwys.insert(actAtcRwy);
// skip if current SID does not match found SID wpt
if (currSid.transition.empty() && currSid.waypoint != sidWpt && currSid.waypoint != "XXX") continue;
else if (!currSid.transition.empty() && !currSid.transition.contains(sidWpt)) continue;
bool rwyMatch = false;
bool restriction = false;
validEquip = true;
// checking areas for arrAsDep - actual area evaluation down below
if (currSid.area != "")
{
std::vector<std::string> sidAreas = vsid::utils::split(currSid.area, ',');
if (std::any_of(sidAreas.begin(), sidAreas.end(), [&](auto sidArea) // #evaluate - wrong areas might result in an arr rwy becoming dep rwy
{
if (this->activeAirports[icao].areas.contains(sidArea) &&
this->activeAirports[icao].areas[sidArea].isActive &&
this->activeAirports[icao].areas[sidArea].inside(FlightPlan.GetFPTrackPosition().GetPosition()))
{
return true;
}
else return false;
}))
{
for (std::string& area : sidAreas)
{
if (this->activeAirports[icao].areas.contains(area) && this->activeAirports[icao].areas[area].arrAsDep)
{
std::set<std::string> arrRwys = this->activeAirports[icao].arrRwys;
depRwys.merge(arrRwys);
}
}
}
}
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Checking SID \"" + currSid.idName() + "\"", vsid::MessageHandler::DebugArea::Sid);
// skip if SID needs active arr rwys
if (!currSid.actArrRwy.empty())
{
if (currSid.actArrRwy.contains("allow"))
{
if (currSid.actArrRwy["allow"]["all"] != "")
{
std::vector<std::string> actArrRwy = vsid::utils::split(currSid.actArrRwy["allow"]["all"], ',');
if (!std::all_of(actArrRwy.begin(), actArrRwy.end(), [&](std::string rwy)
{
if (this->activeAirports[icao].arrRwys.contains(rwy)) return true;
else return false;
}))
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() +
"\" because not all of the required arr Rwys are active",
vsid::MessageHandler::DebugArea::Sid
);
continue;
}
}
else if (currSid.actArrRwy["allow"]["any"] != "")
{
std::vector<std::string> actArrRwy = vsid::utils::split(currSid.actArrRwy["allow"]["any"], ',');
if (std::none_of(actArrRwy.begin(), actArrRwy.end(), [&](std::string rwy)
{
if (this->activeAirports[icao].arrRwys.contains(rwy)) return true;
else return false;
}))
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" +
currSid.idName() + "\" because none of the required arr rwys are active",
vsid::MessageHandler::DebugArea::Sid
);
continue;
}
}
}
if (currSid.actArrRwy.contains("deny"))
{
if (currSid.actArrRwy["deny"]["all"] != "")
{
std::vector<std::string> actArrRwy = vsid::utils::split(currSid.actArrRwy["deny"]["all"], ',');
if (std::all_of(actArrRwy.begin(), actArrRwy.end(), [&](std::string rwy)
{
if (this->activeAirports[icao].arrRwys.contains(rwy)) return true;
else return false;
}))
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() +
"\" because all of the forbidden arr Rwys are active",
vsid::MessageHandler::DebugArea::Sid
);
continue;
}
}
else if (currSid.actArrRwy["deny"]["any"] != "")
{
std::vector<std::string> actArrRwy = vsid::utils::split(currSid.actArrRwy["deny"]["any"], ',');
if (std::any_of(actArrRwy.begin(), actArrRwy.end(), [&](std::string rwy)
{
if (this->activeAirports[icao].arrRwys.contains(rwy)) return true;
else return false;
}))
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" +
currSid.idName() + "\" because at least one of the forbidden arr rwys is active",
vsid::MessageHandler::DebugArea::Sid
);
continue;
}
}
}
}
// skip if SID needs active dep rwys
if (!currSid.actDepRwy.empty())
{
if (currSid.actDepRwy.contains("allow"))
{
if (currSid.actDepRwy["allow"]["all"] != "")
{
std::vector<std::string> actDepRwy = vsid::utils::split(currSid.actDepRwy["allow"]["all"], ',');
if (!std::all_of(actDepRwy.begin(), actDepRwy.end(), [&](std::string rwy)
{
if (depRwys.contains(rwy)) return true;
else return false;
}))
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" +
currSid.idName() + "\" because not all of the required dep Rwys are active",
vsid::MessageHandler::DebugArea::Sid
);
continue;
}
}
else if (currSid.actDepRwy["allow"]["any"] != "")
{
std::vector<std::string> actDepRwy = vsid::utils::split(currSid.actDepRwy["allow"]["any"], ',');
if (std::none_of(actDepRwy.begin(), actDepRwy.end(), [&](std::string rwy)
{
if (depRwys.contains(rwy)) return true;
else return false;
}))
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" +
currSid.idName() + "\" because none of the required dep rwys are active",
vsid::MessageHandler::DebugArea::Sid
);
continue;
}
}
}
if (currSid.actDepRwy.contains("deny"))
{
if (currSid.actDepRwy["deny"]["all"] != "")
{
std::vector<std::string> actDepRwy = vsid::utils::split(currSid.actDepRwy["deny"]["all"], ',');
if (std::all_of(actDepRwy.begin(), actDepRwy.end(), [&](std::string rwy)
{
if (depRwys.contains(rwy)) return true;
else return false;
}))
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" +
currSid.idName() + "\" because all of the forbidden dep Rwys are active",
vsid::MessageHandler::DebugArea::Sid
);
continue;
}
}
else if (currSid.actDepRwy["deny"]["any"] != "")
{
std::vector<std::string> actDepRwy = vsid::utils::split(currSid.actDepRwy["deny"]["any"], ',');
if (std::any_of(actDepRwy.begin(), actDepRwy.end(), [&](std::string rwy)
{
if (depRwys.contains(rwy)) return true;
else return false;
}))
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" +
currSid.idName() + "\" because at least one of the forbidden dep rwys is active",
vsid::MessageHandler::DebugArea::Sid
);
continue;
}
}
}
}
// skip if current SID rwys don't match dep rwys
std::vector<std::string> skipAtcRWY = {};
std::vector<std::string> skipSidRWY = {};
for (std::string depRwy : depRwys)
{
// skip if a rwy has been set manually and it doesn't match available dep rwys
if (atcRwy != "" && atcRwy != depRwy)
{
skipAtcRWY.push_back(depRwy);
continue;
}
// skip if airport dep rwys are not part of the SID
if (!vsid::utils::contains(currSid.rwys, depRwy))
{
skipSidRWY.push_back(depRwy);
continue;
}
else
{
rwyMatch = true;
break;
}
}
messageHandler->writeMessage("DEBUG", "[" + callsign + "] [" + icao + "] available rwys (merged if arrAsDep in active area or rwy set by atc): " +
vsid::utils::join(depRwys),
vsid::MessageHandler::DebugArea::Sid
);
messageHandler->writeMessage("DEBUG", "[" + callsign + "] [" + icao + "] Skipped ATC RWYs : \"" +
vsid::utils::join(skipAtcRWY) + "\" / skipped SID RWY: \"" +
vsid::utils::join(skipSidRWY) + "\"", vsid::MessageHandler::DebugArea::Sid
);
// skip if custom rules are active but the current sid has no rule or has a rule but this is not active
if (customRuleActive && currSid.customRule != "" &&
this->activeAirports[icao].customRules.contains(currSid.customRule) &&
!this->activeAirports[icao].customRules[currSid.customRule])
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" +
currSid.idName() + "\" because the SID custom rule is not active.",
vsid::MessageHandler::DebugArea::Sid);
continue;
}
// skip if aircraft type does not match (heli, fixed wing) - unknown aircraft is never skipped
if (currSid.wingType.find(fplnData.GetAircraftType()) == std::string::npos && fplnData.GetAircraftType() != '?')
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() +
"\" because wing type \"" + fplnData.GetAircraftType() + "\" doesn't match.",
vsid::MessageHandler::DebugArea::Sid);
continue;
}
// skip if equipment does not match
if (this->activeAirports[icao].equipCheck)
{
std::string equip = vsid::fplnhelper::getEquip(FlightPlan, this->configParser.rnavList);
std::string pbn = vsid::fplnhelper::getPbn(FlightPlan);
if (currSid.equip.contains("RNAV"))
{
if (equip.size() > 1 && equip.find_first_of("ABGRI") == std::string::npos && pbn == "")
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() +
"\" because RNAV ('A', 'B', 'G', 'R' or 'I') is required, but not found in equipment \"" +
equip + "\" and PBN is empty", vsid::MessageHandler::DebugArea::Sid);
validEquip = false;
continue;
}
}
else if (currSid.equip.contains("NON-RNAV"))
{
if (equip.size() < 2 && pbn == "")
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() +
"\" because only NON-RNAV is allowed, but equipment \"" + equip +
"\" has less than 2 entry and PBN is empty", vsid::MessageHandler::DebugArea::Sid);
validEquip = false;
continue;
}
/*if (equip.find_first_of("GRI") != std::string::npos || equip == "" || pbn != "")*/
if (equip.find_first_of("GRI") != std::string::npos || pbn != "")
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() +
"\" because only NON-RNAV is allowed, but RNAV ('G', 'R' or 'I') was found in equipment \"" + equip +
"\" or equipment was empty and PBN is not empty", vsid::MessageHandler::DebugArea::Sid);
validEquip = false;
continue;
}
}
else
{
for (const auto& sidEquip : currSid.equip)
{
if (sidEquip.second && equip.find(sidEquip.first) == std::string::npos)
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() +
"\" because equipment \"" + sidEquip.first + "\" is mandatory but was not found in equipment \"" + equip + "\"",
vsid::MessageHandler::DebugArea::Sid);
validEquip = false;
continue;
}
if (!sidEquip.second && equip.find(sidEquip.first) != std::string::npos)
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() +
"\" because equipment \"" + sidEquip.first + "\" is forbidden but was found in equipment \"" + equip + "\"",
vsid::MessageHandler::DebugArea::Sid);
validEquip = false;
continue;
}
}
}
}
// skip if transition part of SID and it doesn't match
if (!currSid.transition.empty())
{
bool transMatch = false;
for (auto& [base, _] : currSid.transition)
{
if (std::find(filedRoute.begin(), filedRoute.end(), base) == filedRoute.end()) continue;
else transMatch = true;
}
if (!transMatch)
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName()
+ "\" because none of the transitions found in the route",
vsid::MessageHandler::DebugArea::Dev);
}
}
// skip if custom rules are inactive but a rule exists in sid
if (!customRuleActive && currSid.customRule != "")
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() +
"\" because no rule is active and the SID has a rule configured",
vsid::MessageHandler::DebugArea::Sid
);
continue;
}
// area checks
if (currSid.area != "")
{
std::vector<std::string> sidAreas = vsid::utils::split(currSid.area, ',');
// skip if areas are inactive but set
if (std::all_of(sidAreas.begin(),
sidAreas.end(),
[&](auto sidArea)
{
if (this->activeAirports[icao].areas.contains(sidArea))
{
if (!this->activeAirports[icao].areas[sidArea].isActive) return true;
else return false;
}
else return false; // warning for wrong config in next area check to prevent doubling
}))
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() +
"\" because all areas are inactive but one is set in the SID",
vsid::MessageHandler::DebugArea::Sid
);
continue;
}
// skip if area is active + fpln outside
if (std::none_of(sidAreas.begin(),
sidAreas.end(),
[&](auto sidArea)
{
if (this->activeAirports[icao].areas.contains(sidArea))
{
if (!this->activeAirports[icao].areas[sidArea].isActive ||
(this->activeAirports[icao].areas[sidArea].isActive &&
!this->activeAirports[icao].areas[sidArea].inside(FlightPlan.GetFPTrackPosition().GetPosition()))
) return false;
else return true;
}
else
{
messageHandler->writeMessage("WARNING", "Area \"" + sidArea + "\" not in config for " + icao + ". Check your config.");
return false;
} // fallback
}))
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() +
"\" because the plane is not in one of the active areas",
vsid::MessageHandler::DebugArea::Sid
);
continue;
}
}
// skip if lvp ops are active but SID is not configured for lvp ops and lvp is not disabled for SID
if (this->activeAirports[icao].settings["lvp"] && !currSid.lvp && currSid.lvp != -1)
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() +
"\" because LVP is active and SID is not configured for LVP or LVP check is not disabled for SID",
vsid::MessageHandler::DebugArea::Sid
);
continue;
}
// skip if lvp ops are inactive but SID is configured for lvp ops
if (!this->activeAirports[icao].settings["lvp"] && currSid.lvp && currSid.lvp != -1)
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() +
"\" because LVP is inactive and SID is configured for LVP or LVP check is not disabled for SID",
vsid::MessageHandler::DebugArea::Sid
);
continue;
}
// skip if no matching rwy was found in SID;
if (!rwyMatch)
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() +
"\" due to a RWY mismatch between SID rwy and active DEP rwy",
vsid::MessageHandler::DebugArea::Sid
);
continue;
}
// skip if engine type doesn't match
if (currSid.engineType != "" && currSid.engineType.find(fplnData.GetEngineType()) == std::string::npos)
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() +
"\" because of a mismatch in engineType",
vsid::MessageHandler::DebugArea::Sid
);
continue;
}
else if (currSid.engineType != "")
{
restriction = true;
}
// skip if an aircraft type is set in sid but is set to false
if ((currSid.acftType.contains(fplnData.GetAircraftFPType()) &&
!currSid.acftType[fplnData.GetAircraftFPType()]) ||
std::any_of(currSid.acftType.begin(), currSid.acftType.end(), [&](auto type)
{
return type.second && !currSid.acftType.contains(fplnData.GetAircraftFPType());
}))
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() +
"\" because of a mismatch in aircraft type (type is set to false" +
" or type is set to true but plane is not of the type)",
vsid::MessageHandler::DebugArea::Sid
);
continue;
}
else if (!currSid.acftType.empty())
{
restriction = true;
}
// skip if SID has engineNumber requirement and acft doesn't match
if (!vsid::utils::containsDigit(currSid.engineCount, fplnData.GetEngineNumber()))
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() +
"\" because of a mismatch in engine number",
vsid::MessageHandler::DebugArea::Sid
);
continue;
}
else if (currSid.engineCount > 0)
{
restriction = true;
}
// skip if SID has WTC requirement and acft doesn't match
if (currSid.wtc != "" && currSid.wtc.find(fplnData.GetAircraftWtc()) == std::string::npos)
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + "\" because of mismatch in WTC",
vsid::MessageHandler::DebugArea::Sid
);
continue;
}
else if (currSid.wtc != "")
{
restriction = true;
}
// skip if SID has mtow requirement and acft is too heavy - if grp config has not yet been loaded load it
if (currSid.mtow)
{
if (this->configParser.grpConfig.size() == 0)
{
this->configParser.loadGrpConfig();
}
std::string acftType = fplnData.GetAircraftFPType();
bool mtowMatch = false;
for (auto it = this->configParser.grpConfig.begin(); it != this->configParser.grpConfig.end(); ++it)
{
if (it->value("ICAO", "") != acftType) continue;
if (it->value("MTOW", 0) > currSid.mtow) break; // acft icao found but to heavy, no further checks
mtowMatch = true;
break; // acft light enough, no further checks
}
if (!mtowMatch)
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + "\" because of MTOW",
vsid::MessageHandler::DebugArea::Sid
);
continue;
}
else restriction = true;
}
// skip if destination restrictions present and flight plan doesn't match
if (!currSid.dest.empty())
{
if (currSid.dest.contains(dest) && !currSid.dest[dest])
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + "\" because destination \"" +
dest + "\" is not allowed", vsid::MessageHandler::DebugArea::Sid
);
continue;
}
else if (!currSid.dest.contains(dest) && std::any_of(currSid.dest.begin(), currSid.dest.end(), [](const std::pair<std::string, bool>& sidDest)
{
return sidDest.second;
}))
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + "\" because destination \"" +
dest + "\" was not found for this SID and the SID has mandatory destinations",
vsid::MessageHandler::DebugArea::Sid);
continue;
}
}
// skip if route restrictions present and flight plan doesn't match
if (!currSid.route.empty())
{
if (currSid.route.contains("allow"))
{
bool validRoute = false;
for (const auto& [_, route] : currSid.route["allow"])
{
std::vector<std::string>::iterator startPos;
try
{
startPos = std::find(filedRoute.begin(), filedRoute.end(), route.at(0));
if (startPos == filedRoute.end()) messageHandler->writeMessage("DEBUG", "[" + callsign + "] skipping SID \"" +
currSid.idName() + "\" route checking for " + vsid::utils::join(route, ' ') +
" because first mandatory wpt " + route.at(0) +
" was not found in route", vsid::MessageHandler::DebugArea::Sid);
messageHandler->removeFplnError(callsign, ERROR_FPLN_ALLOWROUTE);
}
catch (std::out_of_range)
{
if (!messageHandler->getFplnErrors(callsign).contains(ERROR_FPLN_ALLOWROUTE))
{
messageHandler->writeMessage("ERROR", "[" + callsign + "] Failed to get first position for allowed route in SID " +
currSid.idName() + " checking SID route \"" + vsid::utils::join(route, ' ') + "\". Code: " + ERROR_FPLN_ALLOWROUTE);
messageHandler->addFplnError(callsign, ERROR_FPLN_ALLOWROUTE);
}
}
bool lastMatch = false;
bool allowSkip = false;
bool stopRoute = false;
for (const std::string& wpt : route)
{
if (stopRoute) break;
if (wpt == std::string("..."))
{
allowSkip = true;
continue;
}
for (std::vector<std::string>::iterator it = startPos; it != filedRoute.end();)
{
if (*it == std::string("DCT"))
{
startPos++;
it++;
continue;
}
messageHandler->writeMessage("DEBUG", "[" + callsign + "] checking mand. wpt " + wpt +
" vs. " + *it, vsid::MessageHandler::DebugArea::Sid);
if (wpt == *it)
{
allowSkip = false;
lastMatch = true;
startPos++;
break;
}
else if (allowSkip)
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] skipping wpt " + *it +
" as skipping is allowed", vsid::MessageHandler::DebugArea::Sid);
lastMatch = false;
it++;
startPos++;
continue;
}
else
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] mismatch between mand. wpt " +
wpt + " vs. " + *it + ". Aborting", vsid::MessageHandler::DebugArea::Sid);
lastMatch = false;
stopRoute = true;
break;
}
}
}
if (lastMatch)
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] mand. route in " + currSid.idName() +
" was found. Accepting.", vsid::MessageHandler::DebugArea::Sid);
validRoute = true;
break;
}
}
if (!validRoute)
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] skipping SID \"" +
currSid.idName() + "\" because none of the allowed routes matched", vsid::MessageHandler::DebugArea::Sid);
continue;
}
}
if (currSid.route.contains("deny"))
{
bool invalidRoute = false;
for (const auto& [_, route] : currSid.route["deny"])
{
std::vector<std::string>::iterator startPos;
try
{
startPos = std::find(filedRoute.begin(), filedRoute.end(), route.at(0));
if (startPos == filedRoute.end())
{
messageHandler->writeMessage("DEBUG", "[" + callsign + "] accepting SID " +
currSid.idName() + " because first waypoint of denied route wasn't found", vsid::MessageHandler::DebugArea::Sid);
messageHandler->removeFplnError(callsign, ERROR_FPLN_DENYROUTE);
break;
}
}
catch (std::out_of_range)
{
if (!messageHandler->getFplnErrors(callsign).contains(ERROR_FPLN_DENYROUTE))
{
messageHandler->writeMessage("ERROR", "[" + callsign + "] Failed to get first position for denied route in SID " +
currSid.idName() + " checking SID route \"" + vsid::utils::join(route, ' ') + "\". Code: " + ERROR_FPLN_DENYROUTE);
messageHandler->addFplnError(callsign, ERROR_FPLN_DENYROUTE);
}
}
bool lastMatch = false;
bool allowSkip = false;