- // First waypoint is current position of the aircraft as
- // dictated by the traffic manager.
- waypoint* init_waypoint = new waypoint;
- init_waypoint->name = string("initial position");
- init_waypoint->latitude = lat;
- init_waypoint->longitude = lon;
- init_waypoint->altitude = alt;
- init_waypoint->speed = speed;
- init_waypoint->crossat = - 10000;
- init_waypoint->gear_down = false;
- init_waypoint->flaps_down = false;
- waypoints.push_back( init_waypoint );
- for (i = 0; i < node->nChildren(); i++) {
- //cout << "Reading waypoint " << i << endl;
- waypoint* wpt = new waypoint;
- SGPropertyNode * wpt_node = node->getChild(i);
- wpt->name = wpt_node->getStringValue("name", "END");
- wpt->latitude = wpt_node->getDoubleValue("lat", 0);
- wpt->longitude = wpt_node->getDoubleValue("lon", 0);
- wpt->altitude = wpt_node->getDoubleValue("alt", 0);
- wpt->speed = wpt_node->getDoubleValue("ktas", 0);
- //wpt->speed = speed;
- wpt->crossat = wpt_node->getDoubleValue("crossat", -10000);
- wpt->gear_down = wpt_node->getBoolValue("gear-down", false);
- wpt->flaps_down= wpt_node->getBoolValue("flaps-down", false);
-
- if (wpt->name == "END") wpt->finished = true;
- else wpt->finished = false;
- // discard this waypoint if it's bearing differs more than
- // 90 degrees from the course we should fly according to the
- // Traffic manager. Those are considered "behind" us.
- SGWayPoint first(init_waypoint->longitude,
- init_waypoint->latitude,
- init_waypoint->altitude);
- SGWayPoint curr (wpt->longitude,
- wpt->latitude,
- wpt->altitude);
- double crse, crsDiff;
- double dist;
- first.CourseAndDistance(curr, &crse, &dist);
-
- dist *= SG_METER_TO_NM;
-
- // We're only interested in the absolute value of crsDiff
- // wich should fall in the 0-180 deg range.
- crsDiff = fabs(crse-course);
- if (crsDiff > 180)
- crsDiff -= 180;
- // These are the threee conditions that we consder including
- // in our flight plan:
- // 1) current waypoint is less then 100 miles away OR
- // 2) curren waypoint is ahead of us, at any distance
- bool useWpt = false;
- if ((dist > 100.0) && (crsDiff > 90.0) && (wpt->name != string ("EOF")))
- {
- //useWpt = false;
- // Once we start including waypoints, we have to continue, even though
- // one of the following way point would suffice.
- // so once is the useWpt flag is set to true, we cannot reset it to false.
- // cerr << "Discarding waypoint: " << wpt->name
- // << ": Course difference = " << crsDiff << endl;
- }
- else
- useWpt = true;
-
- if (useWpt)
- {
- if ((dist > 100.0) && (useInitialWayPoint))
- {
- waypoints.push_back(init_waypoint);
- //cerr << "Using waypoint : " << init_waypoint->name << endl;
- }
- waypoints.push_back( wpt );
- //cerr << "Using waypoint : " << wpt->name
- // << ": course diff : " << crsDiff
- // << "distance : " << dist << endl;
- useInitialWayPoint = false;
- }
- else
- delete wpt;
+ for (int i = 0; i < node->nChildren(); i++) {
+ FGAIWaypoint* wpt = new FGAIWaypoint;
+ SGPropertyNode * wpt_node = node->getChild(i);
+ wpt->setName (wpt_node->getStringValue("name", "END" ));
+ wpt->setLatitude (wpt_node->getDoubleValue("lat", 0 ));
+ wpt->setLongitude (wpt_node->getDoubleValue("lon", 0 ));
+ wpt->setAltitude (wpt_node->getDoubleValue("alt", 0 ));
+ wpt->setSpeed (wpt_node->getDoubleValue("ktas", 0 ));
+ wpt->setCrossat (wpt_node->getDoubleValue("crossat", -10000 ));
+ wpt->setGear_down (wpt_node->getBoolValue("gear-down", false ));
+ wpt->setFlaps_down (wpt_node->getBoolValue("flaps-down", false ));
+ wpt->setOn_ground (wpt_node->getBoolValue("on-ground", false ));
+ wpt->setTime_sec (wpt_node->getDoubleValue("time-sec", 0 ));
+ wpt->setTime (wpt_node->getStringValue("time", "" ));
+ wpt->setFinished ((wpt->getName() == "END"));
+ pushBackWaypoint( wpt );