if (wpt->getName() == "END") wpt->setFinished(true);
else wpt->setFinished(false);
- waypoints.push_back( wpt );
+ pushBackWaypoint( wpt );
}
wpt_iterator = waypoints.begin();
SGPropertyNode * node = root.getNode("flightplan");
- //waypoints.push_back( init_waypoint );
+ //pushBackWaypoint( init_waypoint );
for (int i = 0; i < node->nChildren(); i++) {
//cout << "Reading waypoint " << i << endl;
FGAIWaypoint* wpt = new FGAIWaypoint;
if (wpt->getName() == "END") wpt->setFinished(true);
else wpt->setFinished(false);
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
} // of node loop
wpt_iterator = waypoints.begin();
} catch (const sg_exception &e) {
{
if ((dist > 100.0) && (useInitialWayPoint))
{
- //waypoints.push_back(init_waypoint);;
+ //pushBackWaypoint(init_waypoint);;
waypoints.insert(i, init_waypoint);
//cerr << "Using waypoint : " << init_waypoint->name << endl;
}
// {
// (*i)->speed = dist; // A hack
// }
- //waypoints.push_back( wpt );
+ //pushBackWaypoint( wpt );
//cerr << "Using waypoint : " << (*i)->name
// << ": course diff : " << crsDiff
// << "Course = " << course
wpt->setOn_ground ( (*i)->getOn_ground() );
//cerr << "Recycling waypoint " << wpt->name << endl;
deleteWaypoints();
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
}
}
+void FGAIFlightPlan::pushBackWaypoint(FGAIWaypoint *wpt)
+{
+ // std::vector::push_back invalidates waypoints
+ // so we should restore wpt_iterator after push_back
+ // (or it could be an index in the vector)
+ size_t pos = wpt_iterator - waypoints.begin();
+ waypoints.push_back(wpt);
+ wpt_iterator = waypoints.begin() + pos;
+}
+
// Start flightplan over from the beginning
void FGAIFlightPlan::restart()
{
wpt =
createOnGround(ac, "Airport Center", aAirport->geod(), airportElev,
ac->getPerformance()->vTaxi());
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
wpt =
createOnGround(ac, "Runway Takeoff", runwayTakeoff, airportElev,
ac->getPerformance()->vTaxi());
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
}
bool FGAIFlightPlan::createTakeoffTaxi(FGAIAircraft * ac, bool firstFlight,
if (taxiRoute->nodesLeft() == 0) {
wpt->setName(wpt->getName() + string("Accel"));
}
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
}
// Acceleration point, 105 meters into the runway,
SGGeod accelPoint = rwy->pointOnCenterline(105.0);
FGAIWaypoint *wpt = createOnGround(ac, "accel", accelPoint, apt->getElevation(), ac->getPerformance()->vRotate());
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
//cerr << "[done]" << endl;
return true;
wpt =
createOnGround(ac, "Runway Exit", lastWptPos, airportElev,
ac->getPerformance()->vTaxi());
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
wpt =
createOnGround(ac, "Airport Center", aAirport->geod(), airportElev,
ac->getPerformance()->vTaxi());
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
double heading, lat, lon;
aAirport->getDynamics()->getParking(gateId, &lat, &lon, &heading);
wpt =
createOnGround(ac, "END", SGGeod::fromDeg(lon, lat), airportElev,
ac->getPerformance()->vTaxi());
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
}
bool FGAIFlightPlan::createLandingTaxi(FGAIAircraft * ac, FGAirport * apt,
createOnGround(ac, buffer, tn->getGeod(), apt->getElevation(),
ac->getPerformance()->vTaxi());
wpt->setRouteIndex(route);
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
}
return true;
}
//cerr << "Using " << accelDistance << " " << accelMetric << " " << vTakeoffMetric << endl;
SGGeod accelPoint = rwy->pointOnCenterline(105.0 + accelDistance);
wpt = createOnGround(ac, "rotate", accelPoint, airportElev, vTakeoff);
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
accelDistance =
((vTakeoffMetric * 1.1) * (vTakeoffMetric * 1.1) -
createOnGround(ac, "rotate", accelPoint, airportElev + 1000,
vTakeoff * 1.1);
wpt->setOn_ground(false);
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
wpt = cloneWithPos(ac, wpt, "3000 ft", rwy->end());
wpt->setAltitude(airportElev + 3000);
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
// Finally, add two more waypoints, so that aircraft will remain under
// Tower control until they have reached the 3000 ft climb point
SGGeod pt = rwy->pointOnCenterline(5000 + rwy->lengthM() * 0.5);
wpt = cloneWithPos(ac, wpt, "5000 ft", pt);
wpt->setAltitude(airportElev + 5000);
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
return true;
}
if (sid) {
for (wpt_vector_iterator i = sid->getFirstWayPoint();
i != sid->getLastWayPoint(); i++) {
- waypoints.push_back(clone(*(i)));
+ pushBackWaypoint(clone(*(i)));
//cerr << " Cloning waypoint " << endl;
}
} else {
wpt = createInAir(ac, "10000ft climb", climb1, 10000, vClimb);
wpt->setGear_down(true);
wpt->setFlaps_down(true);
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
SGGeod climb2 = rwy->pointOnCenterline(20 * SG_NM_TO_METER);
wpt = cloneWithPos(ac, wpt, "18000ft climb", climb2);
wpt->setAltitude(18000);
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
}
return true;
}
wpt = createInAir(ac, buffer, result, currentAltitude, vDescent);
wpt->setCrossat(currentAltitude);
wpt->setTrackLength((newDistance / nPoints));
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
//cerr << "Track Length : " << wpt->trackLength;
//cerr << " Position : " << result.getLatitudeDeg() << " " << result.getLongitudeDeg() << " " << currentAltitude << endl;
}
wpt->setCrossat(currentAltitude);
wpt->setTrackLength(trackLength);
//cerr << "Track Length : " << wpt->trackLength;
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
//cerr << " Position : " << result.getLatitudeDeg() << " " << result.getLongitudeDeg() << " " << currentAltitude << endl;
}
wpt->setTrackLength(wpt->getTrackLength() + distanceCovered);
}
//cerr << "Track Length : " << wpt->trackLength;
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
//if (apt->ident() == fgGetString("/sim/presets/airport-id")) {
// cerr << " Position : " << result.getLatitudeDeg() << " " << result.getLongitudeDeg() << " " << currentAltitude << " " << apt->getElevation() << " " << distanceOut << endl;
//}
coord = rwy->pointOnCenterline((rolloutDistance * ((double) i / (double) nPoints)));
wpt = createOnGround(ac, buffer, coord, currElev, 2*vTaxi);
wpt->setCrossat(currElev);
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
}
wpt->setSpeed(vTaxi);
double mindist = 1.1 * rolloutDistance;
}
if (tn) {
wpt = createOnGround(ac, buffer, tn->getGeod(), currElev, vTaxi);
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
}
}
cerr << "Done. " << endl;
//Runway Threshold
wpt = createOnGround(ac, "Threshold", rwy->threshold(), aptElev, vTouchdown);
wpt->crossat = apt->getElevation();
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
// Roll-out
wpt = createOnGround(ac, "Center", rwy->geod(), aptElev, vTaxi*2);
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
SGGeod rollOut = rwy->pointOnCenterline(rwy->lengthM() * 0.9);
wpt = createOnGround(ac, "Roll Out", rollOut, aptElev, vTaxi);
wpt->crossat = apt->getElevation();
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
*/
return true;
}
wpt =
createOnGround(ac, "taxiStart", SGGeod::fromDeg(lon2, lat2),
aptElev, vTaxiReduced);
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
geo_direct_wgs_84(0, lat, lon, heading,
0.1 * radius, &lat2, &lon2, &az2);
wpt =
createOnGround(ac, "taxiStart2", SGGeod::fromDeg(lon2, lat2),
aptElev, vTaxiReduced);
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
wpt =
createOnGround(ac, "END", SGGeod::fromDeg(lon, lat), aptElev,
vTaxiReduced);
- waypoints.push_back(wpt);
+ pushBackWaypoint(wpt);
return true;
}