#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
+#include <Airports/simple.hxx>
+#include <Traffic/SchedFlight.hxx>
+#include <Traffic/Schedule.hxx>
+#include <Traffic/TrafficMgr.hxx>
+
#include <list>
#include "AIManager.hxx"
#include "AIBallistic.hxx"
#include "AIStorm.hxx"
#include "AIThermal.hxx"
+#include "AICarrier.hxx"
SG_USING_STD(list);
++ai_list_itr;
}
ai_list.clear();
+ ModelVecIterator i = loadedModels.begin();
+ while (i != loadedModels.end())
+ {
+ i->getModelId()->deRef();
+ }
}
// initialize these for finding nearest thermals
range_nearest = 10000.0;
strength = 0.0;
+ FGTrafficManager *tmgr = (FGTrafficManager*) globals->get_subsystem("Traffic Manager");
if (!enabled)
return;
ai_list_itr = ai_list.begin();
while(ai_list_itr != ai_list.end()) {
if ((*ai_list_itr)->getDie()) {
+ tmgr->release((*ai_list_itr)->getID());
--numObjects[(*ai_list_itr)->getType()];
--numObjects[0];
(*ai_list_itr)->unbind();
void*
-FGAIManager::createAircraft( FGAIModelEntity *entity ) {
+FGAIManager::createAircraft( FGAIModelEntity *entity, FGAISchedule *ref) {
- FGAIAircraft* ai_plane = new FGAIAircraft(this);
+ FGAIAircraft* ai_plane = new FGAIAircraft(this, ref);
ai_list.push_back(ai_plane);
++numObjects[0];
++numObjects[FGAIBase::otAircraft];
void*
FGAIManager::createShip( FGAIModelEntity *entity ) {
+
+ // cout << "creating ship" << endl;
FGAIShip* ai_ship = new FGAIShip(this);
ai_list.push_back(ai_ship);
return ai_ship;
}
+void*
+FGAIManager::createCarrier( FGAIModelEntity *entity ) {
+
+ // cout << "creating carrier" << endl;
+
+ FGAICarrier* ai_carrier = new FGAICarrier(this);
+ ai_list.push_back(ai_carrier);
+ ++numObjects[0];
+ ++numObjects[FGAIBase::otShip];
+ ai_carrier->setHeading(entity->heading);
+ ai_carrier->setSpeed(entity->speed);
+ ai_carrier->setPath(entity->path.c_str());
+ ai_carrier->setAltitude(entity->altitude);
+ ai_carrier->setLongitude(entity->longitude);
+ ai_carrier->setLatitude(entity->latitude);
+ ai_carrier->setBank(entity->rudder);
+ ai_carrier->setSolidObjects(entity->solid_objects);
+ ai_carrier->setWireObjects(entity->wire_objects);
+ ai_carrier->setCatapultObjects(entity->catapult_objects);
+ ai_carrier->setRadius(entity->radius);
+ ai_carrier->setXoffset(entity->x_offset);
+ ai_carrier->setYoffset(entity->y_offset);
+ ai_carrier->setZoffset(entity->z_offset);
+
+ if ( entity->fp ) {
+ ai_carrier->setFlightPlan(entity->fp);
+ }
+
+ ai_carrier->init();
+ ai_carrier->bind();
+ return ai_carrier;
+}
+
void*
FGAIManager::createBallistic( FGAIModelEntity *entity ) {
ai_ballistic->setRoll(entity->roll);
ai_ballistic->setCd(entity->cd);
ai_ballistic->setMass(entity->mass);
+ ai_ballistic->setStabilisation(entity->aero_stabilised);
ai_ballistic->init();
ai_ballistic->bind();
return ai_ballistic;
} else if ( en->m_type == "ship") {
createShip( en );
+ } else if ( en->m_type == "carrier") {
+ createCarrier( en );
+
} else if ( en->m_type == "thunderstorm") {
createStorm( en );
delete s;
}
+// This code keeps track of models that have already been loaded
+// Eventually we'd prbably need to find a way to keep track of models
+// that are unloaded again
+ssgBranch * FGAIManager::getModel(const string& path)
+{
+ ModelVecIterator i = loadedModels.begin();
+ while (i != loadedModels.end())
+ {
+ if (i->getPath() == path)
+ return i->getModelId();
+ i++;
+ }
+ return 0;
+}
+
+void FGAIManager::setModel(const string& path, ssgBranch *model)
+{
+ loadedModels.push_back(FGModelID(path,model));
+}
+
+
//end AIManager.cxx