Maintenance: sidstar
SPDX tags. header guard. activeRunway parameter changed to const&. getId() made const.
This commit is contained in:
parent
f9509bf334
commit
7eaca793a6
2 changed files with 90 additions and 119 deletions
|
@ -1,25 +1,12 @@
|
|||
// sidstar.cxx - Code to manage departure / arrival procedures
|
||||
// Written by Durk Talsma, started March 2009.
|
||||
//
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// $Id$
|
||||
/*
|
||||
* SPDX-FileName: sidstar.cxx
|
||||
* SPDX-FileComment: Code to manage departure / arrival procedures
|
||||
* SPDX-FileCopyrightText: Written by Durk Talsma, started March 2009
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
@ -33,88 +20,88 @@
|
|||
|
||||
#include "sidstar.hxx"
|
||||
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
using std::string;
|
||||
|
||||
FGSidStar::FGSidStar(FGAirport *ap) {
|
||||
id = ap->getId();
|
||||
initialized = false;
|
||||
FGSidStar::FGSidStar(FGAirport* ap) : id{ap->getId()}
|
||||
{
|
||||
initialized = false;
|
||||
}
|
||||
|
||||
|
||||
FGSidStar::FGSidStar(const FGSidStar &other) {
|
||||
cerr << "TODO" << endl;
|
||||
FGSidStar::FGSidStar(const FGSidStar& other)
|
||||
{
|
||||
std::cerr << "TODO" << std::endl;
|
||||
}
|
||||
|
||||
void FGSidStar::load(SGPath filename) {
|
||||
SGPropertyNode root;
|
||||
string runway;
|
||||
string name;
|
||||
try {
|
||||
readProperties(filename, &root);
|
||||
} catch (const sg_exception &) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT,
|
||||
"Error reading AI flight plan: " << filename);
|
||||
// cout << path.str() << endl;
|
||||
return;
|
||||
}
|
||||
void FGSidStar::load(SGPath filename)
|
||||
{
|
||||
SGPropertyNode root;
|
||||
|
||||
SGPropertyNode * node = root.getNode("SIDS");
|
||||
FGAIFlightPlan *fp;
|
||||
for (int i = 0; i < node->nChildren(); i++) {
|
||||
fp = new FGAIFlightPlan;
|
||||
SGPropertyNode * fpl_node = node->getChild(i);
|
||||
name = fpl_node->getStringValue("name", "END");
|
||||
runway = fpl_node->getStringValue("runway", "27");
|
||||
//cerr << "Runway = " << runway << endl;
|
||||
fp->setName(name);
|
||||
SGPropertyNode * wpts_node = fpl_node->getNode("wpts");
|
||||
for (int j = 0; j < wpts_node->nChildren(); j++) {
|
||||
FGAIWaypoint* wpt = new FGAIWaypoint;
|
||||
SGPropertyNode * wpt_node = wpts_node->getChild(j);
|
||||
//cerr << "Reading waypoint " << j << wpt_node->getStringValue("name", "END") << endl;
|
||||
wpt->setName (wpt_node->getStringValue("name", "END"));
|
||||
wpt->setLatitude (wpt_node->getDoubleValue("lat", 0));
|
||||
wpt->setLongitude (wpt_node->getDoubleValue("lon", 0));
|
||||
wpt->setAltitude (wpt_node->getDoubleValue("alt", 0));
|
||||
wpt->setSpeed (wpt_node->getDoubleValue("ktas", 0));
|
||||
wpt->setCrossat (wpt_node->getDoubleValue("crossat", -10000));
|
||||
wpt->setGear_down (wpt_node->getBoolValue("gear-down", false));
|
||||
wpt->setFlaps (wpt_node->getBoolValue("flaps-down", false) ? 0.5 : 0.0); // We'll assume all SIDS only require half flaps
|
||||
wpt->setOn_ground (wpt_node->getBoolValue("on-ground", false));
|
||||
wpt->setTime_sec (wpt_node->getDoubleValue("time-sec", 0));
|
||||
wpt->setTime (wpt_node->getStringValue("time", ""));
|
||||
try {
|
||||
readProperties(filename, &root);
|
||||
} catch (const sg_exception&) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "Error reading AI flight plan: " << filename);
|
||||
// cout << path.str() << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (wpt->contains("END"))
|
||||
SGPropertyNode* node = root.getNode("SIDS");
|
||||
FGAIFlightPlan* fp;
|
||||
|
||||
for (int i = 0; i < node->nChildren(); i++) {
|
||||
fp = new FGAIFlightPlan;
|
||||
SGPropertyNode* fpl_node = node->getChild(i);
|
||||
std::string name = fpl_node->getStringValue("name", "END");
|
||||
std::string runway = fpl_node->getStringValue("runway", "27");
|
||||
//std::cerr << "Runway = " << runway << std::endl;
|
||||
|
||||
fp->setName(name);
|
||||
SGPropertyNode* wpts_node = fpl_node->getNode("wpts");
|
||||
|
||||
for (int j = 0; j < wpts_node->nChildren(); j++) {
|
||||
FGAIWaypoint* wpt = new FGAIWaypoint;
|
||||
SGPropertyNode* wpt_node = wpts_node->getChild(j);
|
||||
//std::cerr << "Reading waypoint " << j << wpt_node->getStringValue("name", "END") << std::endl;
|
||||
|
||||
wpt->setName(wpt_node->getStringValue("name", "END"));
|
||||
wpt->setLatitude(wpt_node->getDoubleValue("lat", 0));
|
||||
wpt->setLongitude(wpt_node->getDoubleValue("lon", 0));
|
||||
wpt->setAltitude(wpt_node->getDoubleValue("alt", 0));
|
||||
wpt->setSpeed(wpt_node->getDoubleValue("ktas", 0));
|
||||
wpt->setCrossat(wpt_node->getDoubleValue("crossat", -10000));
|
||||
wpt->setGear_down(wpt_node->getBoolValue("gear-down", false));
|
||||
wpt->setFlaps(wpt_node->getBoolValue("flaps-down", false) ? 0.5 : 0.0); // We'll assume all SIDS only require half-flaps
|
||||
wpt->setOn_ground(wpt_node->getBoolValue("on-ground", false));
|
||||
wpt->setTime_sec(wpt_node->getDoubleValue("time-sec", 0));
|
||||
wpt->setTime(wpt_node->getStringValue("time", ""));
|
||||
|
||||
if (wpt->contains("END"))
|
||||
wpt->setFinished(true);
|
||||
else
|
||||
else
|
||||
wpt->setFinished(false);
|
||||
|
||||
//
|
||||
fp->addWaypoint( wpt );
|
||||
}
|
||||
data[runway].push_back(fp);
|
||||
//cerr << "Runway = " << runway << endl;
|
||||
}
|
||||
//
|
||||
fp->addWaypoint(wpt);
|
||||
}
|
||||
data[runway].push_back(fp);
|
||||
//std::cerr << "Runway = " << runway << std::endl;
|
||||
}
|
||||
|
||||
|
||||
//wpt_iterator = waypoints.begin();
|
||||
//cout << waypoints.size() << " waypoints read." << endl;
|
||||
//wpt_iterator = waypoints.begin();
|
||||
//cout << waypoints.size() << " waypoints read." << std::endl;
|
||||
}
|
||||
|
||||
|
||||
FGAIFlightPlan *FGSidStar::getBest(string activeRunway, double heading)
|
||||
FGAIFlightPlan* FGSidStar::getBest(const std::string& activeRunway, double heading)
|
||||
{
|
||||
//cerr << "Getting best procedure for " << activeRunway << endl;
|
||||
//std::cerr << "Getting best procedure for " << activeRunway << std::endl;
|
||||
for (FlightPlanVecIterator i = data[activeRunway].begin(); i != data[activeRunway].end(); i++) {
|
||||
//cerr << (*i)->getName() << endl;
|
||||
//std::cerr << (*i)->getName() << std::endl;
|
||||
}
|
||||
int size = data[activeRunway].size();
|
||||
//cerr << "size is " << size << endl;
|
||||
//std::cerr << "size is " << size << std::endl;
|
||||
if (size) {
|
||||
return data[activeRunway][(rand() % size)];
|
||||
} else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,48 +1,32 @@
|
|||
// sidstar.hxx - a class to store and maintain data for SID and STAR
|
||||
// procedures.
|
||||
// Written by Durk Talsma, started March 2009.
|
||||
//
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// $Id$
|
||||
/*
|
||||
* SPDX-FileName: sidstar.hxx
|
||||
* SPDX-FileComment: a class to store and maintain data for SID and STAR procedures
|
||||
* SPDX-FileCopyrightText: Written by Durk Talsma, started March 2009
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _SIDSTAR_HXX_
|
||||
#define _SIDSTAR_HXX_
|
||||
|
||||
#include "airports_fwd.hxx"
|
||||
#include <ATC/trafficcontrol.hxx>
|
||||
#pragma once
|
||||
|
||||
#include <simgear/misc/sg_path.hxx>
|
||||
#include <simgear/xml/easyxml.hxx>
|
||||
|
||||
#include <ATC/trafficcontrol.hxx>
|
||||
|
||||
#include "airports_fwd.hxx"
|
||||
|
||||
|
||||
class FGSidStar
|
||||
{
|
||||
private:
|
||||
std::string id;
|
||||
bool initialized;
|
||||
FlightPlanVecMap data;
|
||||
private:
|
||||
std::string id;
|
||||
bool initialized;
|
||||
FlightPlanVecMap data;
|
||||
|
||||
public:
|
||||
FGSidStar(FGAirport *ap);
|
||||
FGSidStar(const FGSidStar &other);
|
||||
public:
|
||||
explicit FGSidStar(FGAirport* ap);
|
||||
FGSidStar(const FGSidStar& other);
|
||||
|
||||
std::string getId() { return id; };
|
||||
void load(SGPath path);
|
||||
FGAIFlightPlan *getBest(std::string activeRunway, double heading);
|
||||
std::string getId() const { return id; };
|
||||
void load(SGPath path);
|
||||
FGAIFlightPlan* getBest(const std::string& activeRunway, double heading);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue