-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctlController.cpp
193 lines (140 loc) · 4.49 KB
/
ctlController.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
#include "stdafx.h"
#include "ctlController.hpp"
extern "C" IMAGE_DOS_HEADER __ImageBase;
bool blink;
bool debugMode;
int disCount;
ifstream sidDatei;
char DllPathFile[_MAX_PATH];
string pfad;
vector<string> clearedAircraft;
vector<string> landingAlert;
// Run on Plugin Initialization
CCTLPlugin::CCTLPlugin(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 "VCT"
RegisterTagItemType("CTL", TAG_ITEM_CTL);
RegisterTagItemFunction("Toggle Cleared To Land", TAG_FUNC_CTL_TOGGLE);
// Get Path of the VCTdata.json
GetModuleFileNameA(HINSTANCE(&__ImageBase), DllPathFile, sizeof(DllPathFile));
pfad = DllPathFile;
pfad.resize(pfad.size() - strlen("CTL.dll"));
debugMode = false;
//getSids();
// getEvents();
}
// Run on Plugin destruction, Ie. Closing EuroScope or unloading plugin
CCTLPlugin::~CCTLPlugin()
{
}
// All the Euroscope functions
void CCTLPlugin::debugMessage(string type, string message) {
// Display Debug Message if debugMode = true
if (debugMode) {
DisplayUserMessage("CTL", type.c_str(), message.c_str(), true, true, true, false, false);
}
}
void CCTLPlugin::sendMessage(string type, string message) {
// Show a message
DisplayUserMessage("CTL", type.c_str(), message.c_str(), true, true, true, true, false);
}
void CCTLPlugin::sendMessage(string message) {
DisplayUserMessage("Message", "CTL", message.c_str(), true, true, true, false, false);
}
void CCTLPlugin::OnGetTagItem(CFlightPlan FlightPlan, CRadarTarget RadarTarget, int ItemCode, int TagData, char sItemString[16], int* pColorCode, COLORREF* pRGB, double* pFontSize)
{
if (ItemCode == TAG_ITEM_CTL)
{
if (find(clearedAircraft.begin(), clearedAircraft.end(), FlightPlan.GetCallsign()) != clearedAircraft.end()) {
*pColorCode = TAG_COLOR_RGB_DEFINED;
*pRGB = TAG_GREEN;
strcpy_s(sItemString, 16, cleared);
}
else if (
(find(clearedAircraft.begin(), clearedAircraft.end(), FlightPlan.GetCallsign()) == clearedAircraft.end())
&& FlightPlan.GetTrackingControllerIsMe()
&& FlightPlan.GetDistanceToDestination() < 6
&& RadarTarget.GetPosition().GetPressureAltitude() < 1500
) {
*pColorCode = TAG_COLOR_RGB_DEFINED;
*pRGB = TAG_YELLOW;
strcpy_s(sItemString, 16, "CLR");
}
else {
strcpy_s(sItemString, 16, notCleared);
}
/*
*pColorCode = TAG_COLOR_RGB_DEFINED;
int ctl = 172;
bool landStatus = false;
if (!landStatus) {
*pRGB = TAG_GREEN;
strcpy_s(sItemString, 16, notCleared);
}
else {
strcpy_s(sItemString, 16, cleared);
}
*/
}
}
void CCTLPlugin::OnFunctionCall(int FunctionId, const char* sItemString, POINT Pt, RECT Area) {
if (FunctionId == TAG_FUNC_CTL_TOGGLE) {
setClearence(FlightPlanSelectASEL());
}
}
void CCTLPlugin::setClearence(CFlightPlan flightPlan) {
if (find(clearedAircraft.begin(), clearedAircraft.end(), flightPlan.GetCallsign()) == clearedAircraft.end()) {
clearedAircraft.push_back(flightPlan.GetCallsign());
} else {
clearedAircraft.erase(remove(clearedAircraft.begin(), clearedAircraft.end(), flightPlan.GetCallsign()), clearedAircraft.end());
}
}
void CCTLPlugin::removeClearence(CFlightPlan flightPlan) {
if (find(clearedAircraft.begin(), clearedAircraft.end(), flightPlan.GetCallsign()) != clearedAircraft.end()) {
clearedAircraft.erase(remove(clearedAircraft.begin(), clearedAircraft.end(), flightPlan.GetCallsign()), clearedAircraft.end());
}
}
bool CCTLPlugin::isCleared(CFlightPlan flightPlan) {
if (find(clearedAircraft.begin(), clearedAircraft.end(), flightPlan.GetCallsign()) == clearedAircraft.end()) {
return false;
} else {
return true;
}
}
bool CCTLPlugin::OnCompileCommand(const char* sCommandLine) {
if (startsWith(".ctl debug", sCommandLine))
{
if (debugMode) {
debugMessage("DebugMode", "Deactivating Debug Mode!");
debugMode = false;
}
else {
debugMode = true;
debugMessage("DebugMode", "Activating Debug Mode!");
}
return true;
}
return false;
}
void CCTLPlugin::OnTimer(int Counter) {
for (string callsign : clearedAircraft) {
CFlightPlan flightPlan = FlightPlanSelect(callsign.c_str());
CRadarTarget radarTarget = RadarTargetSelect(callsign.c_str());
if (!flightPlan.IsValid()) {
removeClearence(flightPlan);
}
}
blink = !blink;
if (blink) {
if (disCount < 6) {
disCount++;
}
else {
disCount = 0;
}
}
}