]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIFlightPlan.hxx
Merge branch 'next' into durk-atc
[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., 675 Mass Ave, Cambridge, MA 02139, 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 FGAIFlightPlan {
34
35 public:
36
37   typedef struct {
38    std::string name;
39    double latitude;
40    double longitude;
41    double altitude;
42    double speed;
43    double crossat;
44    bool finished;
45    bool gear_down;
46    bool flaps_down;
47    bool on_ground;
48     int routeIndex;  // For AI/ATC purposes;
49    double time_sec;
50    double trackLength; // distance from previous waypoint (for AI purposes);
51    std::string time;
52
53   } waypoint;
54   FGAIFlightPlan();
55   FGAIFlightPlan(const std::string& filename);
56   FGAIFlightPlan(FGAIAircraft *,
57                  const std::string& p,
58                  double course,
59                  time_t start,
60                  FGAirport *dep,
61                  FGAirport *arr,
62                  bool firstLeg,
63                  double radius,
64                  double alt,
65                  double lat,
66                  double lon,
67                  double speed,
68                  const std::string& fltType,
69                  const std::string& acType,
70                  const std::string& airline);
71    ~FGAIFlightPlan();
72
73    waypoint* const getPreviousWaypoint( void ) const;
74    waypoint* const getCurrentWaypoint( void ) const;
75    waypoint* const getNextWaypoint( void ) const;
76    void IncrementWaypoint( bool erase );
77    void DecrementWaypoint( bool erase );
78
79    double getDistanceToGo(double lat, double lon, waypoint* wp) const;
80    int getLeg () const { return leg;};
81    void setLeadDistance(double speed, double bearing, waypoint* current, waypoint* next);
82    void setLeadDistance(double distance_ft);
83    double getLeadDistance( void ) const {return lead_distance;}
84    double getBearing(waypoint* previous, waypoint* next) const;
85    double getBearing(double lat, double lon, waypoint* next) const;
86    double checkTrackLength(std::string wptName);
87   time_t getStartTime() const { return start_time; }
88    time_t getArrivalTime() const { return arrivalTime; }
89
90   void    create(FGAIAircraft *, FGAirport *dep, FGAirport *arr, int leg, double alt, double speed, double lat, double lon,
91                  bool firstLeg, double radius, const std::string& fltType, const std::string& aircraftType, const std::string& airline, double distance);
92   void createPushBack(FGAIAircraft *, bool, FGAirport*, double, double, double, const std::string&, const std::string&, const std::string&);
93   void createTakeOff(FGAIAircraft *, bool, FGAirport *, double, const std::string&);
94
95   void setLeg(int val) { leg = val;}
96   void setTime(time_t st) { start_time = st; }
97   int getGate() const { return gateId; }
98   void setGate(int id) { gateId = id; };
99
100   double getLeadInAngle() const { return leadInAngle; }
101   const std::string& getRunway() const;
102   
103   void setRepeat(bool r) { repeat = r; }
104   bool getRepeat(void) const { return repeat; }
105   void restart(void);
106   int getNrOfWayPoints() { return waypoints.size(); }
107   int getRouteIndex(int i); // returns the AI related index of this current routes. 
108   FGTaxiRoute *getTaxiRoute() { return taxiRoute; }
109   void deleteTaxiRoute();
110   std::string getRunway() { return activeRunway; }
111   bool isActive(time_t time) {return time >= this->getStartTime();}
112
113   void setRunway(std::string rwy) { activeRunway = rwy; };
114   std::string getRunwayClassFromTrafficType(std::string fltType);
115
116   void addWaypoint(waypoint* wpt) { waypoints.push_back(wpt); };
117
118   void setName(std::string n) { name = n; };
119   std::string getName() { return name; };
120
121   void setSID(FGAIFlightPlan* fp) { sid = fp;};
122   FGAIFlightPlan* getSID() { return sid; };
123
124 private:
125   FGRunway* rwy;
126   FGAIFlightPlan *sid;
127   typedef std::vector <waypoint*> wpt_vector_type;
128   typedef wpt_vector_type::const_iterator wpt_vector_iterator;
129
130
131   wpt_vector_type       waypoints;
132   wpt_vector_iterator   wpt_iterator;
133
134   bool repeat;
135   double distance_to_go;
136   double lead_distance;
137   double leadInAngle;
138   time_t start_time;
139   time_t arrivalTime;       // For AI/ATC purposes.
140   int leg;
141   int gateId, lastNodeVisited;
142   std::string activeRunway;
143   FGTaxiRoute *taxiRoute;
144   std::string name;
145
146   void createPushBackFallBack(FGAIAircraft *, bool, FGAirport*, double, double, double, const std::string&, const std::string&, const std::string&);
147   void createClimb(FGAIAircraft *, bool, FGAirport *, double, double, const std::string&);
148   void createCruise(FGAIAircraft *, bool, FGAirport*, FGAirport*, double, double, double, double, const std::string&);
149   void createDescent(FGAIAircraft *, FGAirport *,  double latitude, double longitude, double speed, double alt,const std::string&, double distance);
150   void createLanding(FGAIAircraft *, FGAirport *, const std::string&);
151   void createParking(FGAIAircraft *, FGAirport *, double radius);
152   void deleteWaypoints(); 
153   void resetWaypoints();
154
155   void createLandingTaxi(FGAIAircraft *, FGAirport *apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
156   void createDefaultLandingTaxi(FGAIAircraft *, FGAirport* aAirport);
157   void createDefaultTakeoffTaxi(FGAIAircraft *, FGAirport* aAirport, FGRunway* aRunway);
158   void createTakeoffTaxi(FGAIAircraft *, bool firstFlight, FGAirport *apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
159
160   double getTurnRadius(double, bool);
161         
162   waypoint* createOnGround(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
163   waypoint* createInAir(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
164   waypoint* cloneWithPos(FGAIAircraft *, waypoint* aWpt, const std::string& aName, const SGGeod& aPos);
165   waypoint* clone(waypoint* aWpt);
166     
167
168   //void createCruiseFallback(bool, FGAirport*, FGAirport*, double, double, double, double);
169  void evaluateRoutePart(double deplat, double deplon, double arrlat, double arrlon);
170  public:
171   wpt_vector_iterator getFirstWayPoint() { return waypoints.begin(); };
172   wpt_vector_iterator getLastWayPoint()  { return waypoints.end(); };
173
174 };    
175
176 #endif  // _FG_AIFLIGHTPLAN_HXX