From ee63507f22629222c3cb35214e8238800c214df1 Mon Sep 17 00:00:00 2001 From: portree_kid Date: Thu, 12 Feb 2015 22:09:45 +0100 Subject: [PATCH] Code to stop loading of invalid flightplans --- src/AIModel/AIBase.cxx | 7 ++++--- src/AIModel/AIBase.hxx | 1 + src/AIModel/AIFlightPlan.cxx | 5 +++++ src/AIModel/AIFlightPlan.hxx | 2 +- src/AIModel/AIManager.cxx | 9 ++++++++- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index 136c77270..d933e68af 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -106,7 +106,6 @@ public: bool getInteriorLoaded(void) { return _interiorLoaded;} bool hasInteriorPath(void) { return _hasInteriorPath;} inline std::string& getInteriorPath() { return _interiorPath; } - private: std::auto_ptr _nasal; std::string _fxpath; @@ -932,5 +931,7 @@ int FGAIBase::_newAIModelID() { return id; } - - +bool FGAIBase::isValid() { + //Either no flightplan or it is valid + return !fp || fp->isValidPlan(); +} diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index 504419c7c..f2ba097e7 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -110,6 +110,7 @@ public: int _getSubID() const; bool getDie(); + bool isValid(); SGVec3d getCartPosAt(const SGVec3d& off) const; SGVec3d getCartPos() const; diff --git a/src/AIModel/AIFlightPlan.cxx b/src/AIModel/AIFlightPlan.cxx index eb0e6cc1f..99f68eb96 100644 --- a/src/AIModel/AIFlightPlan.cxx +++ b/src/AIModel/AIFlightPlan.cxx @@ -251,6 +251,11 @@ bool FGAIFlightPlan::parseProperties(const std::string& filename) wpt->setFinished ((wpt->getName() == "END")); pushBackWaypoint( wpt ); } + if( getLastWaypoint()->getName().compare("END") != 0 ) { + SG_LOG(SG_AI, SG_ALERT, "FGAIFlightPlan::Flightplan missing END node" ); + return false; + } + wpt_iterator = waypoints.begin(); return true; diff --git a/src/AIModel/AIFlightPlan.hxx b/src/AIModel/AIFlightPlan.hxx index ff3ff2cef..31e4f8698 100644 --- a/src/AIModel/AIFlightPlan.hxx +++ b/src/AIModel/AIFlightPlan.hxx @@ -244,7 +244,7 @@ private: public: wpt_vector_iterator getFirstWayPoint() { return waypoints.begin(); }; wpt_vector_iterator getLastWayPoint() { return waypoints.end(); }; - bool isValidPlan() { return isValid; }; + bool isValidPlan() { return isValid; }; }; #endif // _FG_AIFLIGHTPLAN_HXX diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index 27582d9ca..2c6fc15f4 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -408,7 +408,14 @@ FGAIBasePtr FGAIManager::addObject(const SGPropertyNode* definition) } ai->readFromScenario(const_cast(definition)); - attach(ai); + if((ai->isValid())){ + attach(ai); + SG_LOG(SG_AI, SG_DEBUG, "attached scenario " << ai->_getName()); + } + else{ + ai->setDie(true); + SG_LOG(SG_AI, SG_ALERT, "killed invalid scenario " << ai->_getName()); + } return ai; }