]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIFlightPlan.hxx
toggle fullscreen: also adapt GUI plane when resizing
[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        (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        (std::string tme) { time        = tme; };
72
73     bool contains(std::string name);
74
75     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     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(std::string wptName);
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   std::string getRunway() { return activeRunway; }
157   bool isActive(time_t time) {return time >= this->getStartTime();}
158
159   void incrementLeg() { leg++;};
160
161   void setRunway(std::string rwy) { activeRunway = rwy; };
162   std::string getRunwayClassFromTrafficType(std::string fltType);
163
164   void addWaypoint(FGAIWaypoint* wpt) { waypoints.push_back(wpt); };
165
166   void setName(std::string n) { name = n; };
167   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(ParkingAssignment pka);
177   FGParking* getParkingGate();
178 private:
179   FGAIFlightPlan *sid;
180   typedef std::vector <FGAIWaypoint*> wpt_vector_type;
181   typedef wpt_vector_type::const_iterator wpt_vector_iterator;
182
183
184   wpt_vector_type       waypoints;
185   wpt_vector_iterator   wpt_iterator;
186
187   bool repeat;
188   double distance_to_go;
189   double lead_distance;
190   double leadInAngle;
191   time_t start_time;
192   time_t arrivalTime;       // For AI/ATC purposes.
193   int leg;
194   ParkingAssignment gate;
195   PositionedID lastNodeVisited;
196   std::string activeRunway;
197   std::string name;
198   bool isValid;
199   FGAirportRef departure, arrival;
200   
201   void createPushBackFallBack(FGAIAircraft *, bool, FGAirport*, double radius, const std::string&, const std::string&, const std::string&);
202   bool createClimb(FGAIAircraft *, bool, FGAirport *, FGAirport* arrival, double, double, const std::string&);
203   bool createCruise(FGAIAircraft *, bool, FGAirport*, FGAirport*, double, double, double, double, const std::string&);
204   bool createDescent(FGAIAircraft *, FGAirport *,  double latitude, double longitude, double speed, double alt,const std::string&, double distance);
205   bool createLanding(FGAIAircraft *, FGAirport *, const std::string&);
206   bool createParking(FGAIAircraft *, FGAirport *, double radius);
207   void deleteWaypoints(); 
208   void resetWaypoints();
209   void eraseLastWaypoint();
210   void pushBackWaypoint(FGAIWaypoint *wpt);
211
212   bool createLandingTaxi(FGAIAircraft *, FGAirport *apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
213   void createDefaultLandingTaxi(FGAIAircraft *, FGAirport* aAirport);
214   void createDefaultTakeoffTaxi(FGAIAircraft *, FGAirport* aAirport, FGRunway* aRunway);
215   bool createTakeoffTaxi(FGAIAircraft *, bool firstFlight, FGAirport *apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
216
217   double getTurnRadius(double, bool);
218         
219   FGAIWaypoint* createOnGround(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
220   FGAIWaypoint* createInAir(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
221   FGAIWaypoint* cloneWithPos(FGAIAircraft *, FGAIWaypoint* aWpt, const std::string& aName, const SGGeod& aPos);
222   FGAIWaypoint* clone(FGAIWaypoint* aWpt);
223     
224
225   //void createCruiseFallback(bool, FGAirport*, FGAirport*, double, double, double, double);
226  void evaluateRoutePart(double deplat, double deplon, double arrlat, double arrlon);
227   
228   /**
229    * look for and parse an PropertyList flight-plan file - essentially
230    * a flat list waypoint objects, encoded to properties
231    */
232   bool parseProperties(const std::string& filename);
233   
234   void createWaypoints(FGAIAircraft *ac,
235                        double course,
236                        time_t start,
237                        FGAirport *dep,
238                        FGAirport *arr,
239                        bool firstLeg,
240                        double radius,
241                        double alt,
242                        double lat,
243                        double lon,
244                        double speed,
245                        const std::string& fltType,
246                        const std::string& acType,
247                        const std::string& airline);
248   
249  public:
250   wpt_vector_iterator getFirstWayPoint() { return waypoints.begin(); };
251   wpt_vector_iterator getLastWayPoint()  { return waypoints.end(); };
252     bool isValidPlan() { return isValid; };
253 };
254
255 #endif  // _FG_AIFLIGHTPLAN_HXX