2011-08-07 21:38:50 +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
|
2012-05-05 01:42:41 +02:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-05-15 09:07:55 +00:00
|
|
|
|
|
|
|
#ifndef _FG_AIFLIGHTPLAN_HXX
|
|
|
|
#define _FG_AIFLIGHTPLAN_HXX
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2012-10-30 15:43:54 +00:00
|
|
|
|
|
|
|
#include <simgear/compiler.h>
|
2012-10-08 15:52:06 +01:00
|
|
|
#include <simgear/math/SGMath.hxx>
|
2012-10-30 15:43:54 +00:00
|
|
|
#include <simgear/structure/SGSharedPtr.hxx>
|
2012-10-01 17:18:36 +01:00
|
|
|
#include <Navaids/positioned.hxx>
|
|
|
|
#include <Airports/dynamics.hxx>
|
2009-01-30 18:48:44 +00:00
|
|
|
|
2011-07-31 19:27:44 +02:00
|
|
|
class FGAIWaypoint {
|
|
|
|
private:
|
2010-10-20 17:54:16 +01:00
|
|
|
std::string name;
|
2012-10-08 15:52:06 +01:00
|
|
|
SGGeod pos;
|
2004-05-15 09:07:55 +00:00
|
|
|
double speed;
|
|
|
|
double crossat;
|
2004-05-18 09:09:08 +00:00
|
|
|
bool finished;
|
2004-05-15 09:07:55 +00:00
|
|
|
bool gear_down;
|
|
|
|
bool flaps_down;
|
2004-05-21 16:50:19 +00:00
|
|
|
bool on_ground;
|
2006-08-26 07:22:20 +00:00
|
|
|
int routeIndex; // For AI/ATC purposes;
|
2007-03-30 22:51:52 +00:00
|
|
|
double time_sec;
|
2011-07-31 19:27:44 +02:00
|
|
|
double trackLength; // distance from previous FGAIWaypoint (for AI purposes);
|
2010-10-20 17:54:16 +01:00
|
|
|
std::string time;
|
2007-03-30 22:51:52 +00:00
|
|
|
|
2011-07-31 19:27:44 +02:00
|
|
|
public:
|
|
|
|
FGAIWaypoint();
|
|
|
|
~FGAIWaypoint() {};
|
2012-11-24 11:59:13 +01:00
|
|
|
void setName (const std::string& nam) { name = nam; };
|
2012-10-08 15:52:06 +01:00
|
|
|
void setLatitude (double lat);
|
|
|
|
void setLongitude (double lon);
|
|
|
|
void setAltitude (double alt);
|
|
|
|
void setPos (const SGGeod& aPos) { pos = aPos; }
|
2011-07-31 19:27:44 +02:00
|
|
|
void setSpeed (double spd) { speed = spd; };
|
|
|
|
void setCrossat (double val) { crossat = val; };
|
|
|
|
void setFinished (bool fin) { finished = fin; };
|
|
|
|
void setGear_down (bool grd) { gear_down = grd; };
|
|
|
|
void setFlaps_down (bool fld) { flaps_down = fld; };
|
|
|
|
void setOn_ground (bool grn) { on_ground = grn; };
|
|
|
|
void setRouteIndex (int rte) { routeIndex = rte; };
|
|
|
|
void setTime_sec (double ts ) { time_sec = ts; };
|
|
|
|
void setTrackLength (double tl ) { trackLength = tl; };
|
2012-11-24 11:59:13 +01:00
|
|
|
void setTime (const std::string& tme) { time = tme; };
|
2011-07-31 19:27:44 +02:00
|
|
|
|
2012-11-24 11:59:13 +01:00
|
|
|
bool contains(const std::string& name);
|
2011-07-31 19:27:44 +02:00
|
|
|
|
2012-11-24 11:59:13 +01:00
|
|
|
const std::string& getName() { return name; };
|
2012-10-08 15:52:06 +01:00
|
|
|
const SGGeod& getPos () { return pos; };
|
|
|
|
double getLatitude ();
|
|
|
|
double getLongitude ();
|
|
|
|
double getAltitude ();
|
2011-07-31 19:27:44 +02:00
|
|
|
double getSpeed () { return speed; };
|
|
|
|
|
|
|
|
double getCrossat () { return crossat; };
|
|
|
|
bool getGear_down () { return gear_down; };
|
|
|
|
bool getFlaps_down () { return flaps_down; };
|
|
|
|
bool getOn_ground () { return on_ground; };
|
|
|
|
int getRouteIndex () { return routeIndex; };
|
|
|
|
bool isFinished () { return finished; };
|
|
|
|
double getTime_sec () { return time_sec; };
|
|
|
|
double getTrackLength() { return trackLength; };
|
2012-11-24 11:59:13 +01:00
|
|
|
const std::string& getTime () { return time; };
|
2011-07-31 19:27:44 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class FGAIFlightPlan {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2009-03-08 17:14:05 +00:00
|
|
|
FGAIFlightPlan();
|
2010-10-20 17:54:16 +01:00
|
|
|
FGAIFlightPlan(const std::string& filename);
|
2009-01-30 18:48:44 +00:00
|
|
|
FGAIFlightPlan(FGAIAircraft *,
|
|
|
|
const std::string& p,
|
2004-07-22 18:50:29 +00:00
|
|
|
double course,
|
2004-11-29 09:41:43 +00:00
|
|
|
time_t start,
|
2004-07-22 18:50:29 +00:00
|
|
|
FGAirport *dep,
|
2005-02-10 09:01:51 +00:00
|
|
|
FGAirport *arr,
|
|
|
|
bool firstLeg,
|
|
|
|
double radius,
|
2006-02-11 13:16:56 +00:00
|
|
|
double alt,
|
|
|
|
double lat,
|
|
|
|
double lon,
|
|
|
|
double speed,
|
2010-10-20 17:54:16 +01:00
|
|
|
const std::string& fltType,
|
|
|
|
const std::string& acType,
|
|
|
|
const std::string& airline);
|
2004-05-15 09:07:55 +00:00
|
|
|
~FGAIFlightPlan();
|
|
|
|
|
2011-07-31 19:27:44 +02:00
|
|
|
FGAIWaypoint* const getPreviousWaypoint( void ) const;
|
|
|
|
FGAIWaypoint* const getCurrentWaypoint( void ) const;
|
|
|
|
FGAIWaypoint* const getNextWaypoint( void ) const;
|
2005-02-10 09:01:51 +00:00
|
|
|
void IncrementWaypoint( bool erase );
|
2009-08-25 11:54:49 +02:00
|
|
|
void DecrementWaypoint( bool erase );
|
2004-05-15 09:07:55 +00:00
|
|
|
|
2011-07-31 19:27:44 +02:00
|
|
|
double getDistanceToGo(double lat, double lon, FGAIWaypoint* wp) const;
|
2005-10-26 09:03:49 +00:00
|
|
|
int getLeg () const { return leg;};
|
2011-08-07 21:38:50 +02:00
|
|
|
|
2011-07-31 19:27:44 +02:00
|
|
|
void setLeadDistance(double speed, double bearing, FGAIWaypoint* current, FGAIWaypoint* next);
|
2004-05-15 09:07:55 +00:00
|
|
|
void setLeadDistance(double distance_ft);
|
|
|
|
double getLeadDistance( void ) const {return lead_distance;}
|
2011-07-31 19:27:44 +02:00
|
|
|
double getBearing(FGAIWaypoint* previous, FGAIWaypoint* next) const;
|
2012-10-30 15:43:54 +00:00
|
|
|
double getBearing(const SGGeod& aPos, FGAIWaypoint* next) const;
|
|
|
|
|
2012-11-25 16:41:10 +01:00
|
|
|
double checkTrackLength(const std::string& wptName) const;
|
2007-07-08 08:46:29 +00:00
|
|
|
time_t getStartTime() const { return start_time; }
|
2010-08-29 19:25:34 +02:00
|
|
|
time_t getArrivalTime() const { return arrivalTime; }
|
2004-05-15 09:07:55 +00:00
|
|
|
|
2011-04-19 18:01:24 +02:00
|
|
|
bool create(FGAIAircraft *, FGAirport *dep, FGAirport *arr, int leg, double alt, double speed, double lat, double lon,
|
2010-10-20 17:54:16 +01:00
|
|
|
bool firstLeg, double radius, const std::string& fltType, const std::string& aircraftType, const std::string& airline, double distance);
|
2012-09-23 21:42:40 +01:00
|
|
|
bool createPushBack(FGAIAircraft *, bool, FGAirport*, double radius, const std::string&, const std::string&, const std::string&);
|
2011-04-19 18:01:24 +02:00
|
|
|
bool createTakeOff(FGAIAircraft *, bool, FGAirport *, double, const std::string&);
|
2004-07-22 18:50:29 +00:00
|
|
|
|
2007-07-08 08:46:29 +00:00
|
|
|
void setLeg(int val) { leg = val;}
|
|
|
|
void setTime(time_t st) { start_time = st; }
|
2012-10-01 17:18:36 +01:00
|
|
|
|
2011-04-10 12:46:00 +02:00
|
|
|
|
2007-07-08 08:46:29 +00:00
|
|
|
double getLeadInAngle() const { return leadInAngle; }
|
2010-10-20 17:54:16 +01:00
|
|
|
const std::string& getRunway() const;
|
James Turner:
Convert FGRunway to be heap-based, and inherit FGPositioned. This is a large, ugly change, since FGRunway was essentially a plain struct, with no accessors or abstraction. This change adds various helpers and accessors to FGRunway, but doesn't change many places to use them - that will be a follow up series of patches. It's still a large patch, but outside of FGAirport and FGRunway, mostly mechanical search-and-replace.
An interesting part of this change is that reciprocal runways now exist as independent objects, rather than being created on the fly by the search methods. This simplifies some pieces of code that search for and iterate runways. For users who only want one 'end' of a runway, the new 'isReciprocal' predicate allows them to ignore the 'other' end. Current the only user of this is the 'ground-radar' ATC feature. If we had data on which runways are truly 'single-ended', it would now be trivial to use this in the airport loader to *not* create the reciprocal.
2008-09-11 08:38:09 +00:00
|
|
|
|
2007-07-08 08:46:29 +00:00
|
|
|
void setRepeat(bool r) { repeat = r; }
|
|
|
|
bool getRepeat(void) const { return repeat; }
|
2005-06-04 09:38:52 +00:00
|
|
|
void restart(void);
|
2007-07-08 08:46:29 +00:00
|
|
|
int getNrOfWayPoints() { return waypoints.size(); }
|
2012-10-01 17:18:36 +01:00
|
|
|
|
|
|
|
int getRouteIndex(int i); // returns the AI related index of this current routes.
|
|
|
|
|
2012-11-24 11:59:13 +01:00
|
|
|
const std::string& getRunway() { return activeRunway; }
|
2007-07-08 08:46:29 +00:00
|
|
|
bool isActive(time_t time) {return time >= this->getStartTime();}
|
2005-06-04 09:38:52 +00:00
|
|
|
|
2011-07-31 19:27:44 +02:00
|
|
|
void incrementLeg() { leg++;};
|
|
|
|
|
2012-11-24 11:59:13 +01:00
|
|
|
void setRunway(const std::string& rwy) { activeRunway = rwy; };
|
|
|
|
const char* getRunwayClassFromTrafficType(const std::string& fltType);
|
2009-02-15 15:29:56 +00:00
|
|
|
|
2011-07-31 19:27:44 +02:00
|
|
|
void addWaypoint(FGAIWaypoint* wpt) { waypoints.push_back(wpt); };
|
2009-03-08 17:14:05 +00:00
|
|
|
|
2012-11-24 11:59:13 +01:00
|
|
|
void setName(const std::string& n) { name = n; };
|
|
|
|
const std::string& getName() { return name; };
|
2009-03-08 17:14:05 +00:00
|
|
|
|
|
|
|
void setSID(FGAIFlightPlan* fp) { sid = fp;};
|
|
|
|
FGAIFlightPlan* getSID() { return sid; };
|
2011-07-31 19:27:44 +02:00
|
|
|
FGAIWaypoint *getWayPoint(int i) { return waypoints[i]; };
|
|
|
|
FGAIWaypoint *getLastWaypoint() { return waypoints.back(); };
|
2011-10-09 23:44:42 +02:00
|
|
|
|
|
|
|
void shortenToFirst(unsigned int number, std::string name);
|
2009-03-08 17:14:05 +00:00
|
|
|
|
2012-11-25 16:41:10 +01:00
|
|
|
void setGate(const ParkingAssignment& pka);
|
2012-10-01 17:18:36 +01:00
|
|
|
FGParking* getParkingGate();
|
2012-11-24 11:59:13 +01:00
|
|
|
|
2013-09-14 12:17:33 +01:00
|
|
|
FGAirportRef departureAirport() const;
|
|
|
|
FGAirportRef arrivalAirport() const;
|
2004-05-15 09:07:55 +00:00
|
|
|
private:
|
2009-03-08 17:14:05 +00:00
|
|
|
FGAIFlightPlan *sid;
|
2011-07-31 19:27:44 +02:00
|
|
|
typedef std::vector <FGAIWaypoint*> wpt_vector_type;
|
2005-10-26 09:03:49 +00:00
|
|
|
typedef wpt_vector_type::const_iterator wpt_vector_iterator;
|
2004-05-15 09:07:55 +00:00
|
|
|
|
2010-08-29 19:25:34 +02:00
|
|
|
|
2005-06-04 09:38:52 +00:00
|
|
|
wpt_vector_type waypoints;
|
|
|
|
wpt_vector_iterator wpt_iterator;
|
2004-05-15 09:07:55 +00:00
|
|
|
|
2005-06-04 09:38:52 +00:00
|
|
|
bool repeat;
|
|
|
|
double distance_to_go;
|
|
|
|
double lead_distance;
|
2005-02-10 09:01:51 +00:00
|
|
|
double leadInAngle;
|
2007-07-08 08:46:29 +00:00
|
|
|
time_t start_time;
|
2010-08-29 19:25:34 +02:00
|
|
|
time_t arrivalTime; // For AI/ATC purposes.
|
2005-02-10 09:01:51 +00:00
|
|
|
int leg;
|
2012-10-01 17:18:36 +01:00
|
|
|
ParkingAssignment gate;
|
|
|
|
PositionedID lastNodeVisited;
|
2010-10-20 17:54:16 +01:00
|
|
|
std::string activeRunway;
|
|
|
|
std::string name;
|
2011-04-19 18:01:24 +02:00
|
|
|
bool isValid;
|
2012-10-30 15:43:54 +00:00
|
|
|
FGAirportRef departure, arrival;
|
|
|
|
|
2012-09-23 21:42:40 +01:00
|
|
|
void createPushBackFallBack(FGAIAircraft *, bool, FGAirport*, double radius, const std::string&, const std::string&, const std::string&);
|
2012-10-30 15:43:54 +00:00
|
|
|
bool createClimb(FGAIAircraft *, bool, FGAirport *, FGAirport* arrival, double, double, const std::string&);
|
2011-04-19 18:01:24 +02:00
|
|
|
bool createCruise(FGAIAircraft *, bool, FGAirport*, FGAirport*, double, double, double, double, const std::string&);
|
|
|
|
bool createDescent(FGAIAircraft *, FGAirport *, double latitude, double longitude, double speed, double alt,const std::string&, double distance);
|
|
|
|
bool createLanding(FGAIAircraft *, FGAirport *, const std::string&);
|
|
|
|
bool createParking(FGAIAircraft *, FGAirport *, double radius);
|
2005-02-10 09:01:51 +00:00
|
|
|
void deleteWaypoints();
|
|
|
|
void resetWaypoints();
|
2011-10-09 23:44:42 +02:00
|
|
|
void eraseLastWaypoint();
|
2011-10-22 10:15:16 +02:00
|
|
|
void pushBackWaypoint(FGAIWaypoint *wpt);
|
2006-07-27 14:42:15 +00:00
|
|
|
|
2011-04-19 18:01:24 +02:00
|
|
|
bool createLandingTaxi(FGAIAircraft *, FGAirport *apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
|
2009-02-15 15:29:56 +00:00
|
|
|
void createDefaultLandingTaxi(FGAIAircraft *, FGAirport* aAirport);
|
|
|
|
void createDefaultTakeoffTaxi(FGAIAircraft *, FGAirport* aAirport, FGRunway* aRunway);
|
2011-04-19 18:01:24 +02:00
|
|
|
bool createTakeoffTaxi(FGAIAircraft *, bool firstFlight, FGAirport *apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
|
2010-08-29 19:25:34 +02:00
|
|
|
|
|
|
|
double getTurnRadius(double, bool);
|
2008-12-30 07:41:15 +00:00
|
|
|
|
2011-07-31 19:27:44 +02:00
|
|
|
FGAIWaypoint* createOnGround(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
|
|
|
|
FGAIWaypoint* createInAir(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
|
|
|
|
FGAIWaypoint* cloneWithPos(FGAIAircraft *, FGAIWaypoint* aWpt, const std::string& aName, const SGGeod& aPos);
|
|
|
|
FGAIWaypoint* clone(FGAIWaypoint* aWpt);
|
2008-12-30 07:41:15 +00:00
|
|
|
|
2007-06-28 18:30:35 +00:00
|
|
|
|
2006-07-27 14:42:15 +00:00
|
|
|
//void createCruiseFallback(bool, FGAirport*, FGAirport*, double, double, double, double);
|
|
|
|
void evaluateRoutePart(double deplat, double deplon, double arrlat, double arrlon);
|
2012-10-30 15:43:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* look for and parse an PropertyList flight-plan file - essentially
|
|
|
|
* a flat list waypoint objects, encoded to properties
|
|
|
|
*/
|
|
|
|
bool parseProperties(const std::string& filename);
|
|
|
|
|
|
|
|
void 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 std::string& fltType,
|
|
|
|
const std::string& acType,
|
|
|
|
const std::string& airline);
|
|
|
|
|
2009-03-08 17:14:05 +00:00
|
|
|
public:
|
|
|
|
wpt_vector_iterator getFirstWayPoint() { return waypoints.begin(); };
|
|
|
|
wpt_vector_iterator getLastWayPoint() { return waypoints.end(); };
|
2011-04-19 18:01:24 +02:00
|
|
|
bool isValidPlan() { return isValid; };
|
2011-07-31 19:27:44 +02:00
|
|
|
};
|
2004-05-15 09:07:55 +00:00
|
|
|
|
|
|
|
#endif // _FG_AIFLIGHTPLAN_HXX
|