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