#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
#include <Main/fg_init.hxx>
-#include <Airports/simple.hxx>
+#include <Airports/airport.hxx>
#include <Airports/dynamics.hxx>
#include <Airports/runways.hxx>
#include <Airports/groundnetwork.hxx>
#include "AIAircraft.hxx"
using std::cerr;
+using std::string;
FGAIWaypoint::FGAIWaypoint() {
speed = 0;
trackLength = 0;
}
-bool FGAIWaypoint::contains(string target) {
+bool FGAIWaypoint::contains(const string& target) {
size_t found = name.find(target);
if (found == string::npos)
return false;
pos.setElevationFt(alt);
}
-FGAIFlightPlan::FGAIFlightPlan()
+FGAIFlightPlan::FGAIFlightPlan() :
+ sid(NULL),
+ repeat(false),
+ distance_to_go(0),
+ lead_distance(0),
+ leadInAngle(0),
+ start_time(0),
+ arrivalTime(0),
+ leg(0),
+ lastNodeVisited(0),
+ isValid(true)
{
- sid = 0;
- repeat = false;
- distance_to_go = 0;
- lead_distance = 0;
- start_time = 0;
- arrivalTime = 0;
- leg = 10;
- gateId = 0;
- lastNodeVisited = 0;
- taxiRoute = 0;
wpt_iterator = waypoints.begin();
- isValid = true;
}
-FGAIFlightPlan::FGAIFlightPlan(const string& filename)
+FGAIFlightPlan::FGAIFlightPlan(const string& filename) :
+ sid(NULL),
+ repeat(false),
+ distance_to_go(0),
+ lead_distance(0),
+ leadInAngle(0),
+ start_time(0),
+ arrivalTime(0),
+ leg(10),
+ lastNodeVisited(0),
+ isValid(parseProperties(filename))
{
- sid = 0;
- repeat = false;
- distance_to_go = 0;
- lead_distance = 0;
- start_time = 0;
- arrivalTime = 0;
- leg = 10;
- gateId = 0;
- lastNodeVisited = 0;
- taxiRoute = 0;
-
-
- isValid = parseProperties(filename);
}
const string& fltType,
const string& acType,
const string& airline) :
- departure(dep),
- arrival(arr)
+ sid(NULL),
+ repeat(false),
+ distance_to_go(0),
+ lead_distance(0),
+ leadInAngle(0),
+ start_time(start),
+ arrivalTime(0),
+ leg(10),
+ lastNodeVisited(0),
+ isValid(false),
+ departure(dep),
+ arrival(arr)
{
- sid = 0;
- repeat = false;
- distance_to_go = 0;
- lead_distance = 0;
- start_time = start;
- arrivalTime = 0;
- leg = 10;
- gateId = 0;
- lastNodeVisited = 0;
- taxiRoute = 0;
-
if (parseProperties(p)) {
isValid = true;
} else {
FGAIFlightPlan::~FGAIFlightPlan()
{
deleteWaypoints();
- delete taxiRoute;
-
-// if we're parked at a gate, release it
- if (gateId >= 0) {
- FGAirport* apt = (leg >= 7) ? arrival : departure;
- if (apt) {
- SG_LOG(SG_AI, SG_INFO, "releasing parking gate " << gateId << " at " << apt->ident());
- apt->getDynamics()->releaseParking(gateId);
- }
- }
+ //delete taxiRoute;
}
void FGAIFlightPlan::createWaypoints(FGAIAircraft *ac,
isValid = create(ac, dep, arr, leg, alt, speed, lat, lon,
firstLeg, radius, fltType, acType, airline, dist);
wpt_iterator = waypoints.begin();
-
}
bool FGAIFlightPlan::parseProperties(const std::string& filename)
void FGAIFlightPlan::IncrementWaypoint(bool eraseWaypoints )
{
- if (eraseWaypoints)
+ if (eraseWaypoints)
{
- if (wpt_iterator == waypoints.begin())
- wpt_iterator++;
- else
- {
- delete *(waypoints.begin());
- waypoints.erase(waypoints.begin());
- wpt_iterator = waypoints.begin();
- wpt_iterator++;
- }
+ if (wpt_iterator == waypoints.begin())
+ wpt_iterator++;
+ else
+ if (!waypoints.empty())
+ {
+ delete *(waypoints.begin());
+ waypoints.erase(waypoints.begin());
+ wpt_iterator = waypoints.begin();
+ wpt_iterator++;
+ }
}
- else
- wpt_iterator++;
-
+ else
+ wpt_iterator++;
}
void FGAIFlightPlan::DecrementWaypoint(bool eraseWaypoints )
if (wpt_iterator == waypoints.end())
wpt_iterator--;
else
+ if (!waypoints.empty())
{
- delete *(waypoints.end());
- waypoints.erase(waypoints.end());
+ delete *(waypoints.end()-1);
+ waypoints.erase(waypoints.end()-1);
wpt_iterator = waypoints.end();
wpt_iterator--;
}
for (wpt_vector_iterator i = waypoints.begin(); i != waypoints.end();i++)
delete (*i);
waypoints.clear();
+ wpt_iterator = waypoints.begin();
}
// Delete all waypoints except the last,
wpt_iterator = waypoints.begin();
}
-
-void FGAIFlightPlan::deleteTaxiRoute()
-{
- delete taxiRoute;
- taxiRoute = 0;
-}
-
-
int FGAIFlightPlan::getRouteIndex(int i) {
if ((i > 0) && (i < (int)waypoints.size())) {
return waypoints[i]->getRouteIndex();
return 0;
}
-
-double FGAIFlightPlan::checkTrackLength(string wptName) {
+double FGAIFlightPlan::checkTrackLength(const string& wptName) const {
// skip the first two waypoints: first one is behind, second one is partially done;
double trackDistance = 0;
wpt_vector_iterator wptvec = waypoints.begin();
}
(waypoints.back())->setName((waypoints.back())->getName() + name);
}
+
+void FGAIFlightPlan::setGate(const ParkingAssignment& pka)
+{
+ gate = pka;
+}
+
+FGParking* FGAIFlightPlan::getParkingGate()
+{
+ return gate.parking();
+}
+
+FGAirportRef FGAIFlightPlan::departureAirport() const
+{
+ return departure;
+}
+
+FGAirportRef FGAIFlightPlan::arrivalAirport() const
+{
+ return arrival;
+}