]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIManager.cxx
Ground network distance tracking code. AIAircraft taxiing at airports
[flightgear.git] / src / AIModel / AIManager.cxx
index 5fe3d3dc27525c2bd4ff0a329e93484a605fe4d0..207913bb1ff5aae959e33dc829126c7c8c79ddb2 100644 (file)
@@ -16,7 +16,7 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 #include <Main/globals.hxx>
 
@@ -36,6 +36,8 @@
 FGAIManager::FGAIManager() {
   _dt = 0.0;
   mNumAiModels = 0;
+  for (unsigned i = 0; i < FGAIBase::MAX_OBJECTS; ++i)
+    mNumAiTypeModels[i] = 0;
 }
 
 FGAIManager::~FGAIManager() {
@@ -97,7 +99,6 @@ void FGAIManager::unbind() {
 
 
 void FGAIManager::update(double dt) {
-
   // initialize these for finding nearest thermals
   range_nearest = 10000.0;
   strength = 0.0;
@@ -112,6 +113,7 @@ void FGAIManager::update(double dt) {
     if ((*ai_list_itr)->getDie()) {      
       tmgr->release((*ai_list_itr)->getID());
       --mNumAiModels;
+      --(mNumAiTypeModels[(*ai_list_itr)->getType()]);
       (*ai_list_itr)->unbind();
       ai_list_itr = ai_list.erase(ai_list_itr);
     } else {
@@ -131,9 +133,14 @@ void FGAIManager::update(double dt) {
 void
 FGAIManager::attach(SGSharedPtr<FGAIBase> model)
 {
-  model->setManager(this);
+  unsigned idx = mNumAiTypeModels[model->getType()];
+  const char* typeString = model->getTypeString();
+  SGPropertyNode* root = globals->get_props()->getNode("ai/models", true);
+  SGPropertyNode* p = root->getNode(typeString, idx, true);
+  model->setManager(this, p);
   ai_list.push_back(model);
   ++mNumAiModels;
+  ++(mNumAiTypeModels[model->getType()]);
   model->init();
   model->bind();
 }
@@ -144,6 +151,7 @@ void FGAIManager::destroyObject( int ID ) {
   while(ai_list_itr != ai_list.end()) {
     if ((*ai_list_itr)->getID() == ID) {
       --mNumAiModels;
+      --(mNumAiTypeModels[(*ai_list_itr)->getType()]);
       (*ai_list_itr)->unbind();
       ai_list_itr = ai_list.erase(ai_list_itr);
     } else
@@ -269,8 +277,7 @@ void FGAIManager::setModel(const string& path, ssgBranch *model)
 }
 
 bool FGAIManager::getStartPosition(const string& id, const string& pid,
-                                   Point3D& geodPos, double& heading,
-                                   sgdVec3 uvw)
+                                   SGGeod& geodPos, double& hdng, SGVec3d& uvw)
 {
   bool found = false;
   SGPropertyNode* root = fgGetNode("sim/ai", true);
@@ -294,7 +301,7 @@ bool FGAIManager::getStartPosition(const string& id, const string& pid,
               SGSharedPtr<FGAICarrier> carrier = new FGAICarrier;
               carrier->readFromScenario(scEntry);
               
-              if (carrier->getParkPosition(pid, geodPos, heading, uvw)) {
+              if (carrier->getParkPosition(pid, geodPos, hdng, uvw)) {
                 found = true;
                 break;
               }