2011-04-19 18:01:24 +02:00
|
|
|
// // FGAIFlightPlan - class for loading and storing AI flight plans
|
2004-05-15 09:07:55 +00:00
|
|
|
// Written by David Culp, started May 2004
|
|
|
|
// - davidculp2@comcast.net
|
|
|
|
//
|
|
|
|
// 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
|
2006-02-21 01:16:04 +00:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-05-15 09:07:55 +00:00
|
|
|
|
2006-06-16 10:17:06 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
2004-07-22 18:50:29 +00:00
|
|
|
|
2008-08-14 18:13:39 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2004-05-15 09:07:55 +00:00
|
|
|
#include <simgear/misc/sg_path.hxx>
|
|
|
|
#include <simgear/debug/logstream.hxx>
|
2004-07-22 18:50:29 +00:00
|
|
|
#include <simgear/math/sg_geodesy.hxx>
|
2004-05-15 09:07:55 +00:00
|
|
|
#include <simgear/structure/exception.hxx>
|
|
|
|
#include <simgear/constants.h>
|
|
|
|
#include <simgear/props/props.hxx>
|
2008-07-31 12:04:32 +00:00
|
|
|
#include <simgear/props/props_io.hxx>
|
|
|
|
|
2004-05-15 09:07:55 +00:00
|
|
|
#include <Main/globals.hxx>
|
|
|
|
#include <Main/fg_props.hxx>
|
2004-07-22 18:50:29 +00:00
|
|
|
#include <Main/fg_init.hxx>
|
|
|
|
#include <Airports/simple.hxx>
|
2012-10-30 15:43:54 +00:00
|
|
|
#include <Airports/dynamics.hxx>
|
2004-07-22 18:50:29 +00:00
|
|
|
#include <Airports/runways.hxx>
|
2008-08-14 18:13:39 +00:00
|
|
|
#include <Airports/groundnetwork.hxx>
|
2004-07-22 18:50:29 +00:00
|
|
|
|
|
|
|
#include <Environment/environment_mgr.hxx>
|
|
|
|
#include <Environment/environment.hxx>
|
|
|
|
|
|
|
|
#include "AIFlightPlan.hxx"
|
2009-02-15 15:29:56 +00:00
|
|
|
#include "AIAircraft.hxx"
|
2004-05-15 09:07:55 +00:00
|
|
|
|
2008-08-14 18:13:39 +00:00
|
|
|
using std::cerr;
|
|
|
|
|
2011-07-31 19:27:44 +02:00
|
|
|
FGAIWaypoint::FGAIWaypoint() {
|
|
|
|
speed = 0;
|
|
|
|
crossat = 0;
|
|
|
|
finished = 0;
|
|
|
|
gear_down = 0;
|
|
|
|
flaps_down = 0;
|
|
|
|
on_ground = 0;
|
|
|
|
routeIndex = 0;
|
|
|
|
time_sec = 0;
|
|
|
|
trackLength = 0;
|
|
|
|
}
|
|
|
|
|
2012-11-24 11:59:13 +01:00
|
|
|
bool FGAIWaypoint::contains(const string& target) {
|
2011-07-31 19:27:44 +02:00
|
|
|
size_t found = name.find(target);
|
|
|
|
if (found == string::npos)
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-08 15:52:06 +01:00
|
|
|
double FGAIWaypoint::getLatitude()
|
|
|
|
{
|
|
|
|
return pos.getLatitudeDeg();
|
|
|
|
}
|
|
|
|
|
|
|
|
double FGAIWaypoint::getLongitude()
|
|
|
|
{
|
|
|
|
return pos.getLongitudeDeg();
|
|
|
|
}
|
|
|
|
|
|
|
|
double FGAIWaypoint::getAltitude()
|
|
|
|
{
|
|
|
|
return pos.getElevationFt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FGAIWaypoint::setLatitude(double lat)
|
|
|
|
{
|
|
|
|
pos.setLatitudeDeg(lat);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FGAIWaypoint::setLongitude(double lon)
|
|
|
|
{
|
|
|
|
pos.setLongitudeDeg(lon);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FGAIWaypoint::setAltitude(double alt)
|
|
|
|
{
|
|
|
|
pos.setElevationFt(alt);
|
|
|
|
}
|
|
|
|
|
2012-11-24 13:04:59 +01:00
|
|
|
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)
|
2009-03-08 17:14:05 +00:00
|
|
|
{
|
2012-03-25 14:03:53 +02:00
|
|
|
wpt_iterator = waypoints.begin();
|
2009-03-08 17:14:05 +00:00
|
|
|
}
|
2004-05-15 09:07:55 +00:00
|
|
|
|
2012-11-24 13:04:59 +01:00
|
|
|
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))
|
2004-05-15 09:07:55 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-03 17:59:14 +00:00
|
|
|
// This is a modified version of the constructor,
|
|
|
|
// Which not only reads the waypoints from a
|
|
|
|
// Flight plan file, but also adds the current
|
|
|
|
// Position computed by the traffic manager, as well
|
|
|
|
// as setting speeds and altitude computed by the
|
|
|
|
// traffic manager.
|
2009-01-30 18:48:44 +00:00
|
|
|
FGAIFlightPlan::FGAIFlightPlan(FGAIAircraft *ac,
|
|
|
|
const std::string& p,
|
2012-03-25 14:03:53 +02:00
|
|
|
double course,
|
|
|
|
time_t start,
|
|
|
|
FGAirport *dep,
|
|
|
|
FGAirport *arr,
|
|
|
|
bool firstLeg,
|
|
|
|
double radius,
|
2006-02-11 13:16:56 +00:00
|
|
|
double alt,
|
|
|
|
double lat,
|
|
|
|
double lon,
|
|
|
|
double speed,
|
2012-03-25 14:03:53 +02:00
|
|
|
const string& fltType,
|
|
|
|
const string& acType,
|
2012-10-30 15:43:54 +00:00
|
|
|
const string& airline) :
|
2012-11-24 13:04:59 +01:00
|
|
|
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)
|
2004-06-03 17:59:14 +00:00
|
|
|
{
|
2012-10-30 15:43:54 +00:00
|
|
|
if (parseProperties(p)) {
|
|
|
|
isValid = true;
|
2010-07-23 09:41:37 +01:00
|
|
|
} else {
|
2012-10-30 15:43:54 +00:00
|
|
|
createWaypoints(ac, course, start, dep, arr, firstLeg, radius,
|
|
|
|
alt, lat, lon, speed, fltType, acType, airline);
|
|
|
|
}
|
2004-06-03 17:59:14 +00:00
|
|
|
}
|
|
|
|
|
2004-05-15 09:07:55 +00:00
|
|
|
FGAIFlightPlan::~FGAIFlightPlan()
|
|
|
|
{
|
2005-02-10 09:01:51 +00:00
|
|
|
deleteWaypoints();
|
2012-10-01 17:18:36 +01:00
|
|
|
//delete taxiRoute;
|
2012-10-30 15:43:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FGAIFlightPlan::createWaypoints(FGAIAircraft *ac,
|
|
|
|
double course,
|
|
|
|
time_t start,
|
|
|
|
FGAirport *dep,
|
|
|
|
FGAirport *arr,
|
|
|
|
bool firstLeg,
|
|
|
|
double radius,
|
|
|
|
double alt,
|
|
|
|
double lat,
|
|
|
|
double lon,
|
|
|
|
double speed,
|
|
|
|
const string& fltType,
|
|
|
|
const string& acType,
|
|
|
|
const string& airline)
|
|
|
|
{
|
|
|
|
time_t now = time(NULL) + fgGetLong("/sim/time/warp");
|
|
|
|
time_t timeDiff = now-start;
|
|
|
|
leg = 1;
|
|
|
|
|
|
|
|
if ((timeDiff > 60) && (timeDiff < 1500))
|
|
|
|
leg = 2;
|
|
|
|
//else if ((timeDiff >= 1200) && (timeDiff < 1500)) {
|
|
|
|
//leg = 3;
|
|
|
|
//ac->setTakeOffStatus(2);
|
|
|
|
//}
|
|
|
|
else if ((timeDiff >= 1500) && (timeDiff < 2000))
|
|
|
|
leg = 4;
|
|
|
|
else if (timeDiff >= 2000)
|
|
|
|
leg = 5;
|
|
|
|
/*
|
|
|
|
if (timeDiff >= 2000)
|
|
|
|
leg = 5;
|
|
|
|
*/
|
|
|
|
SG_LOG(SG_AI, SG_INFO, "Route from " << dep->getId() << " to " << arr->getId() << ". Set leg to : " << leg << " " << ac->getTrafficRef()->getCallSign());
|
|
|
|
wpt_iterator = waypoints.begin();
|
|
|
|
bool dist = 0;
|
|
|
|
isValid = create(ac, dep, arr, leg, alt, speed, lat, lon,
|
|
|
|
firstLeg, radius, fltType, acType, airline, dist);
|
|
|
|
wpt_iterator = waypoints.begin();
|
2004-05-15 09:07:55 +00:00
|
|
|
}
|
|
|
|
|
2012-10-30 15:43:54 +00:00
|
|
|
bool FGAIFlightPlan::parseProperties(const std::string& filename)
|
|
|
|
{
|
|
|
|
SGPath path( globals->get_fg_root() );
|
|
|
|
path.append( "/AI/FlightPlans/" + filename );
|
|
|
|
if (!path.exists()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SGPropertyNode root;
|
|
|
|
try {
|
|
|
|
readProperties(path.str(), &root);
|
|
|
|
} catch (const sg_exception &e) {
|
|
|
|
SG_LOG(SG_AI, SG_ALERT, "Error reading AI flight plan: " << path.str()
|
|
|
|
<< "message:" << e.getFormattedMessage());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SGPropertyNode * node = root.getNode("flightplan");
|
|
|
|
for (int i = 0; i < node->nChildren(); i++) {
|
|
|
|
FGAIWaypoint* wpt = new FGAIWaypoint;
|
|
|
|
SGPropertyNode * wpt_node = node->getChild(i);
|
|
|
|
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_down (wpt_node->getBoolValue("flaps-down", false ));
|
|
|
|
wpt->setOn_ground (wpt_node->getBoolValue("on-ground", false ));
|
|
|
|
wpt->setTime_sec (wpt_node->getDoubleValue("time-sec", 0 ));
|
|
|
|
wpt->setTime (wpt_node->getStringValue("time", "" ));
|
|
|
|
wpt->setFinished ((wpt->getName() == "END"));
|
|
|
|
pushBackWaypoint( wpt );
|
|
|
|
}
|
|
|
|
|
|
|
|
wpt_iterator = waypoints.begin();
|
|
|
|
return true;
|
|
|
|
}
|
2004-05-15 09:07:55 +00:00
|
|
|
|
2011-07-31 19:27:44 +02:00
|
|
|
FGAIWaypoint* const FGAIFlightPlan::getPreviousWaypoint( void ) const
|
2004-05-15 09:07:55 +00:00
|
|
|
{
|
|
|
|
if (wpt_iterator == waypoints.begin()) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
wpt_vector_iterator prev = wpt_iterator;
|
|
|
|
return *(--prev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-31 19:27:44 +02:00
|
|
|
FGAIWaypoint* const FGAIFlightPlan::getCurrentWaypoint( void ) const
|
2004-05-15 09:07:55 +00:00
|
|
|
{
|
2012-04-12 19:38:32 +02:00
|
|
|
if (wpt_iterator == waypoints.end())
|
|
|
|
return 0;
|
2004-05-15 09:07:55 +00:00
|
|
|
return *wpt_iterator;
|
|
|
|
}
|
|
|
|
|
2011-07-31 19:27:44 +02:00
|
|
|
FGAIWaypoint* const FGAIFlightPlan::getNextWaypoint( void ) const
|
2004-05-15 09:07:55 +00:00
|
|
|
{
|
2005-02-10 09:01:51 +00:00
|
|
|
wpt_vector_iterator i = waypoints.end();
|
|
|
|
i--; // end() points to one element after the last one.
|
|
|
|
if (wpt_iterator == i) {
|
2004-05-15 09:07:55 +00:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
wpt_vector_iterator next = wpt_iterator;
|
|
|
|
return *(++next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-10 09:01:51 +00:00
|
|
|
void FGAIFlightPlan::IncrementWaypoint(bool eraseWaypoints )
|
2004-05-15 09:07:55 +00:00
|
|
|
{
|
2012-11-27 21:02:32 +01:00
|
|
|
if (eraseWaypoints)
|
2005-02-10 09:01:51 +00:00
|
|
|
{
|
2012-11-27 21:02:32 +01:00
|
|
|
if (wpt_iterator == waypoints.begin())
|
|
|
|
wpt_iterator++;
|
|
|
|
else
|
|
|
|
if (!waypoints.empty())
|
|
|
|
{
|
|
|
|
delete *(waypoints.begin());
|
|
|
|
waypoints.erase(waypoints.begin());
|
|
|
|
wpt_iterator = waypoints.begin();
|
|
|
|
wpt_iterator++;
|
|
|
|
}
|
2005-02-10 09:01:51 +00:00
|
|
|
}
|
2012-11-27 21:02:32 +01:00
|
|
|
else
|
|
|
|
wpt_iterator++;
|
2004-05-15 09:07:55 +00:00
|
|
|
}
|
|
|
|
|
2009-08-25 11:54:49 +02:00
|
|
|
void FGAIFlightPlan::DecrementWaypoint(bool eraseWaypoints )
|
|
|
|
{
|
|
|
|
if (eraseWaypoints)
|
|
|
|
{
|
|
|
|
if (wpt_iterator == waypoints.end())
|
|
|
|
wpt_iterator--;
|
|
|
|
else
|
2012-11-27 21:02:32 +01:00
|
|
|
if (!waypoints.empty())
|
2009-08-25 11:54:49 +02:00
|
|
|
{
|
2012-11-27 21:02:32 +01:00
|
|
|
delete *(waypoints.end()-1);
|
|
|
|
waypoints.erase(waypoints.end()-1);
|
2009-08-25 11:54:49 +02:00
|
|
|
wpt_iterator = waypoints.end();
|
|
|
|
wpt_iterator--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
wpt_iterator--;
|
2011-10-09 23:44:42 +02:00
|
|
|
}
|
2009-08-25 11:54:49 +02:00
|
|
|
|
2011-10-09 23:44:42 +02:00
|
|
|
void FGAIFlightPlan::eraseLastWaypoint()
|
|
|
|
{
|
|
|
|
delete (waypoints.back());
|
|
|
|
waypoints.pop_back();;
|
|
|
|
wpt_iterator = waypoints.begin();
|
|
|
|
wpt_iterator++;
|
2009-08-25 11:54:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-09 23:44:42 +02:00
|
|
|
|
|
|
|
|
2004-05-15 09:07:55 +00:00
|
|
|
// gives distance in feet from a position to a waypoint
|
2011-07-31 19:27:44 +02:00
|
|
|
double FGAIFlightPlan::getDistanceToGo(double lat, double lon, FGAIWaypoint* wp) const{
|
2012-10-08 15:52:06 +01:00
|
|
|
return SGGeodesy::distanceM(SGGeod::fromDeg(lon, lat), wp->getPos());
|
2004-05-15 09:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// sets distance in feet from a lead point to the current waypoint
|
|
|
|
void FGAIFlightPlan::setLeadDistance(double speed, double bearing,
|
2011-07-31 19:27:44 +02:00
|
|
|
FGAIWaypoint* current, FGAIWaypoint* next){
|
2005-02-10 09:01:51 +00:00
|
|
|
double turn_radius;
|
2008-04-02 19:01:48 +00:00
|
|
|
// Handle Ground steering
|
|
|
|
// At a turn rate of 30 degrees per second, it takes 12 seconds to do a full 360 degree turn
|
|
|
|
// So, to get an estimate of the turn radius, calculate the cicumference of the circle
|
|
|
|
// we travel on. Get the turn radius by dividing by PI (*2).
|
2008-11-16 13:41:24 +00:00
|
|
|
if (speed < 0.5) {
|
|
|
|
lead_distance = 0.5;
|
|
|
|
return;
|
|
|
|
}
|
2008-04-02 19:01:48 +00:00
|
|
|
if (speed < 25) {
|
2010-07-24 09:19:37 +02:00
|
|
|
turn_radius = ((360/30)*fabs(speed)) / (2*M_PI);
|
2008-04-02 19:01:48 +00:00
|
|
|
} else
|
2005-02-10 09:01:51 +00:00
|
|
|
turn_radius = 0.1911 * speed * speed; // an estimate for 25 degrees bank
|
|
|
|
|
2004-05-15 09:07:55 +00:00
|
|
|
double inbound = bearing;
|
|
|
|
double outbound = getBearing(current, next);
|
2005-02-10 09:01:51 +00:00
|
|
|
leadInAngle = fabs(inbound - outbound);
|
|
|
|
if (leadInAngle > 180.0)
|
|
|
|
leadInAngle = 360.0 - leadInAngle;
|
2008-04-02 19:01:48 +00:00
|
|
|
//if (leadInAngle < 30.0) // To prevent lead_dist from getting so small it is skipped
|
|
|
|
// leadInAngle = 30.0;
|
2005-02-10 09:01:51 +00:00
|
|
|
|
2008-04-02 19:01:48 +00:00
|
|
|
//lead_distance = turn_radius * sin(leadInAngle * SG_DEGREES_TO_RADIANS);
|
|
|
|
lead_distance = turn_radius * tan((leadInAngle * SG_DEGREES_TO_RADIANS)/2);
|
2010-08-29 19:25:34 +02:00
|
|
|
/*
|
2010-07-24 09:19:37 +02:00
|
|
|
if ((lead_distance > (3*turn_radius)) && (current->on_ground == false)) {
|
2010-07-04 21:00:36 +02:00
|
|
|
// cerr << "Warning: Lead-in distance is large. Inbound = " << inbound
|
|
|
|
// << ". Outbound = " << outbound << ". Lead in angle = " << leadInAngle << ". Turn radius = " << turn_radius << endl;
|
|
|
|
lead_distance = 3 * turn_radius;
|
2010-07-24 09:19:37 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((leadInAngle > 90) && (current->on_ground == true)) {
|
|
|
|
lead_distance = turn_radius * tan((90 * SG_DEGREES_TO_RADIANS)/2);
|
|
|
|
return;
|
2010-08-29 19:25:34 +02:00
|
|
|
}*/
|
2004-05-15 09:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FGAIFlightPlan::setLeadDistance(double distance_ft){
|
|
|
|
lead_distance = distance_ft;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-08 15:52:06 +01:00
|
|
|
double FGAIFlightPlan::getBearing(FGAIWaypoint* first, FGAIWaypoint* second) const
|
|
|
|
{
|
|
|
|
return SGGeodesy::courseDeg(first->getPos(), second->getPos());
|
2004-05-15 09:07:55 +00:00
|
|
|
}
|
|
|
|
|
2012-10-30 15:43:54 +00:00
|
|
|
double FGAIFlightPlan::getBearing(const SGGeod& aPos, FGAIWaypoint* wp) const
|
2012-10-08 15:52:06 +01:00
|
|
|
{
|
2012-10-30 15:43:54 +00:00
|
|
|
return SGGeodesy::courseDeg(aPos, wp->getPos());
|
2004-05-18 09:09:08 +00:00
|
|
|
}
|
2004-05-15 09:07:55 +00:00
|
|
|
|
2005-02-10 09:01:51 +00:00
|
|
|
void FGAIFlightPlan::deleteWaypoints()
|
|
|
|
{
|
|
|
|
for (wpt_vector_iterator i = waypoints.begin(); i != waypoints.end();i++)
|
|
|
|
delete (*i);
|
|
|
|
waypoints.clear();
|
2012-11-27 21:02:32 +01:00
|
|
|
wpt_iterator = waypoints.begin();
|
2005-02-10 09:01:51 +00:00
|
|
|
}
|
2004-07-22 18:50:29 +00:00
|
|
|
|
2005-02-10 09:01:51 +00:00
|
|
|
// Delete all waypoints except the last,
|
|
|
|
// which we will recycle as the first waypoint in the next leg;
|
|
|
|
void FGAIFlightPlan::resetWaypoints()
|
|
|
|
{
|
|
|
|
if (waypoints.begin() == waypoints.end())
|
|
|
|
return;
|
|
|
|
else
|
2004-07-22 18:50:29 +00:00
|
|
|
{
|
2011-07-31 19:27:44 +02:00
|
|
|
FGAIWaypoint *wpt = new FGAIWaypoint;
|
2005-02-10 09:01:51 +00:00
|
|
|
wpt_vector_iterator i = waypoints.end();
|
|
|
|
i--;
|
2011-07-31 19:27:44 +02:00
|
|
|
wpt->setName ( (*i)->getName() );
|
2012-10-08 15:52:06 +01:00
|
|
|
wpt->setPos ( (*i)->getPos() );
|
2011-07-31 19:27:44 +02:00
|
|
|
wpt->setCrossat ( (*i)->getCrossat() );
|
|
|
|
wpt->setGear_down ( (*i)->getGear_down() );
|
|
|
|
wpt->setFlaps_down ( (*i)->getFlaps_down() );
|
|
|
|
wpt->setFinished ( false );
|
|
|
|
wpt->setOn_ground ( (*i)->getOn_ground() );
|
2005-02-10 09:01:51 +00:00
|
|
|
//cerr << "Recycling waypoint " << wpt->name << endl;
|
|
|
|
deleteWaypoints();
|
2011-10-22 10:15:16 +02:00
|
|
|
pushBackWaypoint(wpt);
|
2004-07-22 18:50:29 +00:00
|
|
|
}
|
|
|
|
}
|
2005-06-04 09:38:52 +00:00
|
|
|
|
2011-10-22 10:15:16 +02:00
|
|
|
void FGAIFlightPlan::pushBackWaypoint(FGAIWaypoint *wpt)
|
|
|
|
{
|
|
|
|
// std::vector::push_back invalidates waypoints
|
|
|
|
// so we should restore wpt_iterator after push_back
|
|
|
|
// (or it could be an index in the vector)
|
|
|
|
size_t pos = wpt_iterator - waypoints.begin();
|
|
|
|
waypoints.push_back(wpt);
|
|
|
|
wpt_iterator = waypoints.begin() + pos;
|
|
|
|
}
|
|
|
|
|
2005-06-04 09:38:52 +00:00
|
|
|
// Start flightplan over from the beginning
|
|
|
|
void FGAIFlightPlan::restart()
|
|
|
|
{
|
|
|
|
wpt_iterator = waypoints.begin();
|
|
|
|
}
|
2006-08-26 07:22:20 +00:00
|
|
|
|
|
|
|
int FGAIFlightPlan::getRouteIndex(int i) {
|
2009-05-16 09:40:48 +00:00
|
|
|
if ((i > 0) && (i < (int)waypoints.size())) {
|
2011-07-31 19:27:44 +02:00
|
|
|
return waypoints[i]->getRouteIndex();
|
2006-08-26 07:22:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
2010-08-29 19:25:34 +02:00
|
|
|
|
2012-11-25 16:41:10 +01:00
|
|
|
double FGAIFlightPlan::checkTrackLength(const string& wptName) const {
|
2010-08-29 19:25:34 +02:00
|
|
|
// skip the first two waypoints: first one is behind, second one is partially done;
|
|
|
|
double trackDistance = 0;
|
|
|
|
wpt_vector_iterator wptvec = waypoints.begin();
|
|
|
|
wptvec++;
|
|
|
|
wptvec++;
|
2011-07-31 19:27:44 +02:00
|
|
|
while ((wptvec != waypoints.end()) && (!((*wptvec)->contains(wptName)))) {
|
|
|
|
trackDistance += (*wptvec)->getTrackLength();
|
2010-08-29 19:25:34 +02:00
|
|
|
wptvec++;
|
|
|
|
}
|
|
|
|
if (wptvec == waypoints.end()) {
|
|
|
|
trackDistance = 0; // name not found
|
|
|
|
}
|
|
|
|
return trackDistance;
|
2011-10-09 23:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void FGAIFlightPlan::shortenToFirst(unsigned int number, string name)
|
|
|
|
{
|
|
|
|
while (waypoints.size() > number + 3) {
|
|
|
|
eraseLastWaypoint();
|
|
|
|
}
|
|
|
|
(waypoints.back())->setName((waypoints.back())->getName() + name);
|
|
|
|
}
|
2012-10-01 17:18:36 +01:00
|
|
|
|
2012-11-25 16:41:10 +01:00
|
|
|
void FGAIFlightPlan::setGate(const ParkingAssignment& pka)
|
2012-10-01 17:18:36 +01:00
|
|
|
{
|
|
|
|
gate = pka;
|
|
|
|
}
|
|
|
|
|
|
|
|
FGParking* FGAIFlightPlan::getParkingGate()
|
|
|
|
{
|
|
|
|
return gate.parking();
|
|
|
|
}
|