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>
37 typedef SGSharedPtr<FGAirport> FGAirportRef;
49 int routeIndex; // For AI/ATC purposes;
51 double trackLength; // distance from previous FGAIWaypoint (for AI purposes);
57 void setName (std::string nam) { name = nam; };
58 void setLatitude (double lat);
59 void setLongitude (double lon);
60 void setAltitude (double alt);
61 void setPos (const SGGeod& aPos) { pos = aPos; }
62 void setSpeed (double spd) { speed = spd; };
63 void setCrossat (double val) { crossat = val; };
64 void setFinished (bool fin) { finished = fin; };
65 void setGear_down (bool grd) { gear_down = grd; };
66 void setFlaps_down (bool fld) { flaps_down = fld; };
67 void setOn_ground (bool grn) { on_ground = grn; };
68 void setRouteIndex (int rte) { routeIndex = rte; };
69 void setTime_sec (double ts ) { time_sec = ts; };
70 void setTrackLength (double tl ) { trackLength = tl; };
71 void setTime (std::string tme) { time = tme; };
73 bool contains(std::string name);
75 std::string getName () { return name; };
76 const SGGeod& getPos () { return pos; };
77 double getLatitude ();
78 double getLongitude ();
79 double getAltitude ();
80 double getSpeed () { return speed; };
82 double getCrossat () { return crossat; };
83 bool getGear_down () { return gear_down; };
84 bool getFlaps_down () { return flaps_down; };
85 bool getOn_ground () { return on_ground; };
86 int getRouteIndex () { return routeIndex; };
87 bool isFinished () { return finished; };
88 double getTime_sec () { return time_sec; };
89 double getTrackLength() { return trackLength; };
90 std::string getTime () { return time; };
95 class FGAIFlightPlan {
100 FGAIFlightPlan(const std::string& filename);
101 FGAIFlightPlan(FGAIAircraft *,
102 const std::string& p,
113 const std::string& fltType,
114 const std::string& acType,
115 const std::string& airline);
118 FGAIWaypoint* const getPreviousWaypoint( void ) const;
119 FGAIWaypoint* const getCurrentWaypoint( void ) const;
120 FGAIWaypoint* const getNextWaypoint( void ) const;
121 void IncrementWaypoint( bool erase );
122 void DecrementWaypoint( bool erase );
124 double getDistanceToGo(double lat, double lon, FGAIWaypoint* wp) const;
125 int getLeg () const { return leg;};
127 void setLeadDistance(double speed, double bearing, FGAIWaypoint* current, FGAIWaypoint* next);
128 void setLeadDistance(double distance_ft);
129 double getLeadDistance( void ) const {return lead_distance;}
130 double getBearing(FGAIWaypoint* previous, FGAIWaypoint* next) const;
131 double getBearing(const SGGeod& aPos, FGAIWaypoint* next) const;
133 double checkTrackLength(std::string wptName);
134 time_t getStartTime() const { return start_time; }
135 time_t getArrivalTime() const { return arrivalTime; }
137 bool create(FGAIAircraft *, FGAirport *dep, FGAirport *arr, int leg, double alt, double speed, double lat, double lon,
138 bool firstLeg, double radius, const std::string& fltType, const std::string& aircraftType, const std::string& airline, double distance);
139 bool createPushBack(FGAIAircraft *, bool, FGAirport*, double radius, const std::string&, const std::string&, const std::string&);
140 bool createTakeOff(FGAIAircraft *, bool, FGAirport *, double, const std::string&);
142 void setLeg(int val) { leg = val;}
143 void setTime(time_t st) { start_time = st; }
146 double getLeadInAngle() const { return leadInAngle; }
147 const std::string& getRunway() const;
149 void setRepeat(bool r) { repeat = r; }
150 bool getRepeat(void) const { return repeat; }
152 int getNrOfWayPoints() { return waypoints.size(); }
154 int getRouteIndex(int i); // returns the AI related index of this current routes.
156 std::string getRunway() { return activeRunway; }
157 bool isActive(time_t time) {return time >= this->getStartTime();}
159 void incrementLeg() { leg++;};
161 void setRunway(std::string rwy) { activeRunway = rwy; };
162 std::string getRunwayClassFromTrafficType(std::string fltType);
164 void addWaypoint(FGAIWaypoint* wpt) { waypoints.push_back(wpt); };
166 void setName(std::string n) { name = n; };
167 std::string getName() { return name; };
169 void setSID(FGAIFlightPlan* fp) { sid = fp;};
170 FGAIFlightPlan* getSID() { return sid; };
171 FGAIWaypoint *getWayPoint(int i) { return waypoints[i]; };
172 FGAIWaypoint *getLastWaypoint() { return waypoints.back(); };
174 void shortenToFirst(unsigned int number, std::string name);
176 void setGate(ParkingAssignment pka);
177 FGParking* getParkingGate();
180 typedef std::vector <FGAIWaypoint*> wpt_vector_type;
181 typedef wpt_vector_type::const_iterator wpt_vector_iterator;
184 wpt_vector_type waypoints;
185 wpt_vector_iterator wpt_iterator;
188 double distance_to_go;
189 double lead_distance;
192 time_t arrivalTime; // For AI/ATC purposes.
194 ParkingAssignment gate;
195 PositionedID lastNodeVisited;
196 std::string activeRunway;
199 FGAirportRef departure, arrival;
201 void createPushBackFallBack(FGAIAircraft *, bool, FGAirport*, double radius, const std::string&, const std::string&, const std::string&);
202 bool createClimb(FGAIAircraft *, bool, FGAirport *, FGAirport* arrival, double, double, const std::string&);
203 bool createCruise(FGAIAircraft *, bool, FGAirport*, FGAirport*, double, double, double, double, const std::string&);
204 bool createDescent(FGAIAircraft *, FGAirport *, double latitude, double longitude, double speed, double alt,const std::string&, double distance);
205 bool createLanding(FGAIAircraft *, FGAirport *, const std::string&);
206 bool createParking(FGAIAircraft *, FGAirport *, double radius);
207 void deleteWaypoints();
208 void resetWaypoints();
209 void eraseLastWaypoint();
210 void pushBackWaypoint(FGAIWaypoint *wpt);
212 bool createLandingTaxi(FGAIAircraft *, FGAirport *apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
213 void createDefaultLandingTaxi(FGAIAircraft *, FGAirport* aAirport);
214 void createDefaultTakeoffTaxi(FGAIAircraft *, FGAirport* aAirport, FGRunway* aRunway);
215 bool createTakeoffTaxi(FGAIAircraft *, bool firstFlight, FGAirport *apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
217 double getTurnRadius(double, bool);
219 FGAIWaypoint* createOnGround(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
220 FGAIWaypoint* createInAir(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
221 FGAIWaypoint* cloneWithPos(FGAIAircraft *, FGAIWaypoint* aWpt, const std::string& aName, const SGGeod& aPos);
222 FGAIWaypoint* clone(FGAIWaypoint* aWpt);
225 //void createCruiseFallback(bool, FGAirport*, FGAirport*, double, double, double, double);
226 void evaluateRoutePart(double deplat, double deplon, double arrlat, double arrlon);
229 * look for and parse an PropertyList flight-plan file - essentially
230 * a flat list waypoint objects, encoded to properties
232 bool parseProperties(const std::string& filename);
234 void createWaypoints(FGAIAircraft *ac,
245 const std::string& fltType,
246 const std::string& acType,
247 const std::string& airline);
250 wpt_vector_iterator getFirstWayPoint() { return waypoints.begin(); };
251 wpt_vector_iterator getLastWayPoint() { return waypoints.end(); };
252 bool isValidPlan() { return isValid; };
255 #endif // _FG_AIFLIGHTPLAN_HXX