Skip to content

Commit

Permalink
Merge pull request #13 from martja/destination-condition
Browse files Browse the repository at this point in the history
Destination condition
  • Loading branch information
EvenAR authored Mar 25, 2021
2 parents 6f6a295 + 24e4e30 commit 1783b37
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
23 changes: 18 additions & 5 deletions Aman/AmanPlugIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ std::set<std::string> AmanPlugIn::getAvailableIds() {
return set;
}

std::vector<AmanAircraft> AmanPlugIn::getInboundsForFix(const std::string& fixName, std::vector<std::string> viaFixes) {
std::vector<AmanAircraft> AmanPlugIn::getInboundsForFix(const std::string& fixName, std::vector<std::string> viaFixes, std::vector<std::string> destinationAirports) {
long int timeNow = static_cast<long int>(std::time(nullptr)); // Current UNIX-timestamp in seconds

CRadarTarget asel = RadarTargetSelectASEL();
Expand All @@ -69,8 +69,9 @@ std::vector<AmanAircraft> AmanPlugIn::getInboundsForFix(const std::string& fixNa

int targetFixIndex = getFixIndexByName(route, fixName);

if (targetFixIndex != -1 &&
route.GetPointDistanceInMinutes(targetFixIndex) > -1) { // Target fix found and has not been passed
if (targetFixIndex != -1 && // Target fix found
route.GetPointDistanceInMinutes(targetFixIndex) > -1 && // Target fix has not been passed
hasCorrectDestination(rt.GetCorrelatedFlightPlan().GetFlightPlanData(), destinationAirports)) { // Aircraft going to the correct destination
bool fixIsDestination = targetFixIndex == route.GetPointsNumber() - 1;
int timeToFix;

Expand Down Expand Up @@ -173,6 +174,13 @@ void AmanPlugIn::loadTimelines(const std::string& filename) {
}
}

std::vector<std::string> destinationAirports;
if (object.HasMember("destinationAirports") && object["destinationAirports"].IsArray()) {
for (auto& destination : object["destinationAirports"].GetArray()) {
destinationAirports.push_back(destination.GetString());
}
}

std::string alias;
if (object.HasMember("alias") && object["alias"].IsString()) {
alias = object["alias"].GetString();
Expand All @@ -188,10 +196,15 @@ void AmanPlugIn::loadTimelines(const std::string& filename) {
amanController->setTimelineHorizon(alias, startHorizon);
}

timelines.push_back(std::make_shared<AmanTimeline>(targetFixes, viaFixes, alias));
timelines.push_back(std::make_shared<AmanTimeline>(targetFixes, viaFixes, destinationAirports, alias));
}
}

bool AmanPlugIn::hasCorrectDestination(CFlightPlanData fpd, std::vector<std::string> destinationAirports) {
return destinationAirports.size() == 0 ?
true : std::find(destinationAirports.begin(), destinationAirports.end(), fpd.GetDestination()) != destinationAirports.end();
}

int AmanPlugIn::getFixIndexByName(CFlightPlanExtractedRoute extractedRoute, const std::string& fixName) {
for (int i = 0; i < extractedRoute.GetPointsNumber(); i++) {
if (!strcmp(extractedRoute.GetPointName(i), fixName.c_str())) {
Expand Down Expand Up @@ -237,7 +250,7 @@ std::shared_ptr<std::vector<std::shared_ptr<AmanTimeline>>> AmanPlugIn::getTimel

pAircraftList->clear();
for each (auto finalFix in fixes) {
auto var = getInboundsForFix(finalFix, viaFixes);
auto var = getInboundsForFix(finalFix, viaFixes, timeline->getDestinationAirports());
pAircraftList->insert(pAircraftList->end(), var.begin(), var.end());
}

Expand Down
3 changes: 2 additions & 1 deletion Aman/AmanPlugIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ class AmanPlugIn : public CPlugIn {

virtual void OnTimer(int Counter);

bool hasCorrectDestination(CFlightPlanData fpd, std::vector<std::string> destinationAirports);
int getFixIndexByName(CFlightPlanExtractedRoute extractedRoute, const std::string& fixName);
int getFirstViaFixIndex(CFlightPlanExtractedRoute extractedRoute, std::vector<std::string> viaFixes);
double findRemainingDist(CRadarTarget radarTarget, CFlightPlanExtractedRoute extractedRoute, int fixIndex);

std::vector<AmanAircraft> getInboundsForFix(const std::string& fixName, std::vector<std::string> viaFixes);
std::vector<AmanAircraft> getInboundsForFix(const std::string& fixName, std::vector<std::string> viaFixes, std::vector<std::string> destinationAirports);
void loadTimelines(const std::string& filename);

static std::vector<std::string> splitString(const std::string& string, const char delim);
Expand Down
3 changes: 2 additions & 1 deletion Aman/AmanTimeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
#include "AmanAircraft.h"
#include "AmanTimeline.h"

AmanTimeline::AmanTimeline(std::vector<std::string> fixes, std::vector<std::string> viaFixes, const std::string& alias) {
AmanTimeline::AmanTimeline(std::vector<std::string> fixes, std::vector<std::string> viaFixes, std::vector<std::string> destinations, const std::string& alias) {
this->fixes = fixes;
this->viaFixes = viaFixes;
this->aircraftList = std::vector<AmanAircraft>();
this->destinationAirports = destinations;
this->alias = alias;
}

Expand Down
4 changes: 3 additions & 1 deletion Aman/AmanTimeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AmanAircraft;

class AmanTimeline {
public:
AmanTimeline(std::vector<std::string> fixes, std::vector<std::string> viaFixes, const std::string& alias);
AmanTimeline(std::vector<std::string> fixes, std::vector<std::string> viaFixes, std::vector<std::string> destinationAirports, const std::string& alias);
std::string getIdentifier();
bool isDual();
bool containsListForFix(std::string fixName);
Expand All @@ -16,6 +16,7 @@ class AmanTimeline {
std::vector<AmanAircraft> getAircraftList(std::vector<std::string> fixNames);
std::vector<std::string> getFixes() { return fixes; }
std::vector<std::string> getViaFixes() { return viaFixes; }
std::vector<std::string> getDestinationAirports() { return destinationAirports; }

~AmanTimeline();

Expand All @@ -24,5 +25,6 @@ class AmanTimeline {
std::vector<AmanAircraft> aircraftList;
std::vector<std::string> viaFixes;
std::vector<std::string> fixes;
std::vector<std::string> destinationAirports;
};

7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ Example `aman-config.json`:
"alias": "19R/19L",
"targetFixes": [ "GSW40", "GME40" ],
"viaFixes": [ "ADOPI", "LUNIP", "ESEBA", "INREX", "BELGU", "RIPAM" ],
"initialHorizon": 120
"initialHorizon": 120,
"destinationAirports": [ "ENGM" ]
},
{
"alias": "...",
"targetFixes": [ "....", "...." ],
"viaFixes": [ "..." ],
"initialHorizon": 60
"initialHorizon": 60,
"destinationAirports": [ "....", "...." ]
}
]
}
Expand All @@ -31,6 +33,7 @@ Example `aman-config.json`:
| `viaFixes` | (optional) Each fix will be assigned a color, and aircraft with a route initially (any direct routings ignored) going through one of these fixes will be marked with the color. For example, this can give a better overview of which direction each aircraft is coming from. Only eight different colors are available at the moment.
| `alias` | (optional) If used, this will be the ID of the timeline. If not, the name will be generated from `targetFixes`.
| `initialHorizon` | (optional) If used, this will be the initial time horizon (in minutes) when the timeline is loaded.
| `destinationAirports` | (optional) If used, aircraft whose destination is not in `destinationAirports` will not be included.

The information displayed for each aircraft has the following layout:

Expand Down
Binary file modified Release/Aman.dll
Binary file not shown.
3 changes: 2 additions & 1 deletion Release/aman-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"alias": "19R/19L",
"targetFixes": [ "GSW40", "GME40" ],
"viaFixes": [ "ADOPI", "LUNIP", "ESEBA", "INREX", "BELGU", "RIPAM" ],
"startHorizon": 10
"startHorizon": 10,
"destinationAirports": [ "ENGM" ]
}
]
}

0 comments on commit 1783b37

Please sign in to comment.