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>
35 typedef SGSharedPtr<FGAirport> FGAirportRef;
47 int routeIndex; // For AI/ATC purposes;
49 double trackLength; // distance from previous FGAIWaypoint (for AI purposes);
55 void setName (std::string nam) { name = nam; };
56 void setLatitude (double lat);
57 void setLongitude (double lon);
58 void setAltitude (double alt);
59 void setPos (const SGGeod& aPos) { pos = aPos; }
60 void setSpeed (double spd) { speed = spd; };
61 void setCrossat (double val) { crossat = val; };
62 void setFinished (bool fin) { finished = fin; };
63 void setGear_down (bool grd) { gear_down = grd; };
64 void setFlaps_down (bool fld) { flaps_down = fld; };
65 void setOn_ground (bool grn) { on_ground = grn; };
66 void setRouteIndex (int rte) { routeIndex = rte; };
67 void setTime_sec (double ts ) { time_sec = ts; };
68 void setTrackLength (double tl ) { trackLength = tl; };
69 void setTime (std::string tme) { time = tme; };
71 bool contains(std::string name);
73 std::string getName () { return name; };
74 const SGGeod& getPos () { return pos; };
75 double getLatitude ();
76 double getLongitude ();
77 double getAltitude ();
78 double getSpeed () { return speed; };
80 double getCrossat () { return crossat; };
81 bool getGear_down () { return gear_down; };
82 bool getFlaps_down () { return flaps_down; };
83 bool getOn_ground () { return on_ground; };
84 int getRouteIndex () { return routeIndex; };
85 bool isFinished () { return finished; };
86 double getTime_sec () { return time_sec; };
87 double getTrackLength() { return trackLength; };
88 std::string getTime () { return time; };
93 class FGAIFlightPlan {
98 FGAIFlightPlan(const std::string& filename);
99 FGAIFlightPlan(FGAIAircraft *,
100 const std::string& p,
111 const std::string& fltType,
112 const std::string& acType,
113 const std::string& airline);
116 FGAIWaypoint* const getPreviousWaypoint( void ) const;
117 FGAIWaypoint* const getCurrentWaypoint( void ) const;
118 FGAIWaypoint* const getNextWaypoint( void ) const;
119 void IncrementWaypoint( bool erase );
120 void DecrementWaypoint( bool erase );
122 double getDistanceToGo(double lat, double lon, FGAIWaypoint* wp) const;
123 int getLeg () const { return leg;};
125 void setLeadDistance(double speed, double bearing, FGAIWaypoint* current, FGAIWaypoint* next);
126 void setLeadDistance(double distance_ft);
127 double getLeadDistance( void ) const {return lead_distance;}
128 double getBearing(FGAIWaypoint* previous, FGAIWaypoint* next) const;
129 double getBearing(const SGGeod& aPos, FGAIWaypoint* next) const;
131 double checkTrackLength(std::string wptName);
132 time_t getStartTime() const { return start_time; }
133 time_t getArrivalTime() const { return arrivalTime; }
135 bool create(FGAIAircraft *, FGAirport *dep, FGAirport *arr, int leg, double alt, double speed, double lat, double lon,
136 bool firstLeg, double radius, const std::string& fltType, const std::string& aircraftType, const std::string& airline, double distance);
137 bool createPushBack(FGAIAircraft *, bool, FGAirport*, double radius, const std::string&, const std::string&, const std::string&);
138 bool createTakeOff(FGAIAircraft *, bool, FGAirport *, double, const std::string&);
140 void setLeg(int val) { leg = val;}
141 void setTime(time_t st) { start_time = st; }
142 int getGate() const { return gateId; }
143 void setGate(int id) { gateId = id; };
145 double getLeadInAngle() const { return leadInAngle; }
146 const std::string& getRunway() const;
148 void setRepeat(bool r) { repeat = r; }
149 bool getRepeat(void) const { return repeat; }
151 int getNrOfWayPoints() { return waypoints.size(); }
152 int getRouteIndex(int i); // returns the AI related index of this current routes.
153 FGTaxiRoute *getTaxiRoute() { return taxiRoute; }
154 void deleteTaxiRoute();
155 std::string getRunway() { return activeRunway; }
156 bool isActive(time_t time) {return time >= this->getStartTime();}
158 void incrementLeg() { leg++;};
160 void setRunway(std::string rwy) { activeRunway = rwy; };
161 std::string getRunwayClassFromTrafficType(std::string fltType);
163 void addWaypoint(FGAIWaypoint* wpt) { waypoints.push_back(wpt); };
165 void setName(std::string n) { name = n; };
166 std::string getName() { return name; };
168 void setSID(FGAIFlightPlan* fp) { sid = fp;};
169 FGAIFlightPlan* getSID() { return sid; };
170 FGAIWaypoint *getWayPoint(int i) { return waypoints[i]; };
171 FGAIWaypoint *getLastWaypoint() { return waypoints.back(); };
173 void shortenToFirst(unsigned int number, std::string name);
177 typedef std::vector <FGAIWaypoint*> wpt_vector_type;
178 typedef wpt_vector_type::const_iterator wpt_vector_iterator;
181 wpt_vector_type waypoints;
182 wpt_vector_iterator wpt_iterator;
185 double distance_to_go;
186 double lead_distance;
189 time_t arrivalTime; // For AI/ATC purposes.
191 int gateId, lastNodeVisited;
192 std::string activeRunway;
193 FGTaxiRoute *taxiRoute;
196 FGAirportRef departure, arrival;
198 void createPushBackFallBack(FGAIAircraft *, bool, FGAirport*, double radius, const std::string&, const std::string&, const std::string&);
199 bool createClimb(FGAIAircraft *, bool, FGAirport *, FGAirport* arrival, double, double, const std::string&);
200 bool createCruise(FGAIAircraft *, bool, FGAirport*, FGAirport*, double, double, double, double, const std::string&);
201 bool createDescent(FGAIAircraft *, FGAirport *, double latitude, double longitude, double speed, double alt,const std::string&, double distance);
202 bool createLanding(FGAIAircraft *, FGAirport *, const std::string&);
203 bool createParking(FGAIAircraft *, FGAirport *, double radius);
204 void deleteWaypoints();
205 void resetWaypoints();
206 void eraseLastWaypoint();
207 void pushBackWaypoint(FGAIWaypoint *wpt);
209 bool createLandingTaxi(FGAIAircraft *, FGAirport *apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
210 void createDefaultLandingTaxi(FGAIAircraft *, FGAirport* aAirport);
211 void createDefaultTakeoffTaxi(FGAIAircraft *, FGAirport* aAirport, FGRunway* aRunway);
212 bool createTakeoffTaxi(FGAIAircraft *, bool firstFlight, FGAirport *apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
214 double getTurnRadius(double, bool);
216 FGAIWaypoint* createOnGround(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
217 FGAIWaypoint* createInAir(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
218 FGAIWaypoint* cloneWithPos(FGAIAircraft *, FGAIWaypoint* aWpt, const std::string& aName, const SGGeod& aPos);
219 FGAIWaypoint* clone(FGAIWaypoint* aWpt);
222 //void createCruiseFallback(bool, FGAirport*, FGAirport*, double, double, double, double);
223 void evaluateRoutePart(double deplat, double deplon, double arrlat, double arrlon);
226 * look for and parse an PropertyList flight-plan file - essentially
227 * a flat list waypoint objects, encoded to properties
229 bool parseProperties(const std::string& filename);
231 void createWaypoints(FGAIAircraft *ac,
242 const std::string& fltType,
243 const std::string& acType,
244 const std::string& airline);
247 wpt_vector_iterator getFirstWayPoint() { return waypoints.begin(); };
248 wpt_vector_iterator getLastWayPoint() { return waypoints.end(); };
249 bool isValidPlan() { return isValid; };
252 #endif // _FG_AIFLIGHTPLAN_HXX