]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIFlightPlan.hxx
Fix stray back-button in Qt launcher
[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 #include <Navaids/positioned.hxx>
29 #include <Airports/dynamics.hxx>
30
31 class FGAIWaypoint {
32 private:
33    std::string name;
34    SGGeod pos;
35    double speed;
36    double crossat;
37    bool finished;
38    bool gear_down;
39    bool flaps_down;
40    bool on_ground;
41     int routeIndex;  // For AI/ATC purposes;
42    double time_sec;
43    double trackLength; // distance from previous FGAIWaypoint (for AI purposes);
44    std::string time;
45
46 public:
47     FGAIWaypoint();
48     ~FGAIWaypoint() {};
49     void setName        (const std::string& nam) { name        = nam; };
50     void setLatitude    (double lat);
51     void setLongitude   (double lon);
52     void setAltitude    (double alt);
53     void setPos         (const SGGeod& aPos) { pos = aPos; }
54     void setSpeed       (double spd) { speed       = spd; };
55     void setCrossat     (double val) { crossat     = val; };
56     void setFinished    (bool   fin) { finished    = fin; };
57     void setGear_down   (bool   grd) { gear_down   = grd; };
58     void setFlaps_down  (bool   fld) { flaps_down  = fld; };
59     void setOn_ground   (bool   grn) { on_ground   = grn; };
60     void setRouteIndex  (int    rte) { routeIndex  = rte; };
61     void setTime_sec    (double ts ) { time_sec    = ts;  };
62     void setTrackLength (double tl ) { trackLength = tl;  };
63     void setTime        (const std::string& tme) { time        = tme; };
64
65     bool contains(const std::string& name);
66
67     const std::string& getName() { return name;        };
68     const SGGeod& getPos () { return pos;         };
69     double getLatitude   ();
70     double getLongitude  ();
71     double getAltitude   ();
72     double getSpeed      () { return speed;       };
73
74     double getCrossat    () { return crossat;     };
75     bool   getGear_down  () { return gear_down;   };
76     bool   getFlaps_down () { return flaps_down;  };
77     bool   getOn_ground  () { return on_ground;   };
78     int    getRouteIndex () { return routeIndex;  };
79     bool   isFinished    () { return finished;    };
80     double getTime_sec   () { return time_sec;    };
81     double getTrackLength() { return trackLength; };
82     const std::string& getTime  () { return time;        };
83
84   };
85
86
87 class FGAIFlightPlan {
88
89 public:
90
91   FGAIFlightPlan();
92   FGAIFlightPlan(const std::string& filename);
93   FGAIFlightPlan(FGAIAircraft *,
94                  const std::string& p,
95                  double course,
96                  time_t start,
97                  FGAirport *dep,
98                  FGAirport *arr,
99                  bool firstLeg,
100                  double radius,
101                  double alt,
102                  double lat,
103                  double lon,
104                  double speed,
105                  const std::string& fltType,
106                  const std::string& acType,
107                  const std::string& airline);
108    ~FGAIFlightPlan();
109
110    FGAIWaypoint* const getPreviousWaypoint( void ) const;
111    FGAIWaypoint* const getCurrentWaypoint( void ) const;
112    FGAIWaypoint* const getNextWaypoint( void ) const;
113    void IncrementWaypoint( bool erase );
114    void DecrementWaypoint( bool erase );
115
116    double getDistanceToGo(double lat, double lon, FGAIWaypoint* wp) const;
117    int getLeg () const { return leg;};
118    
119    void setLeadDistance(double speed, double bearing, FGAIWaypoint* current, FGAIWaypoint* next);
120    void setLeadDistance(double distance_ft);
121    double getLeadDistance( void ) const {return lead_distance;}
122    double getBearing(FGAIWaypoint* previous, FGAIWaypoint* next) const;
123    double getBearing(const SGGeod& aPos, FGAIWaypoint* next) const;
124   
125    double checkTrackLength(const std::string& wptName) const;
126   time_t getStartTime() const { return start_time; }
127    time_t getArrivalTime() const { return arrivalTime; }
128
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&);
133
134   void setLeg(int val) { leg = val;}
135   void setTime(time_t st) { start_time = st; }
136
137
138   double getLeadInAngle() const { return leadInAngle; }
139   const std::string& getRunway() const;
140   
141   void setRepeat(bool r) { repeat = r; }
142   bool getRepeat(void) const { return repeat; }
143   void restart(void);
144   int getNrOfWayPoints() { return waypoints.size(); }
145
146   int getRouteIndex(int i); // returns the AI related index of this current routes.
147
148   const std::string& getRunway() { return activeRunway; }
149   bool isActive(time_t time) {return time >= this->getStartTime();}
150
151   void incrementLeg() { leg++;};
152
153   void setRunway(const std::string& rwy) { activeRunway = rwy; };
154   const char* getRunwayClassFromTrafficType(const std::string& fltType);
155
156   void addWaypoint(FGAIWaypoint* wpt) { waypoints.push_back(wpt); };
157
158   void setName(const std::string& n) { name = n; };
159   const std::string& getName() { return name; };
160
161   void setSID(FGAIFlightPlan* fp) { sid = fp;};
162   FGAIFlightPlan* getSID() { return sid; };
163   FGAIWaypoint *getWayPoint(int i) { return waypoints[i]; };
164   FGAIWaypoint *getLastWaypoint() { return waypoints.back(); };
165   
166   void shortenToFirst(unsigned int number, std::string name);
167
168   void setGate(const ParkingAssignment& pka);
169   FGParking* getParkingGate();
170
171     FGAirportRef departureAirport() const;
172     FGAirportRef arrivalAirport() const;
173 private:
174   FGAIFlightPlan *sid;
175   typedef std::vector <FGAIWaypoint*> wpt_vector_type;
176   typedef wpt_vector_type::const_iterator wpt_vector_iterator;
177
178
179   wpt_vector_type       waypoints;
180   wpt_vector_iterator   wpt_iterator;
181
182   bool repeat;
183   double distance_to_go;
184   double lead_distance;
185   double leadInAngle;
186   time_t start_time;
187   time_t arrivalTime;       // For AI/ATC purposes.
188   int leg;
189   ParkingAssignment gate;
190   FGTaxiNodeRef lastNodeVisited;
191   std::string activeRunway;
192   std::string name;
193   bool isValid;
194   FGAirportRef departure, arrival;
195   
196   void createPushBackFallBack(FGAIAircraft *, bool, FGAirport*, double radius, const std::string&, const std::string&, const std::string&);
197   bool createClimb(FGAIAircraft *, bool, FGAirport *, FGAirport* arrival, double, double, const std::string&);
198   bool createCruise(FGAIAircraft *, bool, FGAirport*, FGAirport*, double, double, double, double, const std::string&);
199   bool createDescent(FGAIAircraft *, FGAirport *,  double latitude, double longitude, double speed, double alt,const std::string&, double distance);
200   bool createLanding(FGAIAircraft *, FGAirport *, const std::string&);
201   bool createParking(FGAIAircraft *, FGAirport *, double radius);
202   void deleteWaypoints(); 
203   void resetWaypoints();
204   void eraseLastWaypoint();
205   void pushBackWaypoint(FGAIWaypoint *wpt);
206
207   bool createLandingTaxi(FGAIAircraft *, FGAirport *apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
208   void createDefaultLandingTaxi(FGAIAircraft *, FGAirport* aAirport);
209   void createDefaultTakeoffTaxi(FGAIAircraft *, FGAirport* aAirport, FGRunway* aRunway);
210   bool createTakeoffTaxi(FGAIAircraft *, bool firstFlight, FGAirport *apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
211
212   double getTurnRadius(double, bool);
213         
214   FGAIWaypoint* createOnGround(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
215   FGAIWaypoint* createInAir(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
216   FGAIWaypoint* cloneWithPos(FGAIAircraft *, FGAIWaypoint* aWpt, const std::string& aName, const SGGeod& aPos);
217   FGAIWaypoint* clone(FGAIWaypoint* aWpt);
218     
219
220   //void createCruiseFallback(bool, FGAirport*, FGAirport*, double, double, double, double);
221  void evaluateRoutePart(double deplat, double deplon, double arrlat, double arrlon);
222   
223   /**
224    * look for and parse an PropertyList flight-plan file - essentially
225    * a flat list waypoint objects, encoded to properties
226    */
227   bool parseProperties(const std::string& filename);
228   
229   void createWaypoints(FGAIAircraft *ac,
230                        double course,
231                        time_t start,
232                        FGAirport *dep,
233                        FGAirport *arr,
234                        bool firstLeg,
235                        double radius,
236                        double alt,
237                        double lat,
238                        double lon,
239                        double speed,
240                        const std::string& fltType,
241                        const std::string& acType,
242                        const std::string& airline);
243   
244  public:
245   wpt_vector_iterator getFirstWayPoint() { return waypoints.begin(); };
246   wpt_vector_iterator getLastWayPoint()  { return waypoints.end(); };
247   bool isValidPlan() { return isValid; };
248 };
249
250 #endif  // _FG_AIFLIGHTPLAN_HXX