Debian Codegraph @

src/AIModel/AIFlightPlan.hxx

raw symbols SCIP
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 - [email protected]
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>
14 #include <Navaids/positioned.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
21 class SGPath;
22
23 class FGAIWaypoint
24 {
25 private:
26 std::string name = "unnamed";
27 SGGeod pos;
28 double speed = 0.0;
29 double crossat = 0.0;
30 bool finished = false;
31 bool gear_down = true;
32 double flaps = 0.0;
33 double spoilers = 0.0;
34 double speedbrakes = 0.0;
35 bool on_ground;
36 int routeIndex; // For AI/ATC purposes;
37 double time_sec;
38 double trackLength = 0.0; // distance from previous FGAIWaypoint (for AI purposes);
39 std::string time;
40
41 bool beacon_light = false;
42 bool landing_light = false;
43 bool nav_light = false;
44 bool strobe_light = false;
45 bool taxi_light = false;
46 bool cabin_light = false;
47
48 public:
49 FGAIWaypoint();
50 virtual ~FGAIWaypoint(){};
51
52 void setName(const std::string& nam) { name = nam; };
53 void setLatitude(double lat);
54 void setLongitude(double lon);
55 void setAltitude(double alt);
56 void setPos(const SGGeod& aPos) { pos = aPos; }
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(double val) { flaps = val; };
62 void setSpoilers(double val) { spoilers = val; };
63 void setSpeedBrakes(double val) { speedbrakes = val; };
64 void setOn_ground(bool grn) { on_ground = grn; };
65 void setRouteIndex(int rte) { routeIndex = rte; };
66 void setTime_sec(double ts) { time_sec = ts; };
67 void setTrackLength(double tl) { trackLength = tl; };
68 void setTime(const std::string& tme) { time = tme; };
69 void setLights(bool beacon, bool cabin, bool ldg, bool nav, bool strobe, bool taxi)
70 {
71 beacon_light = beacon;
72 cabin_light = cabin;
73 landing_light = ldg;
74 nav_light = nav;
75 strobe_light = strobe;
76 taxi_light = taxi;
77 };
78
79 // beacon cabin ldg nav strobe taxi
80 void setPowerDownLights() { setLights(false, true, false, false, false, false); };
81 void setGroundLights() { setLights(true, true, false, true, false, true); };
82 void setCruiseLights() { setLights(true, true, false, true, true, false); };
83 void setTakeOffLights() { setLights(true, false, true, true, true, false); };
84 void setApproachLights() { setLights(true, false, true, true, true, false); };
85 void setBeaconLight(bool beacon) { beacon_light = beacon; };
86 void setCabinLight(bool cabin) { cabin_light = cabin; };
87 void setLandingLight(bool ldg) { landing_light = ldg; };
88 void setNavLight(bool nav) { nav_light = nav; };
89 void setStrobeLight(bool strobe) { strobe_light = strobe; };
90 void setTaxiLight(bool taxi) { taxi_light = taxi; };
91
92 bool contains(const std::string& name);
93
94 const std::string& getName() { return name; };
95 const SGGeod& getPos() { return pos; };
96 double getLatitude() const;
97 double getLongitude() const;
98 double getAltitude() const;
99 double getSpeed() { return speed; };
100
101 double getCrossat() { return crossat; };
102 bool getGear_down() { return gear_down; };
103 double getFlaps() { return flaps; };
104 double getSpoilers() { return spoilers; };
105 double getSpeedBrakes() { return speedbrakes; };
106 bool getOn_ground() { return on_ground; };
107 bool getInAir() { return !on_ground; };
108 int getRouteIndex() { return routeIndex; };
109 bool isFinished() { return finished; };
110 double getTime_sec() { return time_sec; };
111 double getTrackLength() { return trackLength; };
112 const std::string& getTime() { return time; };
113 bool getBeaconLight() { return beacon_light; };
114 bool getCabinLight() { return cabin_light; };
115 bool getLandingLight() { return landing_light; };
116 bool getNavLight() { return nav_light; };
117 bool getStrobeLight() { return strobe_light; };
118 bool getTaxiLight() { return taxi_light; };
119 };
120
121
122 class FGAIFlightPlan
123 {
124 public:
125 FGAIFlightPlan();
126 explicit FGAIFlightPlan(const std::string& filename);
127 FGAIFlightPlan(FGAIAircraft*,
128 const std::string& p,
129 double course,
130 time_t start,
131 time_t remainingTime,
132 FGAirport* dep,
133 FGAirport* arr,
134 bool firstLeg,
135 double radius,
136 double alt,
137 double lat,
138 double lon,
139 double speed,
140 const std::string& fltType,
141 const std::string& acType,
142 const std::string& airline);
143 virtual ~FGAIFlightPlan();
144
145 /**
146 @brief create a nearly empty FlightPlan for the user aircraft, based
147 on the current position and route-manager data.
148 */
149 static FGAIFlightPlan* createDummyUserPlan();
150 /**
151
152 @brief read a flight-plan from a file.
153 All current contents of the flight-plan are replaced, and the current waypoint is reset to the beginning
154 */
155 bool readFlightplan(const SGPath& file);
156
157 bool readFlightplan(std::istream& stream, const sg_location& loc = sg_location{});
158
159 FGAIWaypoint* getPreviousWaypoint(void) const;
160 FGAIWaypoint* getCurrentWaypoint(void) const;
161 FGAIWaypoint* getNextWaypoint(void) const;
162 int getNextTurnAngle(void) const;
163 void IncrementWaypoint(bool erase);
164 void DecrementWaypoint();
165
166 double getDistanceToGo(double lat, double lon, FGAIWaypoint* wp) const;
167 int getLeg() const { return leg; };
168
169 /** Set lead_distance_ft*/
170 void setLeadDistance(double speed, double bearing, FGAIWaypoint* current, FGAIWaypoint* next);
171 /** Set lead_distance_ft*/
172 void setLeadDistance(double distance_ft);
173 double getLeadDistance(void) const { return lead_distance_ft; }
174 double getBearing(FGAIWaypoint* previous, FGAIWaypoint* next) const;
175 double getBearing(const SGGeod& aPos, FGAIWaypoint* next) const;
176
177 double checkTrackLength(const std::string& wptName) const;
178 time_t getStartTime() const { return start_time; }
179 time_t getArrivalTime() const { return arrivalTime; }
180
181 bool create(FGAIAircraft*, FGAirport* dep, FGAirport* arr, int leg, double alt, double speed, double lat, double lon,
182 bool firstLeg, double radius, const std::string& fltType, const std::string& aircraftType, const std::string& airline, double distance);
183 bool createPushBack(FGAIAircraft*, bool, FGAirport*, double radius, const std::string&, const std::string&, const std::string&);
184 bool createTakeOff(FGAIAircraft*, bool, FGAirport*, const SGGeod& pos, double speed, const std::string& flightType);
185
186 void setLeg(int val)
187 {
188 SG_LOG(SG_AI, SG_BULK, "Set Leg " << leg);
189 leg = val;
190 }
191 void setTime(time_t st) { start_time = st; }
192
193 double getLeadInAngle() const { return leadInAngle; }
194 const std::string& getRunway() const;
195
196 void setRepeat(bool r) { repeat = r; }
197 bool getRepeat(void) const { return repeat; }
198 void restart(void);
199 int getNrOfWayPoints() { return waypoints.size(); }
200
201 int getRouteIndex(int i) const; // returns the AI related index of this current routes.
202
203 const std::string& getRunway() { return activeRunway; }
204 bool isActive(time_t time) { return time >= this->getStartTime(); }
205
206 void incrementLeg()
207 {
208 SG_LOG(SG_AI, SG_BULK, "Increment Leg " << leg);
209 leg++;
210 };
211
212 void setRunway(const std::string& rwy) { activeRunway = rwy; };
213 const char* getRunwayClassFromTrafficType(const std::string& fltType);
214
215 void addWaypoint(FGAIWaypoint* wpt);
216
217 void setName(const std::string& n) { name = n; };
218 const std::string& getName() { return name; };
219
220 void setSID(FGAIFlightPlan* fp) { sid = fp; };
221 FGAIFlightPlan* getSID() { return sid; };
222 FGAIWaypoint* getWayPoint(int i) { return waypoints[i]; };
223 FGAIWaypoint* getLastWaypoint() const;
224
225 void shortenToFirst(unsigned int number, const std::string& name);
226
227 void setGate(const ParkingAssignment& pka);
228 FGParking* getParkingGate() const;
229
230 FGAirportRef departureAirport() const;
231 FGAirportRef arrivalAirport() const;
232
233 bool empty() const;
234
235 private:
236 FGAIFlightPlan* sid;
237 typedef std::vector<FGAIWaypoint*> wpt_vector_type;
238 typedef wpt_vector_type::const_iterator wpt_vector_iterator;
239
240
241 wpt_vector_type waypoints;
242 wpt_vector_iterator wpt_iterator;
243
244 bool repeat;
245 double distance_to_go = 0;
246 //FIXME ft
247 double lead_distance_ft = 0;
248 double leadInAngle = 0;
249 double nextTurnAngle = 0;
250 time_t start_time;
251 time_t arrivalTime; // For AI/ATC purposes.
252 int leg = 0;
253 ParkingAssignment gate;
254 FGTaxiNodeRef lastNodeVisited;
255 std::string activeRunway;
256 std::string name;
257 bool isValid;
258 FGAirportRef departure, arrival;
259
260 void createPushBackFallBack(FGAIAircraft*, bool, FGAirport*, double radius, const std::string&, const std::string&, const std::string&);
261 bool createClimb(FGAIAircraft*, bool, FGAirport*, FGAirport* arrival, double, double, const std::string&);
262 bool createCruise(FGAIAircraft*, bool, FGAirport*, FGAirport*, const SGGeod& current, double, double, const std::string&);
263 bool createDescent(FGAIAircraft*, FGAirport*, const SGGeod& current, double speed, double alt, const std::string&, double distance);
264 bool createHold(FGAIAircraft*, FGAirport*, const SGGeod& current, double speed, double alt, const std::string&, double distance);
265 bool createLanding(FGAIAircraft*, FGAirport*, const std::string&);
266 bool createParking(FGAIAircraft*, FGAirport*, double radius);
267 void deleteWaypoints();
268 void resetWaypoints();
269 void eraseLastWaypoint();
270 void pushBackWaypoint(FGAIWaypoint* wpt);
271
272 /**Create an arc flightplan around a center from startAngle to endAngle.*/
273 void createArc(FGAIAircraft* ac, const SGGeod& center, int startAngle, int endAngle, int increment, int radius, double aElev, double altDiff, double aSpeed, const char* pattern);
274 /**Create a line flightplan from start with dist and altitude diff*/
275 void createLine(FGAIAircraft* ac, const SGGeod& startPoint, double azimuth, double dist, double aElev, double dAlt, double vDescent, const char* pattern);
276 bool createLandingTaxi(FGAIAircraft*, FGAirport* apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
277 void createDefaultLandingTaxi(FGAIAircraft*, FGAirport* aAirport);
278 void createDefaultTakeoffTaxi(FGAIAircraft*, FGAirport* aAirport, FGRunway* aRunway);
279 bool createTakeoffTaxi(FGAIAircraft*, bool firstFlight, FGAirport* apt, double radius, const std::string& fltType, const std::string& acType, const std::string& airline);
280
281 double getTurnRadius(double, bool);
282
283 FGAIWaypoint* createOnGround(FGAIAircraft*, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
284 FGAIWaypoint* createOnRunway(FGAIAircraft*, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
285 FGAIWaypoint* createInAir(FGAIAircraft*, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
286 FGAIWaypoint* cloneWithPos(FGAIAircraft*, FGAIWaypoint* aWpt, const std::string& aName, const SGGeod& aPos);
287 FGAIWaypoint* clone(FGAIWaypoint* aWpt);
288
289
290 //void createCruiseFallback(bool, FGAirport*, FGAirport*, double, double, double, double);
291 void evaluateRoutePart(double deplat, double deplon, double arrlat, double arrlon);
292
293 /**
294 * look for and parse an PropertyList flight-plan file - essentially
295 * a flat list waypoint objects, encoded to properties
296 */
297 bool parseProperties(const std::string& filename);
298
299 /**
300 * Creates the waypoints for this Flightplan.
301 */
302
303 void createWaypoints(FGAIAircraft* ac,
304 double course,
305 time_t start,
306 time_t remainingTime,
307 FGAirport* dep,
308 FGAirport* arr,
309 bool firstLeg,
310 double radius,
311 double alt,
312 double lat,
313 double lon,
314 double speed,
315 const std::string& fltType,
316 const std::string& acType,
317 const std::string& airline);
318
319 public:
320 wpt_vector_iterator getFirstWayPoint() { return waypoints.begin(); };
321 wpt_vector_iterator getLastWayPoint() { return waypoints.end(); };
322 bool isValidPlan() { return isValid; };
323 };