-
Notifications
You must be signed in to change notification settings - Fork 9
/
CDMSingle.cpp
6665 lines (6103 loc) · 194 KB
/
CDMSingle.cpp
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 "stdafx.h"
#include "CDMSingle.hpp"
#include "pugixml.hpp"
#include "pugixml.cpp"
#include <thread>
#include "Delay.h"
extern "C" IMAGE_DOS_HEADER __ImageBase;
bool blink;
bool debugMode, initialSidLoad;
int disCount;
ifstream sidDatei;
char DllPathFile[_MAX_PATH];
string pfad;
string lfad;
string sfad;
string cfad;
string vfad;
string rfad;
string dfad;
string xfad;
string rateString;
string lvoRateString;
int expiredCTOTTime;
bool defaultRate;
int countTime;
int countFlowTime;
int countTfcDisconnection;
int refreshTime;
bool addTime;
bool lvo;
bool ctotCid;
bool realMode;
bool remarksOption;
bool invalidateTSAT_Option;
string myTimeToAdd;
string rateUrl;
string taxiZonesUrl;
string ctotURL;
string flowRestrictionsUrl;
int defTaxiTime;
string cadUrl;
string myCallsign;
bool option_su_wait;
//Ftp data
string ftpHost;
string ftpUser;
string ftpPassword;
string vdgsFileType;
vector<Plane> slotList;
vector<Flow> flowData;
vector<string> asatList;
vector<string> taxiTimesList;
vector<string> TxtTimesVector;
vector<string> OutOfTsat;
vector<string> colors;
vector<Rate> rate;
vector<string> planeAiportList;
vector<string> masterAirports;
vector<string> CDMairports;
vector<string> CTOTcheck;
vector<string> finalTimesList;
vector<string> disconnectionList;
vector<string> difeobttobtList;
vector<string> reaSent;
vector<string> reaCTOTSent;
vector<CAD> CADvalues;
vector<vector<string>> evCtots;
vector<Delay> delayList;
using namespace std;
using namespace EuroScopePlugIn;
using namespace pugi;
COLORREF TAG_GREEN = 0xFFFFFFFF;
COLORREF TAG_GREENNOTACTIVE = 0xFFFFFFFF;
COLORREF TAG_GREY = 0xFFFFFFFF;
COLORREF TAG_ORANGE = 0xFFFFFFFF;
COLORREF TAG_YELLOW = 0xFFFFFFFF;
COLORREF TAG_DARKYELLOW = 0xFFFFFFFF;
COLORREF TAG_RED = 0xFFFFFFFF;
COLORREF TAG_EOBT = 0xFFFFFFFF;
COLORREF TAG_TTOT = 0xFFFFFFFF;
COLORREF TAG_ASRT = 0xFFFFFFFF;
COLORREF TAG_CTOT = 0xFFFFFFFF;
COLORREF SU_SET_COLOR = 0xFFFFFFFF;
// Run on Plugin Initialization
CDM::CDM(void) :CPlugIn(EuroScopePlugIn::COMPATIBILITY_CODE, MY_PLUGIN_NAME, MY_PLUGIN_VERSION, MY_PLUGIN_DEVELOPER, MY_PLUGIN_COPYRIGHT)
{
string loadingMessage = "Version: ";
loadingMessage += MY_PLUGIN_VERSION;
loadingMessage += " loaded.";
sendMessage(loadingMessage);
// Register Tag Item "CDM-OPTIONS"
RegisterTagItemType("Options", TAG_ITEM_OPTIONS);
RegisterTagItemFunction("Options", TAG_FUNC_OPT);
// Register Tag Item "CDM-EOBT"
RegisterTagItemType("EOBT", TAG_ITEM_EOBT);
RegisterTagItemFunction("Edit EOBT", TAG_FUNC_EDITEOBT);
RegisterTagItemFunction("EOBT Options", TAG_FUNC_OPT_EOBT);
//Register Tag Item "CDM-TOBT"
RegisterTagItemType("TOBT", TAG_ITEM_TOBT);
RegisterTagItemFunction("Ready TOBT", TAG_FUNC_READYTOBT);
RegisterTagItemFunction("Edit TOBT", TAG_FUNC_EDITTOBT);
RegisterTagItemFunction("EOBT to TOBT", TAG_FUNC_EOBTTOTOBT);
RegisterTagItemFunction("TOBT Options", TAG_FUNC_OPT_TOBT);
// Register Tag Item "CDM-TSAT"
RegisterTagItemType("TSAT", TAG_ITEM_TSAT);
RegisterTagItemFunction("TSAT Delay", TAG_FUNC_CUSTOMTSAT);
// Register Tag Item "CDM-TTOT"
RegisterTagItemType("TTOT", TAG_ITEM_TTOT);
RegisterTagItemFunction("TTOT Options", TAG_FUNC_OPT_TTOT);
// Register Tag Item "CDM-TSAC"
RegisterTagItemType("TSAC", TAG_ITEM_TSAC);
RegisterTagItemType("TSAC-Simple", TAG_ITEM_TSAC_SIMPLE);
RegisterTagItemFunction("Add TSAT to TSAC", TAG_FUNC_ADDTSAC);
RegisterTagItemFunction("Edit TSAC", TAG_FUNC_EDITTSAC);
RegisterTagItemFunction("TSAC Options", TAG_FUNC_OPT_TSAC);
// Register Tag Item "CDM-ASAT"
RegisterTagItemType("ASAT", TAG_ITEM_ASAT);
// Register Tag Item "CDM-ASAT"
RegisterTagItemType("ASRT", TAG_ITEM_ASRT);
RegisterTagItemFunction("Toggle ASRT", TAG_FUNC_TOGGLEASRT);
// Register Tag Item "CDM-ASAT"
RegisterTagItemType("Ready Start-up", TAG_ITEM_READYSTARTUP);
RegisterTagItemFunction("Toggle Ready Start-up", TAG_FUNC_READYSTARTUP);
// Register Tag Item "CDM-E"
RegisterTagItemType("E", TAG_ITEM_E);
//Register
RegisterTagItemType("Flow Message", TAG_ITEM_FLOW_MESSAGE);
// Register Tag Item "CDM-CTOT"
RegisterTagItemType("CTOT", TAG_ITEM_CTOT);
RegisterTagItemFunction("CTOT Options", TAG_FUNC_CTOTOPTIONS);
RegisterTagItemFunction("Get FM as text", TAG_FUNC_FMASTEXT);
// Register Tag Item "CDM-EVENT-CTOT"
RegisterTagItemType("EV-CTOT", TAG_ITEM_EV_CTOT);
RegisterTagItemFunction("EvCTOT Options", TAG_FUNC_OPT_EvCTOT);
RegisterTagItemFunction("EvCTOT to MANUAL CTOT", TAG_FUNC_EvCTOTtoCTOT);
GetModuleFileNameA(HINSTANCE(&__ImageBase), DllPathFile, sizeof(DllPathFile));
pfad = DllPathFile;
pfad.resize(pfad.size() - strlen("CDM.dll"));
pfad += "CDMconfig.xml";
dfad = DllPathFile;
dfad.resize(dfad.size() - strlen("CDM.dll"));
dfad += "CDM_data";
lfad = DllPathFile;
lfad.resize(lfad.size() - strlen("CDM.dll"));
lfad += "taxizones.txt";
sfad = DllPathFile;
sfad.resize(sfad.size() - strlen("CDM.dll"));
sfad += "savedData.txt";
cfad = DllPathFile;
cfad.resize(cfad.size() - strlen("CDM.dll"));
cfad += "ctot.txt";
vfad = DllPathFile;
vfad.resize(vfad.size() - strlen("CDM.dll"));
vfad += "colors.txt";
rfad = DllPathFile;
rfad.resize(rfad.size() - strlen("CDM.dll"));
rfad += "rate.txt";
debugMode = false;
initialSidLoad = false;
countTime = stoi(GetTimeNow());
countFlowTime = stoi(GetTimeNow());
//countTime = stoi(GetTimeNow()) - refreshTime;
addTime = false;
countTfcDisconnection = -1;
GetVersion();
//Get data from xml config file
//airport = getFromXml("/CDM/apt/@icao");
//airport = getFromXml("/CDM/apt/@icao");
defTaxiTime = stoi(getFromXml("/CDM/DefaultTaxiTime/@minutes"));
refreshTime = stoi(getFromXml("/CDM/RefreshTime/@seconds"));
expiredCTOTTime = stoi(getFromXml("/CDM/expiredCtot/@time"));
string realModeStr = getFromXml("/CDM/realMode/@mode");
rateString = getFromXml("/CDM/rate/@ops");
lvoRateString = getFromXml("/CDM/rateLvo/@ops");
rateUrl = getFromXml("/CDM/Rates/@url");
taxiZonesUrl = getFromXml("/CDM/Taxizones/@url");
ctotURL = getFromXml("/CDM/Ctot/@url");
string invalidateTSAT_OptionStr = getFromXml("/CDM/invalidateAtTsat/@mode");
string stringDebugMode = getFromXml("/CDM/Debug/@mode");
flowRestrictionsUrl = getFromXml("/CDM/FlowRestrictions/@url");
vdgsFileType = getFromXml("/CDM/vdgsFileType/@type");
ftpHost = getFromXml("/CDM/ftpHost/@host");
ftpUser = getFromXml("/CDM/ftpUser/@user");
ftpPassword = getFromXml("/CDM/ftpPassword/@password");
string opt_su_wait = getFromXml("/CDM/Su_Wait/@mode");
option_su_wait = false;
if (opt_su_wait == "true") {
option_su_wait = true;
}
debugMode = false;
if (stringDebugMode == "true") {
debugMode = true;
sendMessage("[DEBUG MESSAGE] - USING DEBUG MODE");
}
realMode = false;
if (realModeStr == "true") {
realMode = true;
}
//Invalidate FP at TSAT+6
invalidateTSAT_Option = true;
if (invalidateTSAT_OptionStr == "false") {
invalidateTSAT_Option = false;
}
//Flow Data
getFlowData();
//Init reamrksOption
remarksOption = false;
//Initialize with empty callsign
myCallsign = "";
//Get CAD values
cadUrl = "https://raw.githubusercontent.com/rpuig2001/Capacity-Availability-Document-CDM/main/CAD.txt";
//getCADvalues();
multithread(&CDM::getCADvalues);
lvo = false;
if (rateUrl.length() <= 1) {
if (debugMode) {
sendMessage("[DEBUG MESSAGE] - USING RATE FROM LOCAL TXT FILE");
}
getRate();
}
else {
if (debugMode) {
sendMessage("[DEBUG MESSAGE] - USING TAXIZONES FROM URL");
}
getRateFromUrl(rateUrl);
}
if (taxiZonesUrl.length() <= 1) {
if (debugMode) {
sendMessage("[DEBUG MESSAGE] - USING TAXIZONES FROM LOCAL TXT FILE");
}
//Get data from .txt file
fstream file;
string lineValue;
file.open(lfad.c_str(), std::ios::in);
while (getline(file, lineValue))
{
if (!lineValue.empty()) {
if (lineValue.substr(0, 1) != "#") {
TxtTimesVector.push_back(lineValue);
}
}
}
}
else {
if (debugMode) {
sendMessage("[DEBUG MESSAGE] - USING TAXIZONES FROM URL");
}
getTaxiZonesFromUrl(taxiZonesUrl);
}
//Get Values from ctot web or file
if (ctotURL.length() <= 1) {
ctotCid = false;
if (debugMode) {
sendMessage("[DEBUG MESSAGE] - NOT SHOWING EVCTOTs");
}
//Get data from .txt file
/*fstream fileCtot;
string lineValueCtot;
fileCtot.open(cfad.c_str(), std::ios::in);
while (getline(fileCtot, lineValueCtot))
{
addCtotToMainList(lineValueCtot);
}*/
}
else {
ctotCid = true;
if (debugMode) {
sendMessage("[DEBUG MESSAGE] - SHOWING EVCTOTs");
}
getCtotsFromUrl(ctotURL);
}
fstream fileColors;
string lineValueColors;
vector<int> sep;
fileColors.open(vfad.c_str(), std::ios::in);
COLORREF color = RGB(0, 0, 0);
smatch match;
while (getline(fileColors, lineValueColors))
{
if (regex_match(lineValueColors, match, regex("^color(\\d+):(\\d+),(\\d+),(\\d+)$", regex::icase)))
{
color = RGB(stoi(match[2]), stoi(match[3]), stoi(match[4]));
switch (stoi(match[1]))
{
case 1:
TAG_GREEN = color;
break;
case 2:
TAG_GREENNOTACTIVE = color;
break;
case 3:
TAG_GREY = color;
break;
case 4:
TAG_ORANGE = color;
break;
case 5:
TAG_YELLOW = color;
break;
case 6:
TAG_DARKYELLOW = color;
break;
case 7:
TAG_RED = color;
break;
case 8:
TAG_EOBT = color;
break;
case 9:
TAG_TTOT = color;
break;
case 10:
TAG_ASRT = color;
break;
case 11:
TAG_CTOT = color;
break;
case 12:
SU_SET_COLOR = color;
break;
default:
break;
}
}
}
}
// Run on Plugin destruction, Ie. Closing EuroScope or unloading plugin
CDM::~CDM()
{
}
/*
Custom Functions
*/
void CDM::debugMessage(string type, string message) {
// Display Debug Message if debugMode = true
if (debugMode) {
DisplayUserMessage("CDM", type.c_str(), message.c_str(), true, true, true, false, false);
}
}
void CDM::sendMessage(string type, string message) {
// Show a message
DisplayUserMessage("CDM", type.c_str(), message.c_str(), true, true, true, true, false);
}
void CDM::sendMessage(string message) {
DisplayUserMessage(MY_PLUGIN_NAME, "", message.c_str(), true, true, true, false, false);
}
//
void CDM::OnFunctionCall(int FunctionId, const char* ItemString, POINT Pt, RECT Area) {
CFlightPlan fp = FlightPlanSelectASEL();
bool AtcMe = false;
bool master = false;
for (string apt : masterAirports)
{
if (apt == fp.GetFlightPlanData().GetOrigin()) {
master = true;
}
}
if (master) {
if (fp.GetTrackingControllerIsMe() || strlen(fp.GetTrackingControllerId()) == 0) {
AtcMe = true;
}
}
if (FunctionId == TAG_FUNC_EDITEOBT)
{
if (master && AtcMe) {
OpenPopupEdit(Area, TAG_FUNC_NEWEOBT, fp.GetFlightPlanData().GetEstimatedDepartureTime());
}
}
else if (FunctionId == TAG_FUNC_NEWEOBT) {
string editedEOBT = ItemString;
bool hasNoNumber = true;
if (editedEOBT.length() <= 4) {
for (size_t i = 0; i < editedEOBT.length(); i++) {
if (isdigit(editedEOBT[i]) == false) {
hasNoNumber = false;
}
}
if (hasNoNumber) {
fp.GetFlightPlanData().SetEstimatedDepartureTime(editedEOBT.c_str());
fp.GetFlightPlanData().AmendFlightPlan();
}
}
}
else if (FunctionId == TAG_FUNC_EOBTTOTOBT) {
fp.GetControllerAssignedData().SetFlightStripAnnotation(0, formatTime(fp.GetFlightPlanData().GetEstimatedDepartureTime()).c_str());
//Remove if added to not modify TOBT if EOBT changes List
for (size_t i = 0; i < difeobttobtList.size(); i++) {
if ((string)fp.GetCallsign() == difeobttobtList[i]) {
difeobttobtList.erase(difeobttobtList.begin() + i);
}
}
}
else if (FunctionId == TAG_FUNC_ADDTSAC) {
string annotTSAC = fp.GetControllerAssignedData().GetFlightStripAnnotation(2);
string completeTOBT = (string)fp.GetControllerAssignedData().GetFlightStripAnnotation(0);
if (annotTSAC.empty() && !completeTOBT.empty()) {
//Get Time now
time_t rawtime;
struct tm ptm;
time(&rawtime);
gmtime_s(&ptm, &rawtime);
string hour = to_string(ptm.tm_hour % 24);
string min = to_string(ptm.tm_min);
if (stoi(min) < 10) {
min = "0" + min;
}
if (stoi(hour) < 10) {
hour = "0" + hour.substr(0, 1);
}
bool notYetTOBT = false;
string TOBThour = completeTOBT.substr(0, 2);
string TOBTmin = completeTOBT.substr(2, 2);
if (hour != "00") {
if (TOBThour == "00") {
TOBThour = "24";
}
}
int EOBTdifTime = GetdifferenceTime(hour, min, TOBThour, TOBTmin);
if (hour != TOBThour) {
if (EOBTdifTime < -75) {
notYetTOBT = true;
}
}
else {
if (EOBTdifTime < -35) {
notYetTOBT = true;
}
}
if (!notYetTOBT) {
for (size_t a = 0; a < slotList.size(); a++)
{
if (slotList[a].callsign == fp.GetCallsign()) {
string getTSAT = slotList[a].tsat;
if (getTSAT.length() >= 4) {
fp.GetControllerAssignedData().SetFlightStripAnnotation(2, getTSAT.substr(0,4).c_str());
}
}
}
}
}
else {
fp.GetControllerAssignedData().SetFlightStripAnnotation(2, "");
}
}
else if (FunctionId == TAG_FUNC_EDITTSAC) {
OpenPopupEdit(Area, TAG_FUNC_NEWTSAC, fp.GetControllerAssignedData().GetFlightStripAnnotation(2));
}
else if (FunctionId == TAG_FUNC_NEWTSAC) {
string editedTSAC = ItemString;
if (editedTSAC.length() > 0) {
bool hasNoNumber = true;
if (editedTSAC.length() == 4) {
for (size_t i = 0; i < editedTSAC.length(); i++) {
if (isdigit(editedTSAC[i]) == false) {
hasNoNumber = false;
}
}
if (hasNoNumber) {
fp.GetControllerAssignedData().SetFlightStripAnnotation(2, editedTSAC.c_str());
}
}
}
}
else if (FunctionId == TAG_FUNC_TOGGLEASRT || FunctionId == TAG_FUNC_READYSTARTUP) {
if (master && AtcMe) {
string annotAsrt = fp.GetControllerAssignedData().GetFlightStripAnnotation(1);
if (annotAsrt.empty()) {
//Get Time now
time_t rawtime;
struct tm ptm;
time(&rawtime);
gmtime_s(&ptm, &rawtime);
string hour = to_string(ptm.tm_hour % 24);
string min = to_string(ptm.tm_min);
if (stoi(min) < 10) {
min = "0" + min;
}
if (stoi(hour) < 10) {
hour = "0" + hour.substr(0, 1);
}
fp.GetControllerAssignedData().SetFlightStripAnnotation(1, (hour + min).c_str());
//Check if has restriction to reload CTOT
bool hasRestriction = 0;
for (size_t i = 0; i < slotList.size(); i++)
{
if (slotList[i].callsign == fp.GetCallsign()) {
if (slotList[i].hasCtot) {
if (slotList[i].hasRestriction != 0) {
hasRestriction = 0;
}
}
}
}
if (hasRestriction != 0) {
//Reload CTOT
for (size_t a = 0; a < slotList.size(); a++)
{
if (slotList[a].callsign == fp.GetCallsign()) {
if (slotList[a].hasCtot) {
slotList.erase(slotList.begin() + a);
}
}
}
for (size_t i = 0; i < slotList.size(); i++)
{
if (slotList[i].callsign == fp.GetCallsign()) {
slotList[i].hasCtot = false;
slotList[i].ctot = "";
string remarks = fp.GetControllerAssignedData().GetFlightStripAnnotation(3);
if (remarks.find("CTOT") != string::npos) {
if (remarks.find("%") != string::npos) {
string stringToAdd = remarks.substr(0, remarks.find("CTOT")) + remarks.substr(remarks.find("%"), remarks.length() - remarks.find("%"));
fp.GetControllerAssignedData().SetFlightStripAnnotation(3, stringToAdd.c_str());
remarks = stringToAdd;
}
else {
string stringToAdd = remarks.substr(0, remarks.find("CTOT") - 1);
fp.GetControllerAssignedData().SetFlightStripAnnotation(3, stringToAdd.c_str());
remarks = stringToAdd;
}
}
}
}
}
}
else {
fp.GetControllerAssignedData().SetFlightStripAnnotation(1, "");
}
}
}
else if (FunctionId == TAG_FUNC_FMASTEXT) {
if (master) {
for (size_t i = 0; i < slotList.size(); i++)
{
if (slotList[i].callsign == fp.GetCallsign()) {
if (slotList[i].hasCtot && slotList[i].hasRestriction != 0) {
sendMessage(slotList[i].callsign + " FM -> " + slotList[i].flowRestriction.ident);
}
}
}
}
}
else if (FunctionId == TAG_FUNC_CTOTOPTIONS) {
if (master && AtcMe) {
bool hasCTOT = false;
bool hasRestriction = 0;
for (size_t i = 0; i < slotList.size(); i++)
{
if (slotList[i].callsign == fp.GetCallsign()) {
if (slotList[i].hasCtot) {
hasCTOT = true;
if (slotList[i].hasRestriction != 0) {
hasRestriction = 1;
}
}
}
}
bool inreaList = false;
for (string s : reaCTOTSent) {
if (s == fp.GetCallsign()) {
inreaList = true;
}
}
Plane plane;
for (size_t i = 0; i < slotList.size(); i++)
{
if (slotList[i].callsign == fp.GetCallsign()) {
plane = slotList[i];
}
}
OpenPopupList(Area, "CTOT Options", 1);
if (hasCTOT) {
if (hasRestriction != 0) {
if (!inreaList) {
AddPopupListElement("Send REA MSG", "", TAG_FUNC_TOGGLEREAMSG, false, 2, false);
}
else {
AddPopupListElement("Remove from REA MSG", "", TAG_FUNC_TOGGLEREAMSG, false, 2, false);
}
}
else {
AddPopupListElement("Remove CTOT", "", TAG_FUNC_REMOVECTOT, false, 2, false);
}
}
else {
if (!plane.hasManualCtot) {
AddPopupListElement("Set Manual CTOT", "", TAG_FUNC_EDITMANCTOT, false, 2, false);
}
else {
AddPopupListElement("Remove Manual CTOT", "", TAG_FUNC_REMOVEMANCTOT, false, 2, false);
}
}
}
}
else if (FunctionId == TAG_FUNC_TOGGLEREAMSG) {
toggleReaMsg(fp, true);
}
else if (FunctionId == TAG_FUNC_REMOVECTOT) {
for (size_t a = 0; a < slotList.size(); a++)
{
if (slotList[a].callsign == fp.GetCallsign()) {
if (slotList[a].hasCtot) {
slotList.erase(slotList.begin() + a);
}
}
}
for (size_t i = 0; i < slotList.size(); i++)
{
if (slotList[i].callsign == fp.GetCallsign()) {
slotList[i].hasCtot = false;
slotList[i].ctot = "";
string remarks = fp.GetControllerAssignedData().GetFlightStripAnnotation(3);
if (remarks.find("CTOT") != string::npos) {
if (remarks.find("%") != string::npos) {
string stringToAdd = remarks.substr(0, remarks.find("CTOT")) + remarks.substr(remarks.find("%"), remarks.length() - remarks.find("%"));
fp.GetControllerAssignedData().SetFlightStripAnnotation(3, stringToAdd.c_str());
remarks = stringToAdd;
}
else {
string stringToAdd = remarks.substr(0, remarks.find("CTOT") - 1);
fp.GetControllerAssignedData().SetFlightStripAnnotation(3, stringToAdd.c_str());
remarks = stringToAdd;
}
}
}
}
//Update times to slaves
countTime = stoi(GetTimeNow()) - (refreshTime+5);
}
else if (FunctionId == TAG_FUNC_OPT_TTOT) {
if (master && AtcMe) {
OpenPopupList(Area, "TTOT Options", 1);
//CDT OPTIONS
bool planeFound = false;
Plane plane;
for (size_t i = 0; i < slotList.size(); i++)
{
if (slotList[i].callsign == fp.GetCallsign()) {
planeFound = true;
plane = slotList[i];
}
}
if (planeFound) {
if (plane.hasManualCtot) {
AddPopupListElement("Edit Custom CDT", "", TAG_FUNC_EDITCDT, false, 2, false);
}
else {
AddPopupListElement("Set Custom CDT", "", TAG_FUNC_EDITCDT, false, 2, false);
}
}
else {
AddPopupListElement("Set Custom CDT", "", TAG_FUNC_EDITCDT, false, 2, false);
}
}
}
else if (FunctionId == TAG_FUNC_OPT) {
if (master && AtcMe) {
OpenPopupList(Area, "CDM - Options", 1);
//EOBT OPTIONS
AddPopupListElement("Edit EOBT", "", TAG_FUNC_EDITEOBT, false, 2, false);
AddPopupListElement("----------------", "", -1, false, 2, false);
//TOBT OPTIONS
AddPopupListElement("Ready TOBT", "", TAG_FUNC_READYTOBT, false, 2, false);
AddPopupListElement("Edit TOBT", "", TAG_FUNC_EDITTOBT, false, 2, false);
AddPopupListElement("----------------", "", -1, false, 2, false);
//TSAC OPTIONS
string tsacvalue = fp.GetControllerAssignedData().GetFlightStripAnnotation(2);
if (tsacvalue.empty()) {
AddPopupListElement("Add TSAT to TSAC", "", TAG_FUNC_ADDTSAC, false, 2, false);
}
else {
AddPopupListElement("Remove TSAC", "", TAG_FUNC_ADDTSAC, false, 2, false);
}
AddPopupListElement("Edit TSAC", "", TAG_FUNC_EDITTSAC, false, 2, false);
AddPopupListElement("----------------", "", -1, false, 2, false);
//ASRT OPTIONS
string asrtvalue = fp.GetControllerAssignedData().GetFlightStripAnnotation(1);
if (asrtvalue.empty()) {
AddPopupListElement("Set RSTUP State", "", TAG_FUNC_READYSTARTUP, false, 2, false);
}
else {
AddPopupListElement("Remove RSTUP State", "", TAG_FUNC_READYSTARTUP, false, 2, false);
}
AddPopupListElement("----------------", "", -1, false, 2, false);
//CDT OPTIONS
bool planeFound = false;
Plane plane;
for (size_t i = 0; i < slotList.size(); i++)
{
if (slotList[i].callsign == fp.GetCallsign()) {
planeFound = true;
plane = slotList[i];
}
}
if (planeFound) {
if (plane.hasManualCtot) {
AddPopupListElement("Edit Custom CDT", "", TAG_FUNC_EDITCDT, false, 2, false);
}
else {
AddPopupListElement("Set Custom CDT", "", TAG_FUNC_EDITCDT, false, 2, false);
}
}
else {
AddPopupListElement("Set Custom CDT", "", TAG_FUNC_EDITCDT, false, 2, false);
}
//CTOT OPTIONS
bool hasCTOT = false;
bool hasRestriction = 0;
for (size_t i = 0; i < slotList.size(); i++)
{
if (slotList[i].callsign == fp.GetCallsign()) {
if (slotList[i].hasCtot) {
hasCTOT = true;
if (slotList[i].hasRestriction != 0) {
hasRestriction = 1;
}
}
}
}
bool inreaList = false;
for (string s : reaCTOTSent) {
if (s == fp.GetCallsign()) {
inreaList = true;
}
}
if (hasCTOT) {
AddPopupListElement("----------------", "", -1, false, 2, false);
if (hasRestriction != 0) {
if (!inreaList) {
AddPopupListElement("Send REA MSG", "", TAG_FUNC_TOGGLEREAMSG, false, 2, false);
}
else {
AddPopupListElement("Remove from REA MSG", "", TAG_FUNC_TOGGLEREAMSG, false, 2, false);
}
}
else {
AddPopupListElement("Remove CTOT", "", TAG_FUNC_REMOVECTOT, false, 2, false);
}
}
else {
if (!plane.hasManualCtot) {
AddPopupListElement("Set Manual CTOT", "", TAG_FUNC_EDITMANCTOT, false, 2, false);
}
else {
AddPopupListElement("Remove Manual CTOT", "", TAG_FUNC_REMOVEMANCTOT, false, 2, false);
}
}
}
}
else if (FunctionId == TAG_FUNC_OPT_TOBT) {
if (master && AtcMe) {
OpenPopupList(Area, "TOBT Options", 1);
AddPopupListElement("Ready TOBT", "", TAG_FUNC_READYTOBT, false, 2, false);
AddPopupListElement("Edit TOBT", "", TAG_FUNC_EDITTOBT, false, 2, false);
}
}
else if (FunctionId == TAG_FUNC_OPT_EOBT) {
if (master && AtcMe) {
OpenPopupList(Area, "EOBT Options", 1);
AddPopupListElement("Edit EOBT", "", TAG_FUNC_EDITEOBT, false, 2, false);
}
}
else if (FunctionId == TAG_FUNC_OPT_TSAC) {
if (master && AtcMe) {
OpenPopupList(Area, "TSAC Options", 1);
string tsacvalue = fp.GetControllerAssignedData().GetFlightStripAnnotation(2);
if (tsacvalue.empty()) {
AddPopupListElement("Add TSAT to TSAC", "", TAG_FUNC_ADDTSAC, false, 2, false);
}
else {
AddPopupListElement("Remove TSAC", "", TAG_FUNC_ADDTSAC, false, 2, false);
}
AddPopupListElement("Edit TSAC", "", TAG_FUNC_EDITTSAC, false, 2, false);
}
}
else if (FunctionId == TAG_FUNC_OPT_EvCTOT) {
if (master && AtcMe) {
OpenPopupList(Area, "Event CTOT Options", 1);
AddPopupListElement("Add Event CTOT as MAN CTOT", "", TAG_FUNC_EvCTOTtoCTOT, false, 2, false);
}
}
else if (FunctionId == TAG_FUNC_READYTOBT) {
if (master && AtcMe) {
//SET SU_WAIT WHEN OPTION ENABLED
if (option_su_wait) {
fp.GetControllerAssignedData().SetFlightStripAnnotation(4, "SU_WAIT");
}
fp.GetControllerAssignedData().SetFlightStripAnnotation(0, formatTime(GetActualTime()).c_str());
//Send REA MSG if CTOT
for (size_t i = 0; i < slotList.size(); i++) {
if ((string)fp.GetCallsign() == slotList[i].callsign && slotList[i].hasCtot && slotList[i].hasRestriction != 0) {
/*slotList[i].hasCtot = false;
slotList[i].ctot = "";
slotList[i].hasRestriction = 0;*/
toggleReaMsg(fp, false);
}
}
//Get Time now
time_t rawtime;
struct tm ptm;
time(&rawtime);
gmtime_s(&ptm, &rawtime);
string hour = to_string(ptm.tm_hour % 24);
string min = to_string(ptm.tm_min);
if (stoi(min) < 10) {
min = "0" + min;
}
if (stoi(hour) < 10) {
hour = "0" + hour.substr(0, 1);
}
string annotAsrt = fp.GetControllerAssignedData().GetFlightStripAnnotation(1);
if (annotAsrt.empty()) {
fp.GetControllerAssignedData().SetFlightStripAnnotation(1, (hour + min).c_str());
}
//Add to not modify TOBT if EOBT changes List
bool foundInEobtTobtList = false;
for (size_t i = 0; i < difeobttobtList.size(); i++) {
if ((string)fp.GetCallsign() == difeobttobtList[i]) {
foundInEobtTobtList = true;
}
}
if (!foundInEobtTobtList) {
difeobttobtList.push_back(fp.GetCallsign());
}
}
//Update times to slaves
countTime = stoi(GetTimeNow()) - refreshTime;
}
else if (FunctionId == TAG_FUNC_EDITCDT) {
if (master && AtcMe) {
bool found = false;
string ttot;
for (size_t i = 0; i < slotList.size(); i++)
{
if (slotList[i].callsign == fp.GetCallsign()) {
if (!slotList[i].ttot.empty()) {
found = true;
ttot = slotList[i].ttot.substr(0, 4);
}
}
}
if (found) {
OpenPopupEdit(Area, TAG_FUNC_TRY_TO_SET_CDT, ttot.c_str());
}
else {
OpenPopupEdit(Area, TAG_FUNC_TRY_TO_SET_CDT, "");
}
}
}
else if (FunctionId == TAG_FUNC_TRY_TO_SET_CDT) {
if (master && AtcMe) {
//only before start-up/push back
if ((string)fp.GetGroundState() != "STUP" || (string)fp.GetGroundState() != "ST-UP" || (string)fp.GetGroundState() != "PUSH" || (string)fp.GetGroundState() != "TAXI" || (string)fp.GetGroundState() != "DEPA") {
string editedCDT = ItemString;
bool hasNoNumber = true;
if (editedCDT.length() == 4) {
for (size_t i = 0; i < editedCDT.length(); i++) {
if (isdigit(editedCDT[i]) == false) {
hasNoNumber = false;
}
}
if (hasNoNumber) {
//First, Re-order main list
slotList = recalculateSlotList(slotList);
string callsign = fp.GetCallsign();
string depRwy = fp.GetFlightPlanData().GetDepartureRwy(); boost::to_upper(depRwy);
if (RadarTargetSelect(callsign.c_str()).IsValid() && depRwy.length() > 0) {
double lat = RadarTargetSelect(callsign.c_str()).GetPosition().GetPosition().m_Latitude;
double lon = RadarTargetSelect(callsign.c_str()).GetPosition().GetPosition().m_Longitude;
string myTaxiTime = getTaxiTime(lat, lon, fp.GetFlightPlanData().GetOrigin(), depRwy);
string calculatedTOBT = calculateLessTime(editedCDT + "00", stod(myTaxiTime));
// at the earlierst at present time + EXOT
if (stoi(calculatedTOBT) > stoi(GetTimeNow())) {
fp.GetControllerAssignedData().SetFlightStripAnnotation(0, calculatedTOBT.substr(0, 4).c_str());
for (size_t i = 0; i < slotList.size(); i++)
{
if ((string)fp.GetCallsign() == slotList[i].callsign) {
slotList[i].ttot = editedCDT + "00";
if (slotList[i].hasCtot && slotList[i].hasRestriction != 0) {
slotList[i].hasCtot = false;
slotList[i].ctot = "";
slotList[i].hasRestriction = 0;
toggleReaMsg(fp, false);
}
}
}
//Add to not modify TOBT if EOBT changes List
bool foundInEobtTobtList = false;
for (size_t i = 0; i < difeobttobtList.size(); i++) {
if ((string)fp.GetCallsign() == difeobttobtList[i]) {
foundInEobtTobtList = true;
}
}
if (!foundInEobtTobtList) {
difeobttobtList.push_back(fp.GetCallsign());