~jtaylor/ubuntu/oneiric/flightgear/fix-749249

« back to all changes in this revision

Viewing changes to src/AIModel/AIFlightPlanCreate.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Ove Kaaven
  • Date: 2006-05-17 17:12:09 UTC
  • mfrom: (1.1.5 upstream) (3.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060517171209-9qbwm4q1uj05vhcj
Tags: 0.9.10-2
Updated the build dependencies for xorg 7.0. Apparently the
amd64 autobuilder doesn't use Provides.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 *
15
15
 * You should have received a copy of the GNU General Public License
16
16
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
 
 *
 
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
18
 *
20
19
 **************************************************************************/
21
20
#include "AIFlightPlan.hxx"
30
29
 * dynamically create a flight plan for AI traffic, based on data provided by the
31
30
 * Traffic Manager, when reading a filed flightplan failes. (DT, 2004/07/10) 
32
31
 *
33
 
 * This is the top-level function, and the only one that publicly available.
 
32
 * This is the top-level function, and the only one that is publicly available.
34
33
 *
35
34
 */ 
36
35
 
37
36
 
38
37
// Check lat/lon values during initialization;
39
 
void FGAIFlightPlan::create(FGAirport *dep, FGAirport *arr, int legNr, double alt, double speed, 
40
 
                            double latitude, double longitude, bool firstFlight,
41
 
                            double radius, const string& fltType, const string& aircraftType, const string& airline)
 
38
void FGAIFlightPlan::create(FGAirport *dep, FGAirport *arr, int legNr, 
 
39
                            double alt, double speed, double latitude, 
 
40
                            double longitude, bool firstFlight,double radius, 
 
41
                            const string& fltType, const string& aircraftType, 
 
42
                            const string& airline)
42
43
43
44
  int currWpt = wpt_iterator - waypoints.begin();
44
45
  switch(legNr)
45
46
    {
46
47
    case 1:
47
 
      //cerr << "Creating Push_Back" << endl;
48
 
      createPushBack(firstFlight,dep, latitude, longitude, radius, fltType, aircraftType, airline);
49
 
      //cerr << "Done" << endl;
 
48
      createPushBack(firstFlight,dep, latitude, longitude, 
 
49
                     radius, fltType, aircraftType, airline);
50
50
      break;
51
51
    case 2: 
52
 
      //cerr << "Creating Taxi" << endl;
53
 
      createTaxi(firstFlight, 1, dep, latitude, longitude, radius, fltType, aircraftType, airline);
 
52
      createTaxi(firstFlight, 1, dep, latitude, longitude, 
 
53
                 radius, fltType, aircraftType, airline);
54
54
      break;
55
55
    case 3: 
56
 
      //cerr << "Creating TAkeoff" << endl;
57
56
      createTakeOff(firstFlight, dep, speed);
58
57
      break;
59
58
    case 4: 
60
 
      //cerr << "Creating Climb" << endl;
61
59
      createClimb(firstFlight, dep, speed, alt);
62
60
      break;
63
61
    case 5: 
64
 
      //cerr << "Creating Cruise" << endl;
65
62
      createCruise(firstFlight, dep,arr, latitude, longitude, speed, alt);
66
63
      break;
67
64
    case 6: 
68
 
      //cerr << "Creating Decent" << endl;
69
65
      createDecent(arr);
70
66
      break;
71
67
    case 7: 
72
 
      //cerr << "Creating Landing" << endl;
73
68
      createLanding(arr);
74
69
      break;
75
70
    case 8: 
76
 
      //cerr << "Creating Taxi 2" << endl;
77
 
      createTaxi(false, 2, arr, latitude, longitude, radius, fltType, aircraftType, airline);
 
71
      createTaxi(false, 2, arr, latitude, longitude, radius, 
 
72
                 fltType, aircraftType, airline);
78
73
      break;
79
 
    case 9: 
80
 
      //cerr << "Creating Parking" << endl;
81
 
      createParking(arr);
 
74
      case 9: 
 
75
        createParking(arr, radius);
82
76
      break;
83
77
    default:
84
78
      //exit(1);
85
 
      cerr << "Unknown case: " << legNr << endl;
 
79
      SG_LOG(SG_INPUT, SG_ALERT, "AIFlightPlan::create() attempting to create unknown leg"
 
80
             " this is probably an internal program error");
86
81
    }
87
82
  wpt_iterator = waypoints.begin()+currWpt;
88
83
  leg++;
93
88
 * initialize the Aircraft at the parking location
94
89
 ******************************************************************/
95
90
void FGAIFlightPlan::createPushBack(bool firstFlight, FGAirport *dep, 
96
 
                                    double latitude,
97
 
                                    double longitude,
98
 
                                    double radius,
99
 
                                    const string& fltType,
100
 
                                    const string& aircraftType,
101
 
                                    const string& airline)
 
91
                                    double latitude,
 
92
                                    double longitude,
 
93
                                    double radius,
 
94
                                    const string& fltType,
 
95
                                    const string& aircraftType,
 
96
                                    const string& airline)
102
97
{
103
98
  double heading;
104
99
  double lat;
115
110
  // Otherwise use the current aircraft position.
116
111
  if (firstFlight)
117
112
    {
118
 
      if (!(dep->getAvailableParking(&lat, &lon, &heading, &gateId, radius, fltType, aircraftType, airline)))
119
 
        {
120
 
          cerr << "Could not find parking " << endl;
121
 
        }
 
113
      if (!(dep->getDynamics()->getAvailableParking(&lat, &lon, 
 
114
                                                    &heading, &gateId, 
 
115
                                                    radius, fltType, 
 
116
                                                    aircraftType, airline)))
 
117
        {
 
118
          SG_LOG(SG_INPUT, SG_WARN, "Could not find parking for a " << 
 
119
                 aircraftType <<
 
120
                 " of flight type " << fltType << 
 
121
                 " of airline     " << airline <<
 
122
                 " at airport     " << dep->getId());
 
123
        }
122
124
    }
123
125
  else
124
126
    {
125
 
      dep->getParking(gateId, &lat, &lon, &heading);
126
 
      //lat     = latitude;
127
 
      //lon     = longitude;
128
 
      //heading = getHeading();
 
127
      dep->getDynamics()->getParking(gateId, &lat, &lon, &heading);
129
128
    }
130
129
  heading += 180.0;
131
130
  if (heading > 360)
146
145
  // Add park twice, because it uses park once for initialization and once
147
146
  // to trigger the departure ATC message 
148
147
  geo_direct_wgs_84 ( 0, lat, lon, heading, 
149
 
                      10, 
150
 
                      &lat2, &lon2, &az2 );
 
148
                      10, 
 
149
                      &lat2, &lon2, &az2 );
151
150
  wpt = new waypoint;
152
151
  wpt->name      = "park2";
153
152
  wpt->latitude  = lat2;
161
160
  wpt->on_ground = true;
162
161
  waypoints.push_back(wpt); 
163
162
  geo_direct_wgs_84 ( 0, lat, lon, heading, 
164
 
                      radius,                 // push back one entire aircraft radius
165
 
                      &lat2, &lon2, &az2 );
 
163
                      2.2*radius,           
 
164
                      &lat2, &lon2, &az2 );
166
165
  wpt = new waypoint;
167
166
  wpt->name      = "taxiStart";
168
167
  wpt->latitude  = lat2;
174
173
  wpt->flaps_down= true;
175
174
  wpt->finished  = false;
176
175
  wpt->on_ground = true;
177
 
  waypoints.push_back(wpt); 
178
 
 
179
 
  
 
176
  waypoints.push_back(wpt);  
180
177
}
181
178
 
182
179
/*******************************************************************
183
180
 * createCreate Taxi. 
184
181
 * initialize the Aircraft at the parking location
185
182
 ******************************************************************/
186
 
void FGAIFlightPlan::createTaxi(bool firstFlight, int direction, FGAirport *apt, double latitude, double longitude, double radius, const string& fltType, const string& acType, const string& airline)
 
183
void FGAIFlightPlan::createTaxi(bool firstFlight, int direction, 
 
184
                                FGAirport *apt, double latitude, double longitude, 
 
185
                                double radius, const string& fltType, 
 
186
                                const string& acType, const string& airline)
187
187
{
188
188
  double wind_speed;
189
189
  double wind_heading;
190
190
  double heading;
191
 
  //FGRunway rwy;
192
191
  double lat, lon, az;
193
192
  double lat2, lon2, az2;
194
 
  //int direction;
195
193
  waypoint *wpt;
196
194
 
197
 
  // Erase all existing waypoints.
198
 
  //   wpt_vector_iterator i= waypoints.begin();
199
 
  //resetWaypoints();
200
 
  //int currWpt = wpt_iterator - waypoints.begin();
201
 
  if (direction == 1)
 
195
   if (direction == 1)
202
196
    {
203
 
      //string name;
 
197
      // If this function is called during initialization,
 
198
      // make sure we obtain a valid gate ID first
 
199
      // and place the model at the location of the gate.
 
200
      if (firstFlight)
 
201
        {
 
202
          if (!(apt->getDynamics()->getAvailableParking(&lat, &lon, 
 
203
                                                        &heading, &gateId, 
 
204
                                                        radius, fltType, 
 
205
                                                        acType, airline)))
 
206
            {
 
207
              SG_LOG(SG_INPUT, SG_WARN, "Could not find parking for a " << 
 
208
                     acType <<
 
209
                     " of flight type " << fltType <<
 
210
                     " of airline     " << airline <<
 
211
                     " at airport     " << apt->getId());
 
212
            }
 
213
          //waypoint *wpt = new waypoint;
 
214
          //wpt->name      = "park";
 
215
          //wpt->latitude  = lat;
 
216
          //wpt->longitude = lon;
 
217
          //wpt->altitude  = apt->getElevation();
 
218
          //wpt->speed     = -10; 
 
219
          //wpt->crossat   = -10000;
 
220
          //wpt->gear_down = true;
 
221
          //wpt->flaps_down= true;
 
222
          //wpt->finished  = false;
 
223
          //wpt->on_ground = true;
 
224
          //waypoints.push_back(wpt);  
 
225
        }
204
226
      // "NOTE: this is currently fixed to "com" for commercial traffic
205
227
      // Should be changed to be used dynamically to allow "gen" and "mil"
206
228
      // as well
207
 
      apt->getActiveRunway("com", 1, activeRunway);
 
229
      apt->getDynamics()->getActiveRunway("com", 1, activeRunway);
208
230
      if (!(globals->get_runways()->search(apt->getId(), 
209
231
                                            activeRunway, 
210
232
                                            &rwy)))
211
233
        {
212
 
          cout << "Failed to find runway for " << apt->getId() << endl;
213
 
          // Hmm, how do we handle a potential error like this?
214
 
          exit(1);
215
 
        }
216
 
      //string test;
217
 
      //apt->getActiveRunway(string("com"), 1, test);
218
 
      //exit(1);
219
 
      
 
234
           SG_LOG(SG_INPUT, SG_ALERT, "Failed to find runway " << 
 
235
                  activeRunway << 
 
236
                  " at airport     " << apt->getId());
 
237
           exit(1);
 
238
        } 
 
239
 
 
240
      // Determine the beginning of he runway
220
241
      heading = rwy._heading;
221
242
      double azimuth = heading + 180.0;
222
243
      while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
223
244
      geo_direct_wgs_84 ( 0, rwy._lat, rwy._lon, azimuth, 
224
245
                          rwy._length * SG_FEET_TO_METER * 0.5 - 5.0,
225
246
                          &lat2, &lon2, &az2 );
226
 
      if (apt->getGroundNetwork()->exists())
 
247
 
 
248
      if (apt->getDynamics()->getGroundNetwork()->exists())
227
249
        {
228
250
          intVec ids;
229
 
          int runwayId = apt->getGroundNetwork()->findNearestNode(lat2, lon2);
230
 
          //int currId   = apt->getGroundNetwork()->findNearestNode(latitude,longitude);
231
 
          //exit(1);
 
251
          int runwayId = apt->getDynamics()->getGroundNetwork()->findNearestNode(lat2, 
 
252
                                                                                 lon2);
 
253
 
232
254
          
233
255
          // A negative gateId indicates an overflow parking, use a
234
256
          // fallback mechanism for this. 
235
 
          // Starting from gate 0 is a bit of a hack...
 
257
          // Starting from gate 0 in this case is a bit of a hack
 
258
          // which requires a more proper solution later on.
236
259
          FGTaxiRoute route;
237
260
          if (gateId >= 0)
238
 
            route = apt->getGroundNetwork()->findShortestRoute(gateId, runwayId);
 
261
            route = apt->getDynamics()->getGroundNetwork()->findShortestRoute(gateId, 
 
262
                                                                              runwayId);
239
263
          else
240
 
            route = apt->getGroundNetwork()->findShortestRoute(0, runwayId);
 
264
            route = apt->getDynamics()->getGroundNetwork()->findShortestRoute(0, runwayId);
241
265
          intVecIterator i;
242
 
          //cerr << "creating route : ";
243
 
          // No route found: go from gate directly to runway
 
266
         
244
267
          if (route.empty()) {
245
268
            //Add the runway startpoint;
246
269
            wpt = new waypoint;
272
295
          } else {
273
296
            int node;
274
297
            route.first();
 
298
            bool isPushBackPoint = false;
 
299
            if (firstFlight) {
 
300
              // If this is called during initialization, randomly
 
301
              // skip a number of waypoints to get a more realistic
 
302
              // taxi situation.
 
303
              isPushBackPoint = true;
 
304
              int nrWaypoints = route.size();
 
305
              int nrWaypointsToSkip = rand() % nrWaypoints;
 
306
              // but make sure we always keep two active waypoints
 
307
              // to prevent a segmentation fault
 
308
              for (int i = 0; i < nrWaypointsToSkip-2; i++) {
 
309
                isPushBackPoint = false;
 
310
                route.next(&node);
 
311
              }
 
312
            }
 
313
            else {
 
314
              //chop off the first two waypoints, because
 
315
              // those have already been created
 
316
              // by create pushback
 
317
              int size = route.size();
 
318
              if (size > 2) {
 
319
                route.next(&node);
 
320
                route.next(&node);
 
321
              }
 
322
            }
275
323
            while(route.next(&node))
276
324
              {
277
 
                //i = ids.end()-1;
278
 
                //cerr << "Creating Node: " << node << endl;
279
 
                FGTaxiNode *tn = apt->getGroundNetwork()->findNode(node);
 
325
                FGTaxiNode *tn = apt->getDynamics()->getGroundNetwork()->findNode(node);
280
326
                //ids.pop_back();  
281
327
                wpt = new waypoint;
282
328
                wpt->name      = "taxiway"; // fixme: should be the name of the taxiway
283
329
                wpt->latitude  = tn->getLatitude();
284
330
                wpt->longitude = tn->getLongitude();
285
 
                wpt->altitude  = apt->getElevation(); // should maybe be tn->elev too
286
 
                wpt->speed     = 15; 
 
331
                // Elevation is currently disregarded when on_ground is true
 
332
                // because the AIModel obtains a periodic ground elevation estimate.
 
333
                wpt->altitude  = apt->getElevation();
 
334
                if (isPushBackPoint) {
 
335
                  wpt->speed = -10;
 
336
                  isPushBackPoint = false;
 
337
                }
 
338
                else {
 
339
                  wpt->speed     = 15; 
 
340
                }
287
341
                wpt->crossat   = -10000;
288
342
                wpt->gear_down = true;
289
343
                wpt->flaps_down= true;
293
347
              }
294
348
            cerr << endl;
295
349
          }
296
 
          //exit(1);
297
350
        }
298
351
      else 
299
352
        {
 
353
          // This is the fallback mechanism, in case no ground network is available
300
354
          //Add the runway startpoint;
301
355
          wpt = new waypoint;
302
356
          wpt->name      = "Airport Center";
324
378
          wpt->finished  = false;
325
379
          wpt->on_ground = true;
326
380
          waypoints.push_back(wpt);
327
 
          //wpt = new waypoint;
328
 
          //wpt->finished = false;
329
 
          //waypoints.push_back(wpt);  // add one more to prevent a segfault. 
330
381
        }
331
382
    }
332
383
  else  // Landing taxi
333
384
    {
334
 
      //string name;
335
 
      // "NOTE: this is currently fixed to "com" for commercial traffic
336
 
      // Should be changed to be used dynamically to allow "gen" and "mil"
337
 
      // as well
338
 
      //apt->getActiveRunway("com", 1, name);
339
 
      //if (!(globals->get_runways()->search(apt->getId(), 
340
 
      //                                    name, 
341
 
      //                            &rwy)))
342
 
      //{//
343
 
      //cout << "Failed to find runway for " << apt->getId() << endl;
344
 
      // Hmm, how do we handle a potential error like this?
345
 
      // exit(1);
346
 
      //        }
347
 
      //string test;
348
 
      //apt->getActiveRunway(string("com"), 1, test);
349
 
      //exit(1);
350
 
      
351
 
      //heading = rwy._heading;
352
 
      //double azimuth = heading + 180.0;
353
 
      //while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
354
 
      //geo_direct_wgs_84 ( 0, rwy._lat, rwy._lon, azimuth, 
355
 
      //                  rwy._length * SG_FEET_TO_METER * 0.5 - 5.0,
356
 
      //                  &lat2, &lon2, &az2 );
357
 
      apt->getAvailableParking(&lat, &lon, &heading, &gateId, radius, fltType, acType, airline);
358
 
      heading += 180.0;
359
 
      if (heading > 360)
360
 
        heading -= 360;
361
 
      geo_direct_wgs_84 ( 0, lat, lon, heading, 
362
 
                          100,
363
 
                          &lat2, &lon2, &az2 );
 
385
      apt->getDynamics()->getAvailableParking(&lat, &lon, &heading, 
 
386
                                              &gateId, radius, fltType, 
 
387
                                              acType, airline);
 
388
     
364
389
      double lat3 = (*(waypoints.end()-1))->latitude;
365
390
      double lon3 = (*(waypoints.end()-1))->longitude;
366
 
      cerr << (*(waypoints.end()-1))->name << endl;
367
 
      if (apt->getGroundNetwork()->exists())
 
391
      //cerr << (*(waypoints.end()-1))->name << endl;
 
392
      
 
393
      // Find a route from runway end to parking/gate.
 
394
      if (apt->getDynamics()->getGroundNetwork()->exists())
368
395
        {
369
396
          intVec ids;
370
 
          int runwayId = apt->getGroundNetwork()->findNearestNode(lat3, lon3);
371
 
          //int currId   = apt->getGroundNetwork()->findNearestNode(latitude,longitude);
372
 
          //exit(1);
373
 
          
 
397
          int runwayId = apt->getDynamics()->getGroundNetwork()->findNearestNode(lat3, 
 
398
                                                                                 lon3);
374
399
          // A negative gateId indicates an overflow parking, use a
375
400
          // fallback mechanism for this. 
376
401
          // Starting from gate 0 is a bit of a hack...
377
402
          FGTaxiRoute route;
378
403
          if (gateId >= 0)
379
 
            route = apt->getGroundNetwork()->findShortestRoute(runwayId, gateId);
 
404
            route = apt->getDynamics()->getGroundNetwork()->findShortestRoute(runwayId, 
 
405
                                                                              gateId);
380
406
          else
381
 
            route = apt->getGroundNetwork()->findShortestRoute(runwayId, 0);
 
407
            route = apt->getDynamics()->getGroundNetwork()->findShortestRoute(runwayId, 0);
382
408
          intVecIterator i;
383
 
          //cerr << "creating route : ";
 
409
         
384
410
          // No route found: go from gate directly to runway
385
411
          if (route.empty()) {
386
412
            //Add the runway startpoint;
413
439
          } else {
414
440
            int node;
415
441
            route.first();
416
 
            while(route.next(&node))
 
442
            int size = route.size();
 
443
            // Omit the last two waypoints, as 
 
444
            // those are created by createParking()
 
445
            for (int i = 0; i < size-2; i++)
417
446
              {
418
 
                //i = ids.end()-1;
419
 
                //cerr << "Creating Node: " << node << endl;
420
 
                FGTaxiNode *tn = apt->getGroundNetwork()->findNode(node);
421
 
                //ids.pop_back();  
 
447
                route.next(&node);
 
448
                FGTaxiNode *tn = apt->getDynamics()->getGroundNetwork()->findNode(node);
422
449
                wpt = new waypoint;
423
450
                wpt->name      = "taxiway"; // fixme: should be the name of the taxiway
424
451
                wpt->latitude  = tn->getLatitude();
425
452
                wpt->longitude = tn->getLongitude();
426
 
                wpt->altitude  = apt->getElevation(); // should maybe be tn->elev too
 
453
                wpt->altitude  = apt->getElevation();
427
454
                wpt->speed     = 15; 
428
455
                wpt->crossat   = -10000;
429
456
                wpt->gear_down = true;
432
459
                wpt->on_ground = true;
433
460
                waypoints.push_back(wpt);
434
461
              }
435
 
            cerr << endl;
436
462
          }
437
 
          //exit(1);
438
463
        }
439
464
      else
440
465
        {
441
 
          //Add the runway startpoint;
 
466
          // Use a fallback mechanism in case no ground network is available
 
467
          // obtain the location of the gate entrance point 
 
468
          heading += 180.0;
 
469
          if (heading > 360)
 
470
            heading -= 360;
 
471
          geo_direct_wgs_84 ( 0, lat, lon, heading, 
 
472
                              100,
 
473
                              &lat2, &lon2, &az2 );
442
474
          wpt = new waypoint;
443
475
          wpt->name      = "Airport Center";
444
476
          wpt->latitude  = apt->getLatitude();
451
483
          wpt->finished  = false;
452
484
          wpt->on_ground = true;
453
485
          waypoints.push_back(wpt);
 
486
         
 
487
          wpt = new waypoint;
 
488
          wpt->name      = "Begin Parking"; //apt->getId(); //wpt_node->getStringValue("name", "END");
 
489
          wpt->latitude  = lat2;
 
490
          wpt->longitude = lon2;
 
491
          wpt->altitude  = apt->getElevation();
 
492
          wpt->speed     = 15; 
 
493
          wpt->crossat   = -10000;
 
494
          wpt->gear_down = true;
 
495
          wpt->flaps_down= true;
 
496
          wpt->finished  = false;
 
497
          wpt->on_ground = true;
 
498
          waypoints.push_back(wpt); 
 
499
 
 
500
          //waypoint* wpt;
 
501
          //double lat;
 
502
          //double lon;
 
503
          //double heading;
 
504
          apt->getDynamics()->getParking(gateId, &lat, &lon, &heading);
 
505
          heading += 180.0;
 
506
          if (heading > 360)
 
507
            heading -= 360; 
454
508
          
 
509
          wpt = new waypoint;
 
510
          wpt->name      = "END"; //wpt_node->getStringValue("name", "END");
 
511
          wpt->latitude  = lat;
 
512
          wpt->longitude = lon;
 
513
          wpt->altitude  = 19;
 
514
          wpt->speed     = 15; 
 
515
          wpt->crossat   = -10000;
 
516
          wpt->gear_down = true;
 
517
          wpt->flaps_down= true;
 
518
          wpt->finished  = false;
 
519
          wpt->on_ground = true;
 
520
          waypoints.push_back(wpt);
455
521
        }
456
 
 
457
 
 
458
 
 
459
 
 
460
 
      // Add the final destination waypoint
461
 
      wpt = new waypoint;
462
 
      wpt->name      = "Begin Parking"; //apt->getId(); //wpt_node->getStringValue("name", "END");
463
 
      wpt->latitude  = lat2;
464
 
      wpt->longitude = lon2;
465
 
      wpt->altitude  = apt->getElevation();
466
 
      wpt->speed     = 15; 
467
 
      wpt->crossat   = -10000;
468
 
      wpt->gear_down = true;
469
 
      wpt->flaps_down= true;
470
 
      wpt->finished  = false;
471
 
      wpt->on_ground = true;
472
 
      waypoints.push_back(wpt); 
473
 
 
474
 
     
 
522
      
475
523
    }
476
 
  // wpt_iterator = waypoints.begin();
477
 
  //if (!firstFlight)
478
 
  // wpt_iterator++; 
479
 
  //wpt_iterator = waypoints.begin()+currWpt;
480
524
}
481
525
 
482
526
/*******************************************************************
488
532
  double wind_speed;
489
533
  double wind_heading;
490
534
  double heading;
491
 
  //FGRunway rwy;
492
535
  double lat, lon, az;
493
536
  double lat2, lon2, az2;
494
 
  //int direction;
495
537
  waypoint *wpt;
496
538
  
497
 
  
498
 
  // Erase all existing waypoints.
499
 
  // wpt_vector_iterator i= waypoints.begin();
500
 
  //while(waypoints.begin() != waypoints.end())
501
 
  //  {      
502
 
  //    delete *(i);
503
 
  //    waypoints.erase(i);
504
 
  //  }
505
 
  //resetWaypoints();
506
 
  
507
 
  
508
539
  // Get the current active runway, based on code from David Luff
509
540
  // This should actually be unified and extended to include 
510
541
  // Preferential runway use schema's 
514
545
       // "NOTE: this is currently fixed to "com" for commercial traffic
515
546
      // Should be changed to be used dynamically to allow "gen" and "mil"
516
547
      // as well
517
 
      apt->getActiveRunway("com", 1, activeRunway);
 
548
      apt->getDynamics()->getActiveRunway("com", 1, activeRunway);
518
549
        if (!(globals->get_runways()->search(apt->getId(), 
519
550
                                              activeRunway, 
520
551
                                              &rwy)))
521
552
          {
522
 
            cout << "Failed to find runway for " << apt->getId() << endl;
523
 
            // Hmm, how do we handle a potential error like this?
 
553
            SG_LOG(SG_INPUT, SG_ALERT, "Failed to find runway " << 
 
554
                   activeRunway << 
 
555
                   " at airport     " << apt->getId());
524
556
            exit(1);
525
557
          }
526
 
        //string test;
527
 
      //apt->getActiveRunway(string("com"), 1, test);
528
 
      //exit(1);
529
558
    }
530
 
  
531
559
  heading = rwy._heading;
532
560
  double azimuth = heading + 180.0;
533
561
  while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
568
596
  wpt->finished  = false;
569
597
  wpt->on_ground = false;
570
598
  waypoints.push_back(wpt);
571
 
  //  waypoints.push_back(wpt);
572
 
  //waypoints.push_back(wpt);  // add one more to prevent a segfault. 
573
 
  // wpt_iterator = waypoints.begin();
574
 
  //if (!firstFlight)
575
 
  // wpt_iterator++;
576
599
}
577
600
 
578
601
/*******************************************************************
590
613
  //int direction;
591
614
  waypoint *wpt;
592
615
 
593
 
  // Erase all existing waypoints.
594
 
  // wpt_vector_iterator i= waypoints.begin();
595
 
  //while(waypoints.begin() != waypoints.end())
596
 
  //  {      
597
 
  //    delete *(i);
598
 
  //    waypoints.erase(i);
599
 
  //  }
600
 
  //resetWaypoints();
601
 
  
602
 
  
603
 
  // Get the current active runway, based on code from David Luff
604
 
  // This should actually be unified and extended to include 
605
 
  // Preferential runway use schema's 
 
616
 
606
617
  if (firstFlight)
607
618
    {
608
619
      //string name;
609
620
      // "NOTE: this is currently fixed to "com" for commercial traffic
610
621
      // Should be changed to be used dynamically to allow "gen" and "mil"
611
622
      // as well
612
 
      apt->getActiveRunway("com", 1, activeRunway);
 
623
      apt->getDynamics()->getActiveRunway("com", 1, activeRunway);
613
624
        if (!(globals->get_runways()->search(apt->getId(), 
614
625
                                              activeRunway, 
615
626
                                              &rwy)))
616
627
          {
617
 
            cout << "Failed to find runway for " << apt->getId() << endl;
618
 
            // Hmm, how do we handle a potential error like this?
 
628
            SG_LOG(SG_INPUT, SG_ALERT, "Failed to find runway " << 
 
629
                   activeRunway << 
 
630
                   " at airport     " << apt->getId());
619
631
            exit(1);
620
632
          }
621
 
        //string test;
622
 
        //apt->getActiveRunway(string("com"), 1, test);
623
 
      //exit(1);
624
633
    }
625
634
  
626
635
  
659
668
  wpt->finished  = false;
660
669
  wpt->on_ground = false;
661
670
  waypoints.push_back(wpt); 
662
 
  //waypoints.push_back(wpt); 
663
 
  //waypoints.push_back(wpt);  // add one more to prevent a segfault. 
664
 
  // wpt_iterator = waypoints.begin();
665
 
  //if (!firstFlight)
666
 
  // wpt_iterator++;
667
671
}
668
672
 
669
673
 
671
675
 * CreateCruise
672
676
 * initialize the Aircraft at the parking location
673
677
 ******************************************************************/
674
 
void FGAIFlightPlan::createCruise(bool firstFlight, FGAirport *dep, FGAirport *arr, double latitude, double longitude, double speed, double alt)
 
678
void FGAIFlightPlan::createCruise(bool firstFlight, FGAirport *dep, 
 
679
                                  FGAirport *arr, double latitude, 
 
680
                                  double longitude, double speed, 
 
681
                                  double alt)
675
682
{
676
683
  double wind_speed;
677
684
  double wind_heading;
678
685
  double heading;
679
 
  //FGRunway rwy;
680
686
  double lat, lon, az;
681
687
  double lat2, lon2, az2;
682
688
  double azimuth;
683
 
  //int direction;
684
689
  waypoint *wpt;
685
690
 
686
 
  // Erase all existing waypoints.
687
 
  // wpt_vector_iterator i= waypoints.begin();
688
 
  //while(waypoints.begin() != waypoints.end())
689
 
  //  {      
690
 
  //    delete *(i);
691
 
  //    waypoints.erase(i);
692
 
  //  }
693
 
  //resetWaypoints();
694
 
 
695
691
  wpt = new waypoint;
696
692
  wpt->name      = "Cruise"; //wpt_node->getStringValue("name", "END");
697
693
  wpt->latitude  = latitude;
704
700
  wpt->finished  = false;
705
701
  wpt->on_ground = false;
706
702
  waypoints.push_back(wpt); 
707
 
  //Beginning of Decent
 
703
  
708
704
 
709
 
  //string name;
710
705
  // should be changed dynamically to allow "gen" and "mil"
711
 
  arr->getActiveRunway("com", 2, activeRunway);
 
706
  arr->getDynamics()->getActiveRunway("com", 2, activeRunway);
712
707
  if (!(globals->get_runways()->search(arr->getId(), 
713
708
                                       activeRunway, 
714
709
                                       &rwy)))
715
710
    {
716
 
      cout << "Failed to find runway for " << arr->getId() << endl;
717
 
      // Hmm, how do we handle a potential error like this?
 
711
      SG_LOG(SG_INPUT, SG_ALERT, "Failed to find runway " << 
 
712
             activeRunway << 
 
713
             " at airport     " << arr->getId());
718
714
      exit(1);
719
715
    }
720
 
  //string test;
721
 
  //arr->getActiveRunway(string("com"), 1, test);
722
 
  //exit(1);
723
 
  
724
 
  //cerr << "Altitude = " << alt << endl;
725
 
  //cerr << "Done" << endl;
726
 
  //if (arr->getId() == "EHAM")
727
 
  //  {
728
 
  //    cerr << "Creating cruise to EHAM " << latitude << " " << longitude << endl;
729
 
  //  }
730
716
  heading = rwy._heading;
731
717
  azimuth = heading + 180.0;
732
718
  while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
733
719
  
734
720
  
735
 
  // Note: This places us at the location of the active 
736
 
  // runway during initial cruise. This needs to be 
737
 
  // fixed later. 
738
721
  geo_direct_wgs_84 ( 0, rwy._lat, rwy._lon, azimuth, 
739
722
                      110000,
740
723
                      &lat2, &lon2, &az2 );
741
724
  wpt = new waypoint;
742
 
  wpt->name      = "BOD"; //wpt_node->getStringValue("name", "END");
 
725
  wpt->name      = "BOD";
743
726
  wpt->latitude  = lat2;
744
727
  wpt->longitude = lon2;
745
728
  wpt->altitude  = alt;
750
733
  wpt->finished  = false;
751
734
  wpt->on_ground = false;
752
735
  waypoints.push_back(wpt); 
753
 
  //waypoints.push_back(wpt);
754
 
  //waypoints.push_back(wpt);  // add one more to prevent a segfault.  
755
 
  //wpt_iterator = waypoints.begin();
756
 
  //if (!firstFlight)
757
 
  // wpt_iterator++;
758
736
}
759
737
 
760
738
/*******************************************************************
775
753
  //int direction;
776
754
  waypoint *wpt;
777
755
 
778
 
  //// Erase all existing waypoints.
779
 
  // wpt_vector_iterator i= waypoints.begin();
780
 
  //while(waypoints.begin() != waypoints.end())
781
 
  //  {      
782
 
  //    delete *(i);
783
 
  //    waypoints.erase(i);
784
 
  //  }
785
 
  //resetWaypoints();
786
 
 
787
756
  //Beginning of Decent
788
757
  //string name;
789
758
  // allow "mil" and "gen" as well
790
 
  apt->getActiveRunway("com", 2, activeRunway);
791
 
    if (!(globals->get_runways()->search(apt->getId(), 
792
 
                                          activeRunway, 
793
 
                                          &rwy)))
794
 
      {
795
 
        cout << "Failed to find runway for " << apt->getId() << endl;
796
 
        // Hmm, how do we handle a potential error like this?
797
 
        exit(1);
798
 
      }
799
 
    //string test;
800
 
    //apt->getActiveRunway(string("com"), 1, test);
801
 
  //exit(1);
802
 
 
803
 
  //cerr << "Done" << endl;
 
759
  apt->getDynamics()->getActiveRunway("com", 2, activeRunway);
 
760
  if (!(globals->get_runways()->search(apt->getId(), 
 
761
                                       activeRunway, 
 
762
                                       &rwy)))
 
763
    {
 
764
      SG_LOG(SG_INPUT, SG_ALERT, "Failed to find runway " << 
 
765
             activeRunway << 
 
766
             " at airport     " << apt->getId());
 
767
      exit(1);
 
768
    }
 
769
  
804
770
  heading = rwy._heading;
805
771
  azimuth = heading + 180.0;
806
772
  while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
807
 
  
808
 
  
809
 
  
810
773
  geo_direct_wgs_84 ( 0, rwy._lat, rwy._lon, azimuth, 
811
774
                      100000,
812
775
                      &lat2, &lon2, &az2 );
823
786
  wpt->finished  = false;
824
787
  wpt->on_ground = false;
825
788
  waypoints.push_back(wpt);  
826
 
 
 
789
  
827
790
  // Three thousand ft. Slowing down to 160 kts
828
791
  geo_direct_wgs_84 ( 0, rwy._lat, rwy._lon, azimuth, 
829
 
                     8*SG_NM_TO_METER,
830
 
                     &lat2, &lon2, &az2 );
 
792
                      8*SG_NM_TO_METER,
 
793
                      &lat2, &lon2, &az2 );
831
794
  wpt = new waypoint;
832
795
  wpt->name      = "DEC 3000ft"; //wpt_node->getStringValue("name", "END");
833
796
  wpt->latitude  = lat2;
840
803
  wpt->finished  = false;
841
804
  wpt->on_ground = false;
842
805
  waypoints.push_back(wpt);
843
 
  //waypoints.push_back(wpt);
844
 
  //waypoints.push_back(wpt);  // add one more to prevent a segfault. 
845
 
  //wpt_iterator = waypoints.begin();
846
 
  //wpt_iterator++;
847
 
  //if (apt->getId() == "EHAM")
848
 
  //  {
849
 
  //    cerr << "Created Decend to EHAM " << lat2 << " " << lon2 << ": Runway = " << rwy._rwy_no 
850
 
  //       << "heading " << heading << endl;
851
 
  //  }
852
806
}
853
807
/*******************************************************************
854
808
 * CreateLanding
856
810
 ******************************************************************/
857
811
void FGAIFlightPlan::createLanding(FGAirport *apt)
858
812
{
859
 
  // Ten thousand ft. Slowing down to 240 kts
 
813
  // Ten thousand ft. Slowing down to 150 kts
860
814
  double wind_speed;
861
815
  double wind_heading;
862
816
  double heading;
921
875
  wpt->finished  = false;
922
876
  wpt->on_ground = true;
923
877
  waypoints.push_back(wpt); 
924
 
  //waypoints.push_back(wpt); 
925
 
  //waypoints.push_back(wpt);  // add one more to prevent a segfault. 
926
 
  //wpt_iterator = waypoints.begin();
927
 
  //wpt_iterator++;
928
 
 
929
 
  //if (apt->getId() == "EHAM")
930
 
  //{
931
 
  //  cerr << "Created Landing to EHAM " << lat2 << " " << lon2 << ": Runway = " << rwy._rwy_no 
932
 
  //     << "heading " << heading << endl;
933
 
  //}
934
878
}
935
879
 
936
880
/*******************************************************************
937
881
 * CreateParking
938
882
 * initialize the Aircraft at the parking location
939
883
 ******************************************************************/
940
 
void FGAIFlightPlan::createParking(FGAirport *apt)
 
884
void FGAIFlightPlan::createParking(FGAirport *apt, double radius)
941
885
{
942
886
  waypoint* wpt;
943
 
  double lat;
944
 
  double lon;
 
887
  double lat, lat2;
 
888
  double lon, lon2;
 
889
  double az2;
945
890
  double heading;
946
 
  apt->getParking(gateId, &lat, &lon, &heading);
 
891
  apt->getDynamics()->getParking(gateId, &lat, &lon, &heading);
947
892
  heading += 180.0;
948
893
  if (heading > 360)
949
894
    heading -= 360; 
 
895
  geo_direct_wgs_84 ( 0, lat, lon, heading, 
 
896
                      2.2*radius,           
 
897
                      &lat2, &lon2, &az2 );
 
898
  wpt = new waypoint;
 
899
  wpt->name      = "taxiStart";
 
900
  wpt->latitude  = lat2;
 
901
  wpt->longitude = lon2;
 
902
  wpt->altitude  = apt->getElevation();
 
903
  wpt->speed     = 10; 
 
904
  wpt->crossat   = -10000;
 
905
  wpt->gear_down = true;
 
906
  wpt->flaps_down= true;
 
907
  wpt->finished  = false;
 
908
  wpt->on_ground = true;
 
909
  waypoints.push_back(wpt); 
 
910
  geo_direct_wgs_84 ( 0, lat, lon, heading, 
 
911
                      0.1 *radius,           
 
912
                      &lat2, &lon2, &az2 );
 
913
  wpt = new waypoint;
 
914
  wpt->name      = "taxiStart";
 
915
  wpt->latitude  = lat2;
 
916
  wpt->longitude = lon2;
 
917
  wpt->altitude  = apt->getElevation();
 
918
  wpt->speed     = 10; 
 
919
  wpt->crossat   = -10000;
 
920
  wpt->gear_down = true;
 
921
  wpt->flaps_down= true;
 
922
  wpt->finished  = false;
 
923
  wpt->on_ground = true;
 
924
  waypoints.push_back(wpt);   
950
925
 
951
 
  // Erase all existing waypoints.
952
 
  // wpt_vector_iterator i= waypoints.begin();
953
 
  //while(waypoints.begin() != waypoints.end())
954
 
  //  {      
955
 
  //    delete *(i);
956
 
  //    waypoints.erase(i);
957
 
  //  }
958
 
  //resetWaypoints();
959
 
  // And finally one more named "END"
960
926
  wpt = new waypoint;
961
927
  wpt->name      = "END"; //wpt_node->getStringValue("name", "END");
962
928
  wpt->latitude  = lat;
963
929
  wpt->longitude = lon;
964
 
  wpt->altitude  = 19;
 
930
  wpt->altitude  = apt->getElevation();
965
931
  wpt->speed     = 15; 
966
932
  wpt->crossat   = -10000;
967
933
  wpt->gear_down = true;
969
935
  wpt->finished  = false;
970
936
  wpt->on_ground = true;
971
937
  waypoints.push_back(wpt);
972
 
  //waypoints.push_back(wpt);
973
 
  //waypoints.push_back(wpt);  // add one more to prevent a segfault. 
974
 
  //wpt_iterator = waypoints.begin();
975
 
  //wpt_iterator++;
976
938
}