]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIFlightPlan.hxx
Fix a GCC warning.
[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 // forward decls
32 class FGTaxiRoute;
33 class FGRunway;
34 class FGAIAircraft;
35 class FGAirport;
36
37 typedef SGSharedPtr<FGAirport> FGAirportRef;
38
39 class FGAIWaypoint {
40 private:
41    std::string name;
42    SGGeod pos;
43    double speed;
44    double crossat;
45    bool finished;
46    bool gear_down;
47    bool flaps_down;
48    bool on_ground;
49     int routeIndex;  // For AI/ATC purposes;
50    double time_sec;
51    double trackLength; // distance from previous FGAIWaypoint (for AI purposes);
52    std::string time;
53
54 public:
55     FGAIWaypoint();
56     ~FGAIWaypoint() {};
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; };
72
73     bool contains(const std::string& name);
74
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;       };
81
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;        };
91
92   };
93
94
95 class FGAIFlightPlan {
96
97 public:
98
99   FGAIFlightPlan();
100   FGAIFlightPlan(const std::string& filename);
101   FGAIFlightPlan(FGAIAircraft *,
102                  const std::string& p,
103                  double course,
104                  time_t start,
105                  FGAirport *dep,
106                  FGAirport *arr,
107                  bool firstLeg,
108                  double radius,
109                  double alt,
110                  double lat,
111                  double lon,
112                  double speed,
113                  const std::string& fltType,
114                  const std::string& acType,
115                  const std::string& airline);
116    ~FGAIFlightPlan();
117
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 );
123
124    double getDistanceToGo(double lat, double lon, FGAIWaypoint* wp) const;
125    int getLeg () const { return leg;};
126    
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;
132   
133    double checkTrackLength(const std::string& wptName) const;
134   time_t getStartTime() const { return start_time; }
135    time_t getArrivalTime() const { return arrivalTime; }
136
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&);
141
142   void setLeg(int val) { leg = val;}
143   void setTime(time_t st) { start_time = st; }
144
145
146   double getLeadInAngle() const { return leadInAngle; }
147   const std::string& getRunway() const;
148   
149   void setRepeat(bool r) { repeat = r; }
150   bool getRepeat(void) const { return repeat; }
151   void restart(void);
152   int getNrOfWayPoints() { return waypoints.size(); }
153
154   int getRouteIndex(int i); // returns the AI related index of this current routes.
155
156   const std::string& getRunway() { return activeRunway; }
157   bool isActive(time_t time) {return time >= this->getStartTime();}
158
159   void incrementLeg() { leg++;};
160
161   void setRunway(const std::string& rwy) { activeRunway = rwy; };
162   const char* getRunwayClassFromTrafficType(const std::string& fltType);
163
164   void addWaypoint(FGAIWaypoint* wpt) { waypoints.push_back(wpt); };
165
166   void setName(const std::string& n) { name = n; };
167   const std::string& getName() { return name; };
168
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(); };
173   
174   void shortenToFirst(unsigned int number, std::string name);
175
176   void setGate(const ParkingAssignment& pka);
177   FGParking* getParkingGate();
178
179 private:
180   FGAIFlightPlan *sid;
181   typedef std::vector <FGAIWaypoint*> wpt_vector_type;
182   typedef wpt_vector_type::const_iterator wpt_vector_iterator;
183
184
185   wpt_vector_type       waypoints;
186   wpt_vector_iterator   wpt_iterator;
187
188   bool repeat;
189   double distance_to_go;
190   double lead_distance;
191   double leadInAngle;
192   time_t start_time;
193   time_t arrivalTime;       // For AI/ATC purposes.
194   int leg;
195   ParkingAssignment gate;
196   PositionedID lastNodeVisited;
197   std::string activeRunway;
198   std::string name;
199   bool isValid;
200   FGAirportRef departure, arrival;
201   
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);
212
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);
217
218   double getTurnRadius(double, bool);
219         
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);
224     
225
226   //void createCruiseFallback(bool, FGAirport*, FGAirport*, double, double, double, double);
227  void evaluateRoutePart(double deplat, double deplon, double arrlat, double arrlon);
228   
229   /**
230    * look for and parse an PropertyList flight-plan file - essentially
231    * a flat list waypoint objects, encoded to properties
232    */
233   bool parseProperties(const std::string& filename);
234   
235   void createWaypoints(FGAIAircraft *ac,
236                        double course,
237                        time_t start,
238                        FGAirport *dep,
239                        FGAirport *arr,
240                        bool firstLeg,
241                        double radius,
242                        double alt,
243                        double lat,
244                        double lon,
245                        double speed,
246                        const std::string& fltType,
247                        const std::string& acType,
248                        const std::string& airline);
249   
250  public:
251   wpt_vector_iterator getFirstWayPoint() { return waypoints.begin(); };
252   wpt_vector_iterator getLastWayPoint()  { return waypoints.end(); };
253     bool isValidPlan() { return isValid; };
254 };
255
256 #endif  // _FG_AIFLIGHTPLAN_HXX