]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIFlightPlan.hxx
Merge branch 'next' of git://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., 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
93   void setLeg(int val) { leg = val;}
94   void setTime(time_t st) { start_time = st; }
95   int getGate() const { return gateId; }
96   double getLeadInAngle() const { return leadInAngle; }
97   const std::string& getRunway() const;
98   
99   void setRepeat(bool r) { repeat = r; }
100   bool getRepeat(void) const { return repeat; }
101   void restart(void);
102   int getNrOfWayPoints() { return waypoints.size(); }
103   int getRouteIndex(int i); // returns the AI related index of this current routes. 
104   FGTaxiRoute *getTaxiRoute() { return taxiRoute; }
105   void deleteTaxiRoute();
106   std::string getRunway() { return activeRunway; }
107   bool isActive(time_t time) {return time >= this->getStartTime();}
108
109   void setRunway(std::string rwy) { activeRunway = rwy; };
110   std::string getRunwayClassFromTrafficType(std::string fltType);
111
112   void addWaypoint(waypoint* wpt) { waypoints.push_back(wpt); };
113
114   void setName(std::string n) { name = n; };
115   std::string getName() { return name; };
116
117   void setSID(FGAIFlightPlan* fp) { sid = fp;};
118   FGAIFlightPlan* getSID() { return sid; };
119
120 private:
121   FGRunway* rwy;
122   FGAIFlightPlan *sid;
123   typedef std::vector <waypoint*> wpt_vector_type;
124   typedef wpt_vector_type::const_iterator wpt_vector_iterator;
125
126
127   wpt_vector_type       waypoints;
128   wpt_vector_iterator   wpt_iterator;
129
130   bool repeat;
131   double distance_to_go;
132   double lead_distance;
133   double leadInAngle;
134   time_t start_time;
135   time_t arrivalTime;       // For AI/ATC purposes.
136   int leg;
137   int gateId, lastNodeVisited;
138   std::string activeRunway;
139   FGTaxiRoute *taxiRoute;
140   std::string name;
141
142   void createPushBack(FGAIAircraft *, bool, FGAirport*, double, double, double, const std::string&, const std::string&, const std::string&);
143   void createPushBackFallBack(FGAIAircraft *, bool, FGAirport*, double, double, double, const std::string&, const std::string&, const std::string&);
144   void createTakeOff(FGAIAircraft *, bool, FGAirport *, double, const std::string&);
145   void createClimb(FGAIAircraft *, bool, FGAirport *, double, double, const std::string&);
146   void createCruise(FGAIAircraft *, bool, FGAirport*, FGAirport*, double, double, double, double, const std::string&);
147   void createDescent(FGAIAircraft *, FGAirport *,  double latitude, double longitude, double speed, double alt,const std::string&, double distance);
148   void createLanding(FGAIAircraft *, FGAirport *, const std::string&);
149   void createParking(FGAIAircraft *, FGAirport *, double radius);
150   void deleteWaypoints(); 
151   void resetWaypoints();
152
153   void createLandingTaxi(FGAIAircraft *, FGAirport *apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
154   void createDefaultLandingTaxi(FGAIAircraft *, FGAirport* aAirport);
155   void createDefaultTakeoffTaxi(FGAIAircraft *, FGAirport* aAirport, FGRunway* aRunway);
156   void createTakeoffTaxi(FGAIAircraft *, bool firstFlight, FGAirport *apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
157
158   double getTurnRadius(double, bool);
159         
160   waypoint* createOnGround(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
161   waypoint* createInAir(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
162   waypoint* cloneWithPos(FGAIAircraft *, waypoint* aWpt, const std::string& aName, const SGGeod& aPos);
163   waypoint* clone(waypoint* aWpt);
164     
165
166   //void createCruiseFallback(bool, FGAirport*, FGAirport*, double, double, double, double);
167  void evaluateRoutePart(double deplat, double deplon, double arrlat, double arrlon);
168  public:
169   wpt_vector_iterator getFirstWayPoint() { return waypoints.begin(); };
170   wpt_vector_iterator getLastWayPoint()  { return waypoints.end(); };
171
172 };    
173
174 #endif  // _FG_AIFLIGHTPLAN_HXX