From 3c738b5ceef1ad0dfd42a7f400896a6431c34638 Mon Sep 17 00:00:00 2001 From: durk Date: Sun, 26 Mar 2006 21:40:35 +0000 Subject: [PATCH] Bugfix in the ai initialization randomization procedure. Randomly removing waypoints could cause the AIFlightPlan to run out of waypoints. This patch prevents that by retaining at least two waypoints. --- src/AIModel/AIAircraft.cxx | 29 +++++++++++++++-------------- src/AIModel/AIFlightPlanCreate.cxx | 4 +++- src/Airports/groundnetwork.hxx | 2 +- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/AIModel/AIAircraft.cxx b/src/AIModel/AIAircraft.cxx index 8b54c2bdd..5b347d068 100644 --- a/src/AIModel/AIAircraft.cxx +++ b/src/AIModel/AIAircraft.cxx @@ -704,20 +704,21 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) dep->getDynamics()->releaseParking(fp->getGate()); } // Some debug messages, specific to testing the Logical networks. - //if ((arr->getId() == string("EHAM")) && (prev->name == "Center")) - // { - // - // cerr << "Schiphol ground " - // << trafficRef->getRegistration() << " " - // << trafficRef->getCallSign(); - // if (trafficRef->getHeavy()) - // cerr << "Heavy"; - // cerr << " landed runway " - // << fp->getRunway() - // << " request taxi to gate " - // << arr->getDynamics()->getParkingName(fp->getGate()) - // << endl; - // } + if ((arr->getId() == string("EHAM")) && (prev->name == "Center")) + { + + cerr << "Schiphol ground " + << trafficRef->getRegistration() << " " + << trafficRef->getCallSign(); + if (trafficRef->getHeavy()) + cerr << "Heavy"; + cerr << ", arriving from " << dep->getName() ; + cerr << " landed runway " + << fp->getRunway() + << " request taxi to gate " + << arr->getDynamics()->getParkingName(fp->getGate()) + << endl; + } if (prev->name == "END") fp->setTime(trafficRef->getDepartureTime()); //cerr << "5" << endl; diff --git a/src/AIModel/AIFlightPlanCreate.cxx b/src/AIModel/AIFlightPlanCreate.cxx index 296a5920c..9a2b81561 100644 --- a/src/AIModel/AIFlightPlanCreate.cxx +++ b/src/AIModel/AIFlightPlanCreate.cxx @@ -303,7 +303,9 @@ void FGAIFlightPlan::createTaxi(bool firstFlight, int direction, isPushBackPoint = true; int nrWaypoints = route.size(); int nrWaypointsToSkip = rand() % nrWaypoints; - for (int i = 0; i < nrWaypointsToSkip; i++) { + // but make sure we always keep two active waypoints + // to prevent a segmentation fault + for (int i = 0; i < nrWaypointsToSkip-2; i++) { isPushBackPoint = false; route.next(&node); } diff --git a/src/Airports/groundnetwork.hxx b/src/Airports/groundnetwork.hxx index 2d779b5b8..c7a8b215f 100644 --- a/src/Airports/groundnetwork.hxx +++ b/src/Airports/groundnetwork.hxx @@ -124,7 +124,7 @@ public: bool next(int *val); void first() { currNode = nodes.begin(); }; - int size() { return nodes.end() - nodes.begin(); }; + int size() { return nodes.size(); }; }; typedef vector TaxiRouteVector; -- 2.39.5