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