- aircraft->SetFlightPlan(new FGAIFlightPlan(aircraft, flightPlanName, courseToDest, deptime,
- dep, arr, true, radius,
- flight->getCruiseAlt()*100,
- position.getLatitudeDeg(),
- position.getLongitudeDeg(),
- speedKnots, flightType, acType,
- airline));
-
-
- FGAIManager* aimgr = (FGAIManager *) globals-> get_subsystem("ai_model");
- aimgr->attach(aircraft);
- AIManagerRef = aircraft->getID();
- return true;
+ FGAIFlightPlan *fp = new FGAIFlightPlan(aiAircraft, flightPlanName, courseToDest, deptime,
+ dep, arr, true, radius,
+ flight->getCruiseAlt()*100,
+ position.getLatitudeDeg(),
+ position.getLongitudeDeg(),
+ speedKnots, flightType, acType,
+ airline);
+ if (fp->isValidPlan()) {
+ aiAircraft->SetFlightPlan(fp);
+ FGAIManager* aimgr = (FGAIManager *) globals-> get_subsystem("ai-model");
+ aimgr->attach(aiAircraft);
+ return true;
+ } else {
+ aiAircraft = NULL;
+ delete fp;
+ //hand back the flights that had already been scheduled
+ while (!flights.empty()) {
+ flights.front()->release();
+ flights.erase(flights.begin());
+ }
+ return false;
+ }