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
22 #include <simgear/compiler.h>
25 #include <simgear/math/SGMath.hxx>
42 int routeIndex; // For AI/ATC purposes;
44 double trackLength; // distance from previous FGAIWaypoint (for AI purposes);
50 void setName (std::string nam) { name = nam; };
51 void setLatitude (double lat);
52 void setLongitude (double lon);
53 void setAltitude (double alt);
54 void setPos (const SGGeod& aPos) { pos = aPos; }
55 void setSpeed (double spd) { speed = spd; };
56 void setCrossat (double val) { crossat = val; };
57 void setFinished (bool fin) { finished = fin; };
58 void setGear_down (bool grd) { gear_down = grd; };
59 void setFlaps_down (bool fld) { flaps_down = fld; };
60 void setOn_ground (bool grn) { on_ground = grn; };
61 void setRouteIndex (int rte) { routeIndex = rte; };
62 void setTime_sec (double ts ) { time_sec = ts; };
63 void setTrackLength (double tl ) { trackLength = tl; };
64 void setTime (std::string tme) { time = tme; };
66 bool contains(std::string name);
68 std::string getName () { return name; };
69 const SGGeod& getPos () { return pos; };
70 double getLatitude ();
71 double getLongitude ();
72 double getAltitude ();
73 double getSpeed () { return speed; };
75 double getCrossat () { return crossat; };
76 bool getGear_down () { return gear_down; };
77 bool getFlaps_down () { return flaps_down; };
78 bool getOn_ground () { return on_ground; };
79 int getRouteIndex () { return routeIndex; };
80 bool isFinished () { return finished; };
81 double getTime_sec () { return time_sec; };
82 double getTrackLength() { return trackLength; };
83 std::string getTime () { return time; };
88 class FGAIFlightPlan {
93 FGAIFlightPlan(const std::string& filename);
94 FGAIFlightPlan(FGAIAircraft *,
106 const std::string& fltType,
107 const std::string& acType,
108 const std::string& airline);
111 FGAIWaypoint* const getPreviousWaypoint( void ) const;
112 FGAIWaypoint* const getCurrentWaypoint( void ) const;
113 FGAIWaypoint* const getNextWaypoint( void ) const;
114 void IncrementWaypoint( bool erase );
115 void DecrementWaypoint( bool erase );
117 double getDistanceToGo(double lat, double lon, FGAIWaypoint* wp) const;
118 int getLeg () const { return leg;};
120 void setLeadDistance(double speed, double bearing, FGAIWaypoint* current, FGAIWaypoint* next);
121 void setLeadDistance(double distance_ft);
122 double getLeadDistance( void ) const {return lead_distance;}
123 double getBearing(FGAIWaypoint* previous, FGAIWaypoint* next) const;
124 double getBearing(double lat, double lon, FGAIWaypoint* next) const;
125 double checkTrackLength(std::string wptName);
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; }
136 int getGate() const { return gateId; }
137 void setGate(int id) { gateId = id; };
139 double getLeadInAngle() const { return leadInAngle; }
140 const std::string& getRunway() const;
142 void setRepeat(bool r) { repeat = r; }
143 bool getRepeat(void) const { return repeat; }
145 int getNrOfWayPoints() { return waypoints.size(); }
146 int getRouteIndex(int i); // returns the AI related index of this current routes.
147 FGTaxiRoute *getTaxiRoute() { return taxiRoute; }
148 void deleteTaxiRoute();
149 std::string getRunway() { return activeRunway; }
150 bool isActive(time_t time) {return time >= this->getStartTime();}
152 void incrementLeg() { leg++;};
154 void setRunway(std::string rwy) { activeRunway = rwy; };
155 std::string getRunwayClassFromTrafficType(std::string fltType);
157 void addWaypoint(FGAIWaypoint* wpt) { waypoints.push_back(wpt); };
159 void setName(std::string n) { name = n; };
160 std::string getName() { return name; };
162 void setSID(FGAIFlightPlan* fp) { sid = fp;};
163 FGAIFlightPlan* getSID() { return sid; };
164 FGAIWaypoint *getWayPoint(int i) { return waypoints[i]; };
165 FGAIWaypoint *getLastWaypoint() { return waypoints.back(); };
167 void shortenToFirst(unsigned int number, std::string name);
171 typedef std::vector <FGAIWaypoint*> wpt_vector_type;
172 typedef wpt_vector_type::const_iterator wpt_vector_iterator;
175 wpt_vector_type waypoints;
176 wpt_vector_iterator wpt_iterator;
179 double distance_to_go;
180 double lead_distance;
183 time_t arrivalTime; // For AI/ATC purposes.
185 int gateId, lastNodeVisited;
186 std::string activeRunway;
187 FGTaxiRoute *taxiRoute;
191 void createPushBackFallBack(FGAIAircraft *, bool, FGAirport*, double radius, const std::string&, const std::string&, const std::string&);
192 bool createClimb(FGAIAircraft *, bool, FGAirport *, double, double, const std::string&);
193 bool createCruise(FGAIAircraft *, bool, FGAirport*, FGAirport*, double, double, double, double, const std::string&);
194 bool createDescent(FGAIAircraft *, FGAirport *, double latitude, double longitude, double speed, double alt,const std::string&, double distance);
195 bool createLanding(FGAIAircraft *, FGAirport *, const std::string&);
196 bool createParking(FGAIAircraft *, FGAirport *, double radius);
197 void deleteWaypoints();
198 void resetWaypoints();
199 void eraseLastWaypoint();
200 void pushBackWaypoint(FGAIWaypoint *wpt);
202 bool createLandingTaxi(FGAIAircraft *, FGAirport *apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
203 void createDefaultLandingTaxi(FGAIAircraft *, FGAirport* aAirport);
204 void createDefaultTakeoffTaxi(FGAIAircraft *, FGAirport* aAirport, FGRunway* aRunway);
205 bool createTakeoffTaxi(FGAIAircraft *, bool firstFlight, FGAirport *apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
207 double getTurnRadius(double, bool);
209 FGAIWaypoint* createOnGround(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
210 FGAIWaypoint* createInAir(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
211 FGAIWaypoint* cloneWithPos(FGAIAircraft *, FGAIWaypoint* aWpt, const std::string& aName, const SGGeod& aPos);
212 FGAIWaypoint* clone(FGAIWaypoint* aWpt);
215 //void createCruiseFallback(bool, FGAirport*, FGAirport*, double, double, double, double);
216 void evaluateRoutePart(double deplat, double deplon, double arrlat, double arrlon);
218 wpt_vector_iterator getFirstWayPoint() { return waypoints.begin(); };
219 wpt_vector_iterator getLastWayPoint() { return waypoints.end(); };
220 bool isValidPlan() { return isValid; };
223 #endif // _FG_AIFLIGHTPLAN_HXX