]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIFlightPlan.hxx
Alexis Bory:
[flightgear.git] / src / AIModel / AIFlightPlan.hxx
1 // FGAIFlightPlan - class for loading and storing  AI flight plans
2 // Written by David Culp, started May 2004
3 // - davidculp2@comcast.net
4 //
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.
9 //
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.
14 //
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.
18
19 #ifndef _FG_AIFLIGHTPLAN_HXX
20 #define _FG_AIFLIGHTPLAN_HXX
21
22 #include <vector>
23 #include <string>
24
25 #include <simgear/compiler.h>
26 #include <simgear/math/SGMath.hxx>
27 #include <simgear/structure/SGSharedPtr.hxx>
28
29 // forward decls
30 class FGTaxiRoute;
31 class FGRunway;
32 class FGAIAircraft;
33 class FGAirport;
34
35 typedef SGSharedPtr<FGAirport> FGAirportRef;
36
37 class FGAIWaypoint {
38 private:
39    std::string name;
40    SGGeod pos;
41    double speed;
42    double crossat;
43    bool finished;
44    bool gear_down;
45    bool flaps_down;
46    bool on_ground;
47     int routeIndex;  // For AI/ATC purposes;
48    double time_sec;
49    double trackLength; // distance from previous FGAIWaypoint (for AI purposes);
50    std::string time;
51
52 public:
53     FGAIWaypoint();
54     ~FGAIWaypoint() {};
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; };
70
71     bool contains(std::string name);
72
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;       };
79
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;        };
89
90   };
91
92
93 class FGAIFlightPlan {
94
95 public:
96
97   FGAIFlightPlan();
98   FGAIFlightPlan(const std::string& filename);
99   FGAIFlightPlan(FGAIAircraft *,
100                  const std::string& p,
101                  double course,
102                  time_t start,
103                  FGAirport *dep,
104                  FGAirport *arr,
105                  bool firstLeg,
106                  double radius,
107                  double alt,
108                  double lat,
109                  double lon,
110                  double speed,
111                  const std::string& fltType,
112                  const std::string& acType,
113                  const std::string& airline);
114    ~FGAIFlightPlan();
115
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 );
121
122    double getDistanceToGo(double lat, double lon, FGAIWaypoint* wp) const;
123    int getLeg () const { return leg;};
124    
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;
130   
131    double checkTrackLength(std::string wptName);
132   time_t getStartTime() const { return start_time; }
133    time_t getArrivalTime() const { return arrivalTime; }
134
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&);
139
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; };
144
145   double getLeadInAngle() const { return leadInAngle; }
146   const std::string& getRunway() const;
147   
148   void setRepeat(bool r) { repeat = r; }
149   bool getRepeat(void) const { return repeat; }
150   void restart(void);
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();}
157
158   void incrementLeg() { leg++;};
159
160   void setRunway(std::string rwy) { activeRunway = rwy; };
161   std::string getRunwayClassFromTrafficType(std::string fltType);
162
163   void addWaypoint(FGAIWaypoint* wpt) { waypoints.push_back(wpt); };
164
165   void setName(std::string n) { name = n; };
166   std::string getName() { return name; };
167
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(); };
172   
173   void shortenToFirst(unsigned int number, std::string name);
174
175 private:
176   FGAIFlightPlan *sid;
177   typedef std::vector <FGAIWaypoint*> wpt_vector_type;
178   typedef wpt_vector_type::const_iterator wpt_vector_iterator;
179
180
181   wpt_vector_type       waypoints;
182   wpt_vector_iterator   wpt_iterator;
183
184   bool repeat;
185   double distance_to_go;
186   double lead_distance;
187   double leadInAngle;
188   time_t start_time;
189   time_t arrivalTime;       // For AI/ATC purposes.
190   int leg;
191   int gateId, lastNodeVisited;
192   std::string activeRunway;
193   FGTaxiRoute *taxiRoute;
194   std::string name;
195   bool isValid;
196   FGAirportRef departure, arrival;
197   
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);
208
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);
213
214   double getTurnRadius(double, bool);
215         
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);
220     
221
222   //void createCruiseFallback(bool, FGAirport*, FGAirport*, double, double, double, double);
223  void evaluateRoutePart(double deplat, double deplon, double arrlat, double arrlon);
224   
225   /**
226    * look for and parse an PropertyList flight-plan file - essentially
227    * a flat list waypoint objects, encoded to properties
228    */
229   bool parseProperties(const std::string& filename);
230   
231   void createWaypoints(FGAIAircraft *ac,
232                        double course,
233                        time_t start,
234                        FGAirport *dep,
235                        FGAirport *arr,
236                        bool firstLeg,
237                        double radius,
238                        double alt,
239                        double lat,
240                        double lon,
241                        double speed,
242                        const std::string& fltType,
243                        const std::string& acType,
244                        const std::string& airline);
245   
246  public:
247   wpt_vector_iterator getFirstWayPoint() { return waypoints.begin(); };
248   wpt_vector_iterator getLastWayPoint()  { return waypoints.end(); };
249     bool isValidPlan() { return isValid; };
250 };
251
252 #endif  // _FG_AIFLIGHTPLAN_HXX