1 // FGAIFlightPlan - class for loading and storing AI flight plans
2 // Written by David Culp, started May 2004
3 // - davidculp2@comcast.net
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 #ifndef _FG_AIFLIGHTPLAN_HXX
20 #define _FG_AIFLIGHTPLAN_HXX
25 #include <simgear/compiler.h>
26 #include <simgear/math/SGMath.hxx>
27 #include <simgear/structure/SGSharedPtr.hxx>
28 #include <Navaids/positioned.hxx>
29 #include <Airports/dynamics.hxx>
41 int routeIndex; // For AI/ATC purposes;
43 double trackLength; // distance from previous FGAIWaypoint (for AI purposes);
49 void setName (const std::string& nam) { name = nam; };
50 void setLatitude (double lat);
51 void setLongitude (double lon);
52 void setAltitude (double alt);
53 void setPos (const SGGeod& aPos) { pos = aPos; }
54 void setSpeed (double spd) { speed = spd; };
55 void setCrossat (double val) { crossat = val; };
56 void setFinished (bool fin) { finished = fin; };
57 void setGear_down (bool grd) { gear_down = grd; };
58 void setFlaps_down (bool fld) { flaps_down = fld; };
59 void setOn_ground (bool grn) { on_ground = grn; };
60 void setRouteIndex (int rte) { routeIndex = rte; };
61 void setTime_sec (double ts ) { time_sec = ts; };
62 void setTrackLength (double tl ) { trackLength = tl; };
63 void setTime (const std::string& tme) { time = tme; };
65 bool contains(const std::string& name);
67 const std::string& getName() { return name; };
68 const SGGeod& getPos () { return pos; };
69 double getLatitude ();
70 double getLongitude ();
71 double getAltitude ();
72 double getSpeed () { return speed; };
74 double getCrossat () { return crossat; };
75 bool getGear_down () { return gear_down; };
76 bool getFlaps_down () { return flaps_down; };
77 bool getOn_ground () { return on_ground; };
78 int getRouteIndex () { return routeIndex; };
79 bool isFinished () { return finished; };
80 double getTime_sec () { return time_sec; };
81 double getTrackLength() { return trackLength; };
82 const std::string& getTime () { return time; };
87 class FGAIFlightPlan {
92 FGAIFlightPlan(const std::string& filename);
93 FGAIFlightPlan(FGAIAircraft *,
105 const std::string& fltType,
106 const std::string& acType,
107 const std::string& airline);
110 FGAIWaypoint* const getPreviousWaypoint( void ) const;
111 FGAIWaypoint* const getCurrentWaypoint( void ) const;
112 FGAIWaypoint* const getNextWaypoint( void ) const;
113 void IncrementWaypoint( bool erase );
114 void DecrementWaypoint( bool erase );
116 double getDistanceToGo(double lat, double lon, FGAIWaypoint* wp) const;
117 int getLeg () const { return leg;};
119 void setLeadDistance(double speed, double bearing, FGAIWaypoint* current, FGAIWaypoint* next);
120 void setLeadDistance(double distance_ft);
121 double getLeadDistance( void ) const {return lead_distance;}
122 double getBearing(FGAIWaypoint* previous, FGAIWaypoint* next) const;
123 double getBearing(const SGGeod& aPos, FGAIWaypoint* next) const;
125 double checkTrackLength(const std::string& wptName) const;
126 time_t getStartTime() const { return start_time; }
127 time_t getArrivalTime() const { return arrivalTime; }
129 bool create(FGAIAircraft *, FGAirport *dep, FGAirport *arr, int leg, double alt, double speed, double lat, double lon,
130 bool firstLeg, double radius, const std::string& fltType, const std::string& aircraftType, const std::string& airline, double distance);
131 bool createPushBack(FGAIAircraft *, bool, FGAirport*, double radius, const std::string&, const std::string&, const std::string&);
132 bool createTakeOff(FGAIAircraft *, bool, FGAirport *, double, const std::string&);
134 void setLeg(int val) { leg = val;}
135 void setTime(time_t st) { start_time = st; }
138 double getLeadInAngle() const { return leadInAngle; }
139 const std::string& getRunway() const;
141 void setRepeat(bool r) { repeat = r; }
142 bool getRepeat(void) const { return repeat; }
144 int getNrOfWayPoints() { return waypoints.size(); }
146 int getRouteIndex(int i); // returns the AI related index of this current routes.
148 const std::string& getRunway() { return activeRunway; }
149 bool isActive(time_t time) {return time >= this->getStartTime();}
151 void incrementLeg() { leg++;};
153 void setRunway(const std::string& rwy) { activeRunway = rwy; };
154 const char* getRunwayClassFromTrafficType(const std::string& fltType);
156 void addWaypoint(FGAIWaypoint* wpt) { waypoints.push_back(wpt); };
158 void setName(const std::string& n) { name = n; };
159 const std::string& getName() { return name; };
161 void setSID(FGAIFlightPlan* fp) { sid = fp;};
162 FGAIFlightPlan* getSID() { return sid; };
163 FGAIWaypoint *getWayPoint(int i) { return waypoints[i]; };
164 FGAIWaypoint *getLastWaypoint() { return waypoints.back(); };
166 void shortenToFirst(unsigned int number, std::string name);
168 void setGate(const ParkingAssignment& pka);
169 FGParking* getParkingGate();
171 FGAirportRef departureAirport() const;
172 FGAirportRef arrivalAirport() const;
175 typedef std::vector <FGAIWaypoint*> wpt_vector_type;
176 typedef wpt_vector_type::const_iterator wpt_vector_iterator;
179 wpt_vector_type waypoints;
180 wpt_vector_iterator wpt_iterator;
183 double distance_to_go;
184 double lead_distance;
187 time_t arrivalTime; // For AI/ATC purposes.
189 ParkingAssignment gate;
190 FGTaxiNodeRef lastNodeVisited;
191 std::string activeRunway;
194 FGAirportRef departure, arrival;
196 void createPushBackFallBack(FGAIAircraft *, bool, FGAirport*, double radius, const std::string&, const std::string&, const std::string&);
197 bool createClimb(FGAIAircraft *, bool, FGAirport *, FGAirport* arrival, double, double, const std::string&);
198 bool createCruise(FGAIAircraft *, bool, FGAirport*, FGAirport*, double, double, double, double, const std::string&);
199 bool createDescent(FGAIAircraft *, FGAirport *, double latitude, double longitude, double speed, double alt,const std::string&, double distance);
200 bool createLanding(FGAIAircraft *, FGAirport *, const std::string&);
201 bool createParking(FGAIAircraft *, FGAirport *, double radius);
202 void deleteWaypoints();
203 void resetWaypoints();
204 void eraseLastWaypoint();
205 void pushBackWaypoint(FGAIWaypoint *wpt);
207 bool createLandingTaxi(FGAIAircraft *, FGAirport *apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
208 void createDefaultLandingTaxi(FGAIAircraft *, FGAirport* aAirport);
209 void createDefaultTakeoffTaxi(FGAIAircraft *, FGAirport* aAirport, FGRunway* aRunway);
210 bool createTakeoffTaxi(FGAIAircraft *, bool firstFlight, FGAirport *apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
212 double getTurnRadius(double, bool);
214 FGAIWaypoint* createOnGround(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
215 FGAIWaypoint* createInAir(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
216 FGAIWaypoint* cloneWithPos(FGAIAircraft *, FGAIWaypoint* aWpt, const std::string& aName, const SGGeod& aPos);
217 FGAIWaypoint* clone(FGAIWaypoint* aWpt);
220 //void createCruiseFallback(bool, FGAirport*, FGAirport*, double, double, double, double);
221 void evaluateRoutePart(double deplat, double deplon, double arrlat, double arrlon);
224 * look for and parse an PropertyList flight-plan file - essentially
225 * a flat list waypoint objects, encoded to properties
227 bool parseProperties(const std::string& filename);
229 void createWaypoints(FGAIAircraft *ac,
240 const std::string& fltType,
241 const std::string& acType,
242 const std::string& airline);
245 wpt_vector_iterator getFirstWayPoint() { return waypoints.begin(); };
246 wpt_vector_iterator getLastWayPoint() { return waypoints.end(); };
247 bool isValidPlan() { return isValid; };
250 #endif // _FG_AIFLIGHTPLAN_HXX