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., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #ifndef _FG_AIFLIGHTPLAN_HXX
20 #define _FG_AIFLIGHTPLAN_HXX
22 #include <simgear/compiler.h>
45 int routeIndex; // For AI/ATC purposes;
47 double trackLength; // distance from previous FGAIWaypoint (for AI purposes);
53 void setName (std::string nam) { name = nam; };
54 void setLatitude (double lat) { latitude = lat; };
55 void setLongitude (double lon) { longitude = lon; };
56 void setAltitude (double alt) { altitude = alt; };
57 void setSpeed (double spd) { speed = spd; };
58 void setCrossat (double val) { crossat = val; };
59 void setFinished (bool fin) { finished = fin; };
60 void setGear_down (bool grd) { gear_down = grd; };
61 void setFlaps_down (bool fld) { flaps_down = fld; };
62 void setOn_ground (bool grn) { on_ground = grn; };
63 void setRouteIndex (int rte) { routeIndex = rte; };
64 void setTime_sec (double ts ) { time_sec = ts; };
65 void setTrackLength (double tl ) { trackLength = tl; };
66 void setTime (std::string tme) { time = tme; };
68 bool contains(std::string name);
70 std::string getName () { return name; };
71 double getLatitude () { return latitude; };
72 double getLongitude () { return longitude; };
73 double getAltitude () { return altitude; };
74 double getSpeed () { return speed; };
76 double getCrossat () { return crossat; };
77 bool getGear_down () { return gear_down; };
78 bool getFlaps_down () { return flaps_down; };
79 bool getOn_ground () { return on_ground; };
80 int getRouteIndex () { return routeIndex; };
81 bool isFinished () { return finished; };
82 double getTime_sec () { return time_sec; };
83 double getTrackLength() { return trackLength; };
84 std::string getTime () { return time; };
89 class FGAIFlightPlan {
94 FGAIFlightPlan(const std::string& filename);
95 FGAIFlightPlan(FGAIAircraft *,
107 const std::string& fltType,
108 const std::string& acType,
109 const std::string& airline);
112 FGAIWaypoint* const getPreviousWaypoint( void ) const;
113 FGAIWaypoint* const getCurrentWaypoint( void ) const;
114 FGAIWaypoint* const getNextWaypoint( void ) const;
115 void IncrementWaypoint( bool erase );
116 void DecrementWaypoint( bool erase );
118 double getDistanceToGo(double lat, double lon, FGAIWaypoint* wp) const;
119 int getLeg () const { return leg;};
121 void setLeadDistance(double speed, double bearing, FGAIWaypoint* current, FGAIWaypoint* next);
122 void setLeadDistance(double distance_ft);
123 double getLeadDistance( void ) const {return lead_distance;}
124 double getBearing(FGAIWaypoint* previous, FGAIWaypoint* next) const;
125 double getBearing(double lat, double lon, FGAIWaypoint* next) const;
126 double checkTrackLength(std::string wptName);
127 time_t getStartTime() const { return start_time; }
128 time_t getArrivalTime() const { return arrivalTime; }
130 bool create(FGAIAircraft *, FGAirport *dep, FGAirport *arr, int leg, double alt, double speed, double lat, double lon,
131 bool firstLeg, double radius, const std::string& fltType, const std::string& aircraftType, const std::string& airline, double distance);
132 bool createPushBack(FGAIAircraft *, bool, FGAirport*, double, double, double, const std::string&, const std::string&, const std::string&);
133 bool createTakeOff(FGAIAircraft *, bool, FGAirport *, double, const std::string&);
135 void setLeg(int val) { leg = val;}
136 void setTime(time_t st) { start_time = st; }
137 int getGate() const { return gateId; }
138 void setGate(int id) { gateId = id; };
140 double getLeadInAngle() const { return leadInAngle; }
141 const std::string& getRunway() const;
143 void setRepeat(bool r) { repeat = r; }
144 bool getRepeat(void) const { return repeat; }
146 int getNrOfWayPoints() { return waypoints.size(); }
147 int getRouteIndex(int i); // returns the AI related index of this current routes.
148 FGTaxiRoute *getTaxiRoute() { return taxiRoute; }
149 void deleteTaxiRoute();
150 std::string getRunway() { return activeRunway; }
151 bool isActive(time_t time) {return time >= this->getStartTime();}
153 void incrementLeg() { leg++;};
155 void setRunway(std::string rwy) { activeRunway = rwy; };
156 std::string getRunwayClassFromTrafficType(std::string fltType);
158 void addWaypoint(FGAIWaypoint* wpt) { waypoints.push_back(wpt); };
160 void setName(std::string n) { name = n; };
161 std::string getName() { return name; };
163 void setSID(FGAIFlightPlan* fp) { sid = fp;};
164 FGAIFlightPlan* getSID() { return sid; };
165 FGAIWaypoint *getWayPoint(int i) { return waypoints[i]; };
166 FGAIWaypoint *getLastWaypoint() { return waypoints.back(); };
168 void shortenToFirst(unsigned int number, std::string name);
172 typedef std::vector <FGAIWaypoint*> wpt_vector_type;
173 typedef wpt_vector_type::const_iterator wpt_vector_iterator;
176 wpt_vector_type waypoints;
177 wpt_vector_iterator wpt_iterator;
180 double distance_to_go;
181 double lead_distance;
184 time_t arrivalTime; // For AI/ATC purposes.
186 int gateId, lastNodeVisited;
187 std::string activeRunway;
188 FGTaxiRoute *taxiRoute;
192 void createPushBackFallBack(FGAIAircraft *, bool, FGAirport*, double, double, double, const std::string&, const std::string&, const std::string&);
193 bool createClimb(FGAIAircraft *, bool, FGAirport *, double, double, const std::string&);
194 bool createCruise(FGAIAircraft *, bool, FGAirport*, FGAirport*, double, double, double, double, const std::string&);
195 bool createDescent(FGAIAircraft *, FGAirport *, double latitude, double longitude, double speed, double alt,const std::string&, double distance);
196 bool createLanding(FGAIAircraft *, FGAirport *, const std::string&);
197 bool createParking(FGAIAircraft *, FGAirport *, double radius);
198 void deleteWaypoints();
199 void resetWaypoints();
200 void eraseLastWaypoint();
201 void pushBackWaypoint(FGAIWaypoint *wpt);
203 bool createLandingTaxi(FGAIAircraft *, FGAirport *apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
204 void createDefaultLandingTaxi(FGAIAircraft *, FGAirport* aAirport);
205 void createDefaultTakeoffTaxi(FGAIAircraft *, FGAirport* aAirport, FGRunway* aRunway);
206 bool createTakeoffTaxi(FGAIAircraft *, bool firstFlight, FGAirport *apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
208 double getTurnRadius(double, bool);
210 FGAIWaypoint* createOnGround(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
211 FGAIWaypoint* createInAir(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
212 FGAIWaypoint* cloneWithPos(FGAIAircraft *, FGAIWaypoint* aWpt, const std::string& aName, const SGGeod& aPos);
213 FGAIWaypoint* clone(FGAIWaypoint* aWpt);
216 //void createCruiseFallback(bool, FGAirport*, FGAirport*, double, double, double, double);
217 void evaluateRoutePart(double deplat, double deplon, double arrlat, double arrlon);
219 wpt_vector_iterator getFirstWayPoint() { return waypoints.begin(); };
220 wpt_vector_iterator getLastWayPoint() { return waypoints.end(); };
221 bool isValidPlan() { return isValid; };
224 #endif // _FG_AIFLIGHTPLAN_HXX