Skip to content

Commit

Permalink
Add AFL custom number mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
KingfuChan committed Mar 13, 2022
1 parent 2dfd931 commit 4072f64
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 54 deletions.
33 changes: 29 additions & 4 deletions MTEPlugIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ bool IsCFLAssigned(CFlightPlan FlightPlan);
const char* SETTING_CUSTOM_CURSOR = "CustomCursor";
const char* SETTING_ROUTE_CHECKER_CSV = "RteCheckerCSV";
const char* SETTING_AUTO_RETRACK = "AutoRetrack";
const char* SETTING_CUSTOM_NUMBER_MAP = "CustomNumber0-9";

// WINAPI RELATED
WNDPROC prevWndFunc = nullptr;
Expand Down Expand Up @@ -98,6 +99,15 @@ CMTEPlugIn::CMTEPlugIn(void)
const char* setar = GetDataFromSettings(SETTING_AUTO_RETRACK);
m_AutoRetrack = setar == nullptr ? false : stoi(setar);

const char* setnm = GetDataFromSettings(SETTING_CUSTOM_NUMBER_MAP);
m_CustomNumMap = "012345679";
if (setnm != nullptr) {
if (strlen(setnm) == 10) {
m_CustomNumMap = setnm;
DisplayUserMessage("MESSAGE", "MTEPlugin", ("Numbers are mapped to (0-9): " + m_CustomNumMap).c_str(), 1, 0, 0, 0, 0);
}
}

AddAlias(".mteplugin", GITHUB_LINK); // for testing and for fun

RegisterTagItemType("GS(KPH) with trend indicator", TAG_ITEM_TYPE_GS_W_IND);
Expand Down Expand Up @@ -202,6 +212,11 @@ void CMTEPlugIn::OnGetTagItem(CFlightPlan FlightPlan, CRadarTarget RadarTarget,
if (!m_TrackedRecorder->IsForceFeet(FlightPlan.GetCallsign())) {
dspAlt = (int)round(MetricAlt::FeettoM(rdrAlt) / 10.0);
sprintf_s(sItemString, 5, "%04d", OVRFLW4(dspAlt));
if (rdrAlt < GetTransitionAltitude()) {
// use custom number mapping
for (size_t i = 0; i < 4; i++)
*(sItemString + i) = m_CustomNumMap[(int)(*(sItemString + i) - '0')];
}
}
else {
dspAlt = (int)round(rdrAlt / 100.0);
Expand All @@ -214,10 +229,10 @@ void CMTEPlugIn::OnGetTagItem(CFlightPlan FlightPlan, CRadarTarget RadarTarget,
switch (cflAlt)
{
case 2: // cleared for visual approach
sprintf_s(sItemString, 5, "VA ");
sprintf_s(sItemString, 3, "VA");
break;
case 1: // cleared for ILS approach
sprintf_s(sItemString, 5, "ILS ");
sprintf_s(sItemString, 4, "ILS");
break;
case 0: { // no cleared level or CFL==RFL
if (!IsCFLAssigned(FlightPlan)) {
Expand Down Expand Up @@ -701,8 +716,8 @@ void CMTEPlugIn::OnRadarTargetPositionUpdate(CRadarTarget RadarTarget)
m_TrackedRecorder->UpdateFlight(RadarTarget);
}
else if (m_AutoRetrack) {
m_TrackedRecorder->SetTrackedData(RadarTarget);
if (m_AutoRetrack == 2) {
bool r = m_TrackedRecorder->SetTrackedData(RadarTarget);
if (r && m_AutoRetrack == 2) {
string msg = string(RadarTarget.GetCallsign()) + " reconnected and is re-tracked.";
DisplayUserMessage("MTEP-Recorder", "MTEPlugin", msg.c_str(), 1, 1, 0, 0, 0);
}
Expand Down Expand Up @@ -799,6 +814,7 @@ bool CMTEPlugIn::OnCompileCommand(const char* sCommandLine) {
return true;
}

// set auto retrack
regex rxtrrt("^.MTEP TR ([0-2])$", regex_constants::icase);
if (regex_match(cmd, match, rxtrrt)) {
string res = match[1].str();
Expand All @@ -821,6 +837,15 @@ bool CMTEPlugIn::OnCompileCommand(const char* sCommandLine) {
return true;
}

// set custom number mapping
regex rxnm("^.MTEP NUM ([\\S]{10})$", regex_constants::icase);
if (regex_match(cmd, match, rxnm)) {
m_CustomNumMap = match[1].str();
SaveDataToSettings(SETTING_CUSTOM_NUMBER_MAP, "custom number mapping (0-9)", m_CustomNumMap.c_str());
DisplayUserMessage("MESSAGE", "MTEPlugin", ("Numbers are mapped to (0-9): " + m_CustomNumMap).c_str(), 1, 0, 0, 0, 0);
return true;
}

return false;
}

Expand Down
1 change: 1 addition & 0 deletions MTEPlugIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class CMTEPlugIn :
TrackedRecorder* m_TrackedRecorder;
bool m_CustomCursor;
int m_AutoRetrack; // 0: off; 1: silent; 2: notified.
string m_CustomNumMap; // 0-9

int GetRadarDisplayAltitude(CRadarTarget RadarTarget);
void SetCustomCursor(void);
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Miscellaneous Tag Enhancement Plugin for EuroScope (MTEPlugin)
3. **Vertical speed (4-digit FPM)** - vertical speed in xxxx, will not display if vs<=100 fpm.
4. **Climb/Descend/Level indicator** - combination of climb, descent, level flight indicator. Threshold is 100 fpm.
5. **Actual altitude (m)** - uses QNH altitude below transition level and STD altitude above.
+ Allows custom number mapping if below transition level. See command line features below
6. **Cleared flight level (m/FL)** - shows Chinese metric RVSM levels if matches, or FLxxx, otherwise calculated meters.
7. **Cleared flight level (m)** - shows Chinese metric RVSM levels if matches, otherwise calculated meters.
+ Similar to item 6, but won't show ILS/VA or Fxxx. More useful in a Sweatbox simulator session.
Expand Down Expand Up @@ -158,3 +159,4 @@ All command line functions are case-insensitive, including those mentioned above

1. **.MTEP FR24 ICAO / .MTEP VARI ICAO** - opens [Flightradar24](https://www.flightradar24.com/) / [飞常准ADS-B](https://flightadsb.variflight.com/) in web browser and centers the map on the given **ICAO** airport. Only works with airports within sector file.
2. **.MTEP CURSOR ON/OFF** - turns mouse cursor into Topsky or Eurocat style; may conflict with other plugins. This setting will be saved in your EuroScope plugin settings.
3. **.MTEP NUM 0123456789** - sets custom number mapping to replace corresponding 0-9 characters, which will be used in **Actual altitude (m)** if below transition level (Tips: use with custom font, e.g. number underscores). Note that not all characters are available, use at own risk of crashing EuroScope (offline setting recommended). This setting will be saved in your EuroScope plugin settings.
65 changes: 20 additions & 45 deletions TrackedRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void TrackedRecorder::UpdateFlight(EuroScopePlugIn::CFlightPlan FlightPlan, bool
if (r != m_TrackedMap.end()) {
if (FlightPlan.GetTrackingControllerIsMe()) {
// recorded, tracking. update
auto tad = ExtractAssignedData(FlightPlan);
auto tad = AssignedData(FlightPlan);
bool rfsc = !(
tad.m_ScratchPad == r->second.m_AssignedData.m_ScratchPad &&
tad.m_CommType == r->second.m_AssignedData.m_CommType &&
Expand All @@ -38,13 +38,7 @@ void TrackedRecorder::UpdateFlight(EuroScopePlugIn::CFlightPlan FlightPlan, bool
}
else if (FlightPlan.GetTrackingControllerIsMe()) {
// not recorded but tracking. add
TrackedData trd{};
trd.m_SystemID = FlightPlan.GetCorrelatedRadarTarget().GetSystemID();
trd.m_Offline = false;
trd.m_CommEstbed = false;
trd.m_CFLConfirmed = false;
trd.m_ForceFeet = false;
trd.m_AssignedData = ExtractAssignedData(FlightPlan);
TrackedData trd{ FlightPlan.GetCorrelatedRadarTarget().GetSystemID(), AssignedData(FlightPlan) };
m_TrackedMap.insert({ FlightPlan.GetCallsign(), trd });
RefreshSimilarCallsign();
}
Expand All @@ -70,13 +64,7 @@ void TrackedRecorder::UpdateFlight(EuroScopePlugIn::CRadarTarget RadarTarget)
}
else if (FlightPlan.GetTrackingControllerIsMe()) {
// not recorded, tracking. add
TrackedData trd{};
trd.m_SystemID = RadarTarget.GetSystemID();
trd.m_Offline = false;
trd.m_CommEstbed = false;
trd.m_CFLConfirmed = false;
trd.m_ForceFeet = false;
trd.m_AssignedData = ExtractAssignedData(FlightPlan);
TrackedData trd{ RadarTarget.GetSystemID(), AssignedData(FlightPlan) };
m_TrackedMap.insert({ FlightPlan.GetCallsign(), trd });
RefreshSimilarCallsign();
}
Expand Down Expand Up @@ -178,14 +166,22 @@ unordered_set<string> TrackedRecorder::GetSimilarCallsigns(string callsign)
return unordered_set<string>();
}

void TrackedRecorder::SetTrackedData(EuroScopePlugIn::CFlightPlan FlightPlan)
bool TrackedRecorder::SetTrackedData(EuroScopePlugIn::CFlightPlan FlightPlan)
{
// returns true if success
auto trd = m_TrackedMap.find(FlightPlan.GetCallsign());
if (trd == m_TrackedMap.end())
return;
return false;
// radar target
if (!FlightPlan.GetCorrelatedRadarTarget().IsValid() && trd->second.m_SystemID.size()) {
auto corrRT = m_PluginPtr->RadarTargetSelect(trd->second.m_SystemID.c_str());
if (corrRT.IsValid()) {
FlightPlan.CorrelateWithRadarTarget(corrRT);
}
}
// flight plan
trd->second.m_Offline = true; // prevent following assigns removing
TrackedRecorder::AssignedData tad = trd->second.m_AssignedData;
AssignedData tad(trd->second.m_AssignedData);
auto asd = FlightPlan.GetControllerAssignedData();
asd.SetSquawk(tad.m_Squawk.c_str());
asd.SetFinalAltitude(tad.m_FinalAlt);
Expand All @@ -201,48 +197,27 @@ void TrackedRecorder::SetTrackedData(EuroScopePlugIn::CFlightPlan FlightPlan)
asd.SetAssignedHeading(tad.m_Heading);
else if (tad.m_DCTName.size())
asd.SetDirectToPointName(tad.m_DCTName.c_str());
FlightPlan.StartTracking();
trd->second.m_Offline = false;
// radar target
if (!FlightPlan.GetCorrelatedRadarTarget().IsValid() && trd->second.m_SystemID.size()) {
auto corrRT = m_PluginPtr->RadarTargetSelect(trd->second.m_SystemID.c_str());
if (corrRT.IsValid()) {
FlightPlan.CorrelateWithRadarTarget(corrRT);
}
}
return FlightPlan.StartTracking();
}

void TrackedRecorder::SetTrackedData(EuroScopePlugIn::CRadarTarget RadarTarget)
bool TrackedRecorder::SetTrackedData(EuroScopePlugIn::CRadarTarget RadarTarget)
{
// returns true if success
auto FlightPlan = RadarTarget.GetCorrelatedFlightPlan();
if (FlightPlan.IsValid()) {
SetTrackedData(FlightPlan);
return SetTrackedData(FlightPlan);
}
else {
auto trp = GetTrackedDataBySystemID(RadarTarget.GetSystemID());
if (trp != m_TrackedMap.end()) {
auto corrFP = m_PluginPtr->FlightPlanSelect(trp->first.c_str());
if (corrFP.IsValid()) {
SetTrackedData(corrFP);
RadarTarget.CorrelateWithFlightPlan(corrFP); // set data at next radar refresh
}
}
}
}

TrackedRecorder::AssignedData TrackedRecorder::ExtractAssignedData(EuroScopePlugIn::CFlightPlan FlightPlan)
{
AssignedData tad{};
tad.m_Squawk = FlightPlan.GetControllerAssignedData().GetSquawk();
tad.m_FinalAlt = FlightPlan.GetControllerAssignedData().GetFinalAltitude();
tad.m_ClearedAlt = FlightPlan.GetControllerAssignedData().GetClearedAltitude();
tad.m_CommType = FlightPlan.IsTextCommunication() ? 'T' : FlightPlan.GetControllerAssignedData().GetCommunicationType();
tad.m_ScratchPad = FlightPlan.GetControllerAssignedData().GetScratchPadString();
tad.m_Speed = FlightPlan.GetControllerAssignedData().GetAssignedSpeed();
tad.m_Mach = FlightPlan.GetControllerAssignedData().GetAssignedMach();
tad.m_Rate = FlightPlan.GetControllerAssignedData().GetAssignedRate();
tad.m_Heading = FlightPlan.GetControllerAssignedData().GetAssignedHeading();
tad.m_DCTName = FlightPlan.GetControllerAssignedData().GetDirectToPointName();
return tad;
return false;
}

unordered_map<string, TrackedRecorder::TrackedData>::iterator TrackedRecorder::GetTrackedDataBySystemID(string systemID)
Expand Down
25 changes: 21 additions & 4 deletions TrackedRecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class TrackedRecorder
bool IsActive(EuroScopePlugIn::CRadarTarget RadarTarget);
bool IsSimilarCallsign(string callsign);
unordered_set<string> GetSimilarCallsigns(string callsign);
void SetTrackedData(EuroScopePlugIn::CFlightPlan FlightPlan);
void SetTrackedData(EuroScopePlugIn::CRadarTarget RadarTarget);
bool SetTrackedData(EuroScopePlugIn::CFlightPlan FlightPlan);
bool SetTrackedData(EuroScopePlugIn::CRadarTarget RadarTarget);

private:
struct AssignedData {
Expand All @@ -49,6 +49,19 @@ class TrackedRecorder
int m_Rate;
int m_Heading;
string m_DCTName;

AssignedData(EuroScopePlugIn::CFlightPlan _fp) :
m_Squawk(_fp.GetControllerAssignedData().GetSquawk()),
m_FinalAlt(_fp.GetFinalAltitude()),
m_ClearedAlt(_fp.GetControllerAssignedData().GetClearedAltitude()),
m_CommType(_fp.IsTextCommunication() ? 'T' : _fp.GetControllerAssignedData().GetCommunicationType()),
m_ScratchPad(_fp.GetControllerAssignedData().GetScratchPadString()),
m_Speed(_fp.GetControllerAssignedData().GetAssignedSpeed()),
m_Mach(_fp.GetControllerAssignedData().GetAssignedMach()),
m_Rate(_fp.GetControllerAssignedData().GetAssignedRate()),
m_Heading(_fp.GetControllerAssignedData().GetAssignedHeading()),
m_DCTName(_fp.GetControllerAssignedData().GetDirectToPointName())
{};
};
struct TrackedData {
string m_SystemID;
Expand All @@ -57,14 +70,18 @@ class TrackedRecorder
bool m_CFLConfirmed;
bool m_ForceFeet;
AssignedData m_AssignedData;

TrackedData(string _sID, AssignedData _asd) :
m_SystemID(_sID),
m_Offline(false), m_CommEstbed(false), m_CFLConfirmed(true), m_ForceFeet(false),
m_AssignedData(_asd)
{};
};

EuroScopePlugIn::CPlugIn* m_PluginPtr;
unordered_map<string, TrackedData> m_TrackedMap; // callsign
unordered_map<string, unordered_set<string>> m_SCSetMap; // callsign

AssignedData ExtractAssignedData(EuroScopePlugIn::CFlightPlan FlightPlan);
unordered_map<string, TrackedData>::iterator GetTrackedDataBySystemID(string systemID);
void RefreshSimilarCallsign(void);

};
2 changes: 1 addition & 1 deletion Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#define VERSION_MAJOR 3
#define VERSION_MINOR 1
#define VERSION_REVISION 4
#define VERSION_BUILD 316
#define VERSION_BUILD 319

#define VERSION_FILE VERSION_MAJOR,VERSION_MINOR,VERSION_REVISION
#define VERSION_FILE_STR \
Expand Down

0 comments on commit 4072f64

Please sign in to comment.