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 (const 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 (const std::string& tme) { time = tme; };
73 bool contains(const std::string& name);
75 const 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 const 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(const 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 const std::string& getRunway() { return activeRunway; }
157 bool isActive(time_t time) {return time >= this->getStartTime();}
159 void incrementLeg() { leg++;};
161 void setRunway(const std::string& rwy) { activeRunway = rwy; };
162 const char* getRunwayClassFromTrafficType(const std::string& fltType);
164 void addWaypoint(FGAIWaypoint* wpt) { waypoints.push_back(wpt); };
166 void setName(const std::string& n) { name = n; };
167 const 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();
181 typedef std::vector <FGAIWaypoint*> wpt_vector_type;
182 typedef wpt_vector_type::const_iterator wpt_vector_iterator;
185 wpt_vector_type waypoints;
186 wpt_vector_iterator wpt_iterator;
189 double distance_to_go;
190 double lead_distance;
193 time_t arrivalTime; // For AI/ATC purposes.
195 ParkingAssignment gate;
196 PositionedID lastNodeVisited;
197 std::string activeRunway;
200 FGAirportRef departure, arrival;
202 void createPushBackFallBack(FGAIAircraft *, bool, FGAirport*, double radius, const std::string&, const std::string&, const std::string&);
203 bool createClimb(FGAIAircraft *, bool, FGAirport *, FGAirport* arrival, double, double, const std::string&);
204 bool createCruise(FGAIAircraft *, bool, FGAirport*, FGAirport*, double, double, double, double, const std::string&);
205 bool createDescent(FGAIAircraft *, FGAirport *, double latitude, double longitude, double speed, double alt,const std::string&, double distance);
206 bool createLanding(FGAIAircraft *, FGAirport *, const std::string&);
207 bool createParking(FGAIAircraft *, FGAirport *, double radius);
208 void deleteWaypoints();
209 void resetWaypoints();
210 void eraseLastWaypoint();
211 void pushBackWaypoint(FGAIWaypoint *wpt);
213 bool createLandingTaxi(FGAIAircraft *, FGAirport *apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
214 void createDefaultLandingTaxi(FGAIAircraft *, FGAirport* aAirport);
215 void createDefaultTakeoffTaxi(FGAIAircraft *, FGAirport* aAirport, FGRunway* aRunway);
216 bool createTakeoffTaxi(FGAIAircraft *, bool firstFlight, FGAirport *apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
218 double getTurnRadius(double, bool);
220 FGAIWaypoint* createOnGround(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
221 FGAIWaypoint* createInAir(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
222 FGAIWaypoint* cloneWithPos(FGAIAircraft *, FGAIWaypoint* aWpt, const std::string& aName, const SGGeod& aPos);
223 FGAIWaypoint* clone(FGAIWaypoint* aWpt);
226 //void createCruiseFallback(bool, FGAirport*, FGAirport*, double, double, double, double);
227 void evaluateRoutePart(double deplat, double deplon, double arrlat, double arrlon);
230 * look for and parse an PropertyList flight-plan file - essentially
231 * a flat list waypoint objects, encoded to properties
233 bool parseProperties(const std::string& filename);
235 void createWaypoints(FGAIAircraft *ac,
246 const std::string& fltType,
247 const std::string& acType,
248 const std::string& airline);
251 wpt_vector_iterator getFirstWayPoint() { return waypoints.begin(); };
252 wpt_vector_iterator getLastWayPoint() { return waypoints.end(); };
253 bool isValidPlan() { return isValid; };
256 #endif // _FG_AIFLIGHTPLAN_HXX