FlightGear next
AIFlightPlan.hxx
Go to the documentation of this file.
1/*
2 * SPDX-FileName: AIFlightPlan.hxx
3 * SPDX-FileComment: class for loading and storing AI flight plans
4 * SPDX-FileCopyrightText: Written by David Culp, started May 2004 - davidculp2@comcast.net
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8#pragma once
9
10#include <string>
11#include <vector>
12
13#include <Airports/dynamics.hxx>
15#include <simgear/compiler.h>
16#include <simgear/math/SGMath.hxx>
17#include <simgear/structure/SGSharedPtr.hxx>
18#include <simgear/structure/exception.hxx>
19
20// forward decls
21class SGPath;
23
25{
26private:
27 std::string name = "unnamed";
28 SGGeod pos;
29 double speed = 0.0;
30 double crossat = 0.0;
31 bool finished = false;
32 bool gear_down = true;
33 double flaps = 0.0;
34 double spoilers = 0.0;
35 double speedbrakes = 0.0;
36 bool on_ground;
37 int routeIndex; // For AI/ATC purposes;
38 double time_sec;
39 double trackLength = 0.0; // distance from previous FGAIWaypoint (for AI purposes);
40 std::string time;
41
42 bool beacon_light = false;
43 bool landing_light = false;
44 bool nav_light = false;
45 bool strobe_light = false;
46 bool taxi_light = false;
47 bool cabin_light = false;
48
49public:
51 virtual ~FGAIWaypoint(){};
52
53 void setName(const std::string& nam) { name = nam; };
54 void setLatitude(double lat);
55 void setLongitude(double lon);
56 void setAltitude(double alt);
57 void setPos(const SGGeod& aPos) { pos = aPos; }
58 void setSpeed(double spd) { speed = spd; };
59 void setCrossat(double val) { crossat = val; };
60 void setFinished(bool fin) { finished = fin; };
61 void setGear_down(bool grd) { gear_down = grd; };
62 void setFlaps(double val) { flaps = val; };
63 void setSpoilers(double val) { spoilers = val; };
64 void setSpeedBrakes(double val) { speedbrakes = val; };
65 void setOn_ground(bool grn) { on_ground = grn; };
66 void setRouteIndex(int rte) { routeIndex = rte; };
67 void setTime_sec(double ts) { time_sec = ts; };
68 void setTrackLength(double tl) { trackLength = tl; };
69 void setTime(const std::string& tme) { time = tme; };
70 void setLights(bool beacon, bool cabin, bool ldg, bool nav, bool strobe, bool taxi)
71 {
72 beacon_light = beacon;
73 cabin_light = cabin;
74 landing_light = ldg;
75 nav_light = nav;
76 strobe_light = strobe;
77 taxi_light = taxi;
78 };
79
80 // beacon cabin ldg nav strobe taxi
81 void setPowerDownLights() { setLights(false, true, false, false, false, false); };
82 void setGroundLights() { setLights(true, true, false, true, false, true); };
83 void setCruiseLights() { setLights(true, true, false, true, true, false); };
84 void setTakeOffLights() { setLights(true, false, true, true, true, false); };
85 void setApproachLights() { setLights(true, false, true, true, true, false); };
86 void setBeaconLight(bool beacon) { beacon_light = beacon; };
87 void setCabinLight(bool cabin) { cabin_light = cabin; };
88 void setLandingLight(bool ldg) { landing_light = ldg; };
89 void setNavLight(bool nav) { nav_light = nav; };
90 void setStrobeLight(bool strobe) { strobe_light = strobe; };
91 void setTaxiLight(bool taxi) { taxi_light = taxi; };
92
93 bool contains(const std::string& name);
94
95 const std::string& getName() { return name; };
96 const SGGeod& getPos() { return pos; };
97 double getLatitude() const;
98 double getLongitude() const;
99 double getAltitude() const;
100 double getSpeed() { return speed; };
101
102 double getCrossat() { return crossat; };
103 bool getGear_down() { return gear_down; };
104 double getFlaps() { return flaps; };
105 double getSpoilers() { return spoilers; };
106 double getSpeedBrakes() { return speedbrakes; };
107 bool getOn_ground() { return on_ground; };
108 bool getInAir() { return !on_ground; };
109 int getRouteIndex() { return routeIndex; };
110 bool isFinished() { return finished; };
111 double getTime_sec() { return time_sec; };
112 double getTrackLength() { return trackLength; };
113 const std::string& getTime() { return time; };
114 bool getBeaconLight() { return beacon_light; };
115 bool getCabinLight() { return cabin_light; };
116 bool getLandingLight() { return landing_light; };
117 bool getNavLight() { return nav_light; };
118 bool getStrobeLight() { return strobe_light; };
119 bool getTaxiLight() { return taxi_light; };
120};
121
122
124{
125public:
127 explicit FGAIFlightPlan(const std::string& filename);
129 const std::string& p,
130 double course,
131 time_t start,
132 time_t remainingTime,
133 FGAirport* dep,
134 FGAirport* arr,
135 bool firstLeg,
136 double radius,
137 double alt,
138 double lat,
139 double lon,
140 double speed,
141 const std::string& fltType,
142 const std::string& acType,
143 const std::string& airline);
144 virtual ~FGAIFlightPlan();
145
156 bool readFlightplan(const SGPath& file);
157
158 bool readFlightplan(std::istream& stream, const sg_location& loc = sg_location{});
159
161 FGAIWaypoint* getCurrentWaypoint(void) const;
162 FGAIWaypoint* getNextWaypoint(void) const;
163 int getNextTurnAngle(void) const;
164 void IncrementWaypoint(bool erase);
165 void DecrementWaypoint();
166
167 double getDistanceToGo(double lat, double lon, FGAIWaypoint* wp) const;
168 int getLeg() const { return leg; };
169
171 void setLeadDistance(double speed, double bearing, FGAIWaypoint* current, FGAIWaypoint* next);
173 void setLeadDistance(double distance_ft);
174 double getLeadDistance(void) const { return lead_distance_ft; }
175 double getBearing(FGAIWaypoint* previous, FGAIWaypoint* next) const;
176 double getBearing(const SGGeod& aPos, FGAIWaypoint* next) const;
177
178 double checkTrackLength(const std::string& wptName) const;
179 time_t getStartTime() const { return start_time; }
180 time_t getArrivalTime() const { return arrivalTime; }
181
182 bool create(FGAIAircraft*, FGAirport* dep, FGAirport* arr, int leg, double alt, double speed, double lat, double lon,
183 bool firstLeg, double radius, const std::string& fltType, const std::string& aircraftType, const std::string& airline, double distance);
184 bool createPushBack(FGAIAircraft*, bool, FGAirport*, double radius, const std::string&, const std::string&, const std::string&);
185 bool createTakeOff(FGAIAircraft*, bool, FGAirport*, const SGGeod& pos, double speed, const std::string& flightType);
186
187 void setLeg(int val)
188 {
189 SG_LOG(SG_AI, SG_BULK, "Set Leg " << leg);
190 leg = val;
191 }
192 void setTime(time_t st) { start_time = st; }
193
194 double getLeadInAngle() const { return leadInAngle; }
195 const std::string& getRunway() const;
196
197 void setRepeat(bool r) { repeat = r; }
198 bool getRepeat(void) const { return repeat; }
199 void restart(void);
200 int getNrOfWayPoints() { return waypoints.size(); }
201
202 int getRouteIndex(int i) const; // returns the AI related index of this current routes.
203
204 const std::string& getRunway() { return activeRunway; }
205 bool isActive(time_t time) { return time >= this->getStartTime(); }
206
208 {
209 SG_LOG(SG_AI, SG_BULK, "Increment Leg " << leg);
210 leg++;
211 };
212
213 void setRunway(const std::string& rwy) { activeRunway = rwy; };
214 const char* getRunwayClassFromTrafficType(const std::string& fltType);
215
216 void addWaypoint(FGAIWaypoint* wpt);
217
218 void setName(const std::string& n) { name = n; };
219 const std::string& getName() { return name; };
220
221 void setSID(FGAIFlightPlan* fp) { sid = fp; };
222 FGAIFlightPlan* getSID() { return sid; };
223 FGAIWaypoint* getWayPoint(int i) { return waypoints[i]; };
225
226 void shortenToFirst(unsigned int number, const std::string& name);
227
228 void setGate(const ParkingAssignment& pka);
229 FGParking* getParkingGate() const;
230
233
234 bool empty() const;
235
236private:
237 FGAIFlightPlan* sid;
238 typedef std::vector<FGAIWaypoint*> wpt_vector_type;
239 typedef wpt_vector_type::const_iterator wpt_vector_iterator;
240
241
242 wpt_vector_type waypoints;
243 wpt_vector_iterator wpt_iterator;
244
245 bool repeat;
246 double distance_to_go = 0;
247 //FIXME ft
248 double lead_distance_ft = 0;
249 double leadInAngle = 0;
250 double nextTurnAngle = 0;
251 time_t start_time;
252 time_t arrivalTime; // For AI/ATC purposes.
253 int leg = 0;
255 FGTaxiNodeRef lastNodeVisited;
256 std::string activeRunway;
257 std::string name;
258 bool isValid;
259 FGAirportRef departure, arrival;
260
261 time_t calcArrivalTimes() const;
262
263 void createPushBackFallBack(FGAIAircraft*, bool, FGAirport*, double radius, const std::string&, const std::string&, const std::string&);
264 bool createTakeoffTaxi(FGAIAircraft*, bool firstFlight, FGAirport* apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
265 bool createClimb(FGAIAircraft*, bool, FGAirport*, FGAirport* arrival, double, double, const std::string&);
266 bool createCruise(FGAIAircraft*, bool, FGAirport*, FGAirport*, const SGGeod& current, double, double, const std::string&);
267 bool createDescent(FGAIAircraft*, FGAirport*, const SGGeod& current, double speed, double alt, const std::string&, double distance);
268 bool createHold(FGAIAircraft*, FGAirport*, const SGGeod& current, double speed, double alt, const std::string&, double distance);
269 bool createLanding(FGAIAircraft*, FGAirport*, const std::string&);
270 bool createLandingTaxi(FGAIAircraft*, FGAirport* apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
271 void createDefaultLandingTaxi(FGAIAircraft*, FGAirport* aAirport);
272 void createDefaultTakeoffTaxi(FGAIAircraft*, FGAirport* aAirport, FGRunway* aRunway);
273 bool createParking(FGAIAircraft*, FGAirport*, double radius);
274 void deleteWaypoints();
275 void resetWaypoints();
276 void eraseLastWaypoint();
277 void pushBackWaypoint(FGAIWaypoint* wpt);
278
280 void createArc(FGAIAircraft* ac, const SGGeod& center, int startAngle, int endAngle, int increment, int radius, double aElev, double altDiff, double aSpeed, const char* pattern);
282 void createLine(FGAIAircraft* ac, const SGGeod& startPoint, double azimuth, double dist, double aElev, double dAlt, double vDescent, const char* pattern);
283
284 double getTurnRadius(double, bool);
285
286 FGAIWaypoint* createOnGround(FGAIAircraft*, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
287 FGAIWaypoint* createOnRunway(FGAIAircraft*, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
288 FGAIWaypoint* createInAir(FGAIAircraft*, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
289 FGAIWaypoint* cloneWithPos(FGAIAircraft*, FGAIWaypoint* aWpt, const std::string& aName, const SGGeod& aPos);
290 FGAIWaypoint* clone(FGAIWaypoint* aWpt);
291
292
293 //void createCruiseFallback(bool, FGAirport*, FGAirport*, double, double, double, double);
294 void evaluateRoutePart(double deplat, double deplon, double arrlat, double arrlon);
295
300 bool parseProperties(const std::string& filename);
301
305
306 void createWaypoints(FGAIAircraft* ac,
307 double course,
308 time_t start,
309 time_t remainingTime,
310 FGAirport* dep,
311 FGAirport* arr,
312 bool firstLeg,
313 double radius,
314 double alt,
315 double lat,
316 double lon,
317 double speed,
318 const std::string& fltType,
319 const std::string& acType,
320 const std::string& airline);
321
322public:
323 wpt_vector_iterator getFirstWayPoint() { return waypoints.begin(); };
324 wpt_vector_iterator getLastWayPoint() { return waypoints.end(); };
325 bool isValidPlan() { return isValid; };
326};
#define p(x)
#define i(x)
SGSharedPtr< FGTaxiNode > FGTaxiNodeRef
SGSharedPtr< FGAirport > FGAirportRef
void setGate(const ParkingAssignment &pka)
void IncrementWaypoint(bool erase)
const char * getRunwayClassFromTrafficType(const std::string &fltType)
const std::string & getRunway() const
FGAIWaypoint * getWayPoint(int i)
void setLeadDistance(double speed, double bearing, FGAIWaypoint *current, FGAIWaypoint *next)
Set lead_distance_ft.
double getLeadInAngle() const
void setRepeat(bool r)
void setTime(time_t st)
int getRouteIndex(int i) const
FGAIWaypoint * getNextWaypoint(void) const
FGParking * getParkingGate() const
bool createTakeOff(FGAIAircraft *, bool, FGAirport *, const SGGeod &pos, double speed, const std::string &flightType)
FGAirportRef departureAirport() const
double getDistanceToGo(double lat, double lon, FGAIWaypoint *wp) const
static FGAIFlightPlan * createDummyUserPlan()
create a nearly empty FlightPlan for the user aircraft, based on the current position and route-manag...
FGAIFlightPlan * getSID()
void setRunway(const std::string &rwy)
FGAirportRef arrivalAirport() const
double checkTrackLength(const std::string &wptName) const
void shortenToFirst(unsigned int number, const std::string &name)
bool readFlightplan(const SGPath &file)
read a flight-plan from a file.
void setName(const std::string &n)
virtual ~FGAIFlightPlan()
void setSID(FGAIFlightPlan *fp)
bool create(FGAIAircraft *, FGAirport *dep, FGAirport *arr, int leg, double alt, double speed, double lat, double lon, bool firstLeg, double radius, const std::string &fltType, const std::string &aircraftType, const std::string &airline, double distance)
time_t getArrivalTime() const
bool getRepeat(void) const
bool empty() const
time_t getStartTime() const
const std::string & getName()
wpt_vector_iterator getFirstWayPoint()
int getNextTurnAngle(void) const
wpt_vector_iterator getLastWayPoint()
FGAIFlightPlan(FGAIAircraft *, const std::string &p, double course, time_t start, time_t remainingTime, FGAirport *dep, FGAirport *arr, bool firstLeg, double radius, double alt, double lat, double lon, double speed, const std::string &fltType, const std::string &acType, const std::string &airline)
void setLeg(int val)
bool isActive(time_t time)
double getLeadDistance(void) const
int getLeg() const
void restart(void)
FGAIWaypoint * getPreviousWaypoint(void) const
FGAIWaypoint * getCurrentWaypoint(void) const
FGAIWaypoint * getLastWaypoint() const
bool createPushBack(FGAIAircraft *, bool, FGAirport *, double radius, const std::string &, const std::string &, const std::string &)
FGAIFlightPlan(const std::string &filename)
void addWaypoint(FGAIWaypoint *wpt)
const std::string & getRunway()
double getBearing(FGAIWaypoint *previous, FGAIWaypoint *next) const
double getSpeedBrakes()
void setApproachLights()
void setGear_down(bool grd)
void setAltitude(double alt)
double getSpeed()
void setCrossat(double val)
bool contains(const std::string &name)
void setTakeOffLights()
void setName(const std::string &nam)
double getLatitude() const
void setStrobeLight(bool strobe)
void setOn_ground(bool grn)
double getCrossat()
void setTrackLength(double tl)
const std::string & getName()
void setSpoilers(double val)
double getFlaps()
void setTime_sec(double ts)
void setFinished(bool fin)
void setLongitude(double lon)
void setTime(const std::string &tme)
void setLatitude(double lat)
const std::string & getTime()
void setSpeed(double spd)
void setCruiseLights()
void setBeaconLight(bool beacon)
bool getLandingLight()
bool getStrobeLight()
void setLandingLight(bool ldg)
double getTrackLength()
double getSpoilers()
void setPos(const SGGeod &aPos)
bool getBeaconLight()
void setPowerDownLights()
double getLongitude() const
virtual ~FGAIWaypoint()
void setFlaps(double val)
void setTaxiLight(bool taxi)
double getTime_sec()
void setGroundLights()
void setCabinLight(bool cabin)
double getAltitude() const
void setSpeedBrakes(double val)
void setLights(bool beacon, bool cabin, bool ldg, bool nav, bool strobe, bool taxi)
const SGGeod & getPos()
void setNavLight(bool nav)
void setRouteIndex(int rte)
const char * name