+
+void
+FGAIManager::processScenario( const string &filename ) {
+
+ SGPropertyNode_ptr scenarioTop = loadScenarioFile(filename);
+
+ if (!scenarioTop)
+ return;
+
+ SGPropertyNode* scenarios = scenarioTop->getChild("scenario");
+
+ if (!scenarios)
+ return;
+
+ for (int i = 0; i < scenarios->nChildren(); i++) {
+ SGPropertyNode* scEntry = scenarios->getChild(i);
+
+ if (strcmp(scEntry->getName(), "entry"))
+ continue;
+ std::string type = scEntry->getStringValue("type", "aircraft");
+
+ if (type == "tanker") { // refueling scenarios
+ FGAITanker* tanker = new FGAITanker;
+ tanker->readFromScenario(scEntry);
+ attach(tanker);
+
+ } else if (type == "wingman") {
+ FGAIWingman* wingman = new FGAIWingman;
+ wingman->readFromScenario(scEntry);
+ attach(wingman);
+
+ } else if (type == "aircraft") {
+ FGAIAircraft* aircraft = new FGAIAircraft;
+ aircraft->readFromScenario(scEntry);
+ attach(aircraft);
+
+ } else if (type == "ship") {
+ FGAIShip* ship = new FGAIShip;
+ ship->readFromScenario(scEntry);
+ attach(ship);
+
+ } else if (type == "carrier") {
+ FGAICarrier* carrier = new FGAICarrier;
+ carrier->readFromScenario(scEntry);
+ attach(carrier);
+
+ } else if (type == "groundvehicle") {
+ FGAIGroundVehicle* groundvehicle = new FGAIGroundVehicle;
+ groundvehicle->readFromScenario(scEntry);
+ attach(groundvehicle);
+
+ } else if (type == "thunderstorm") {
+ FGAIStorm* storm = new FGAIStorm;
+ storm->readFromScenario(scEntry);
+ attach(storm);
+
+ } else if (type == "thermal") {
+ FGAIThermal* thermal = new FGAIThermal;
+ thermal->readFromScenario(scEntry);
+ attach(thermal);
+
+ } else if (type == "ballistic") {
+ FGAIBallistic* ballistic = new FGAIBallistic;
+ ballistic->readFromScenario(scEntry);
+ attach(ballistic);
+
+ } else if (type == "static") {
+ FGAIStatic* aistatic = new FGAIStatic;
+ aistatic->readFromScenario(scEntry);
+ attach(aistatic);
+ }
+
+ }
+
+}
+
+SGPropertyNode_ptr
+FGAIManager::loadScenarioFile(const std::string& filename)
+{
+ SGPath path(globals->get_fg_root());
+ path.append("AI/" + filename + ".xml");
+ try {
+ SGPropertyNode_ptr root = new SGPropertyNode;
+ readProperties(path.str(), root);
+ return root;
+ } catch (const sg_exception &) {
+ SG_LOG(SG_GENERAL, SG_DEBUG, "Incorrect path specified for AI "
+ "scenario: \"" << path.str() << "\"");
+ return 0;
+ }
+}
+
+bool
+FGAIManager::getStartPosition(const string& id, const string& pid,
+ SGGeod& geodPos, double& hdng, SGVec3d& uvw)
+{
+ bool found = false;
+ SGPropertyNode* root = fgGetNode("sim/ai", true);
+ if (!root->getNode("enabled", true)->getBoolValue())
+ return found;
+
+ for (int i = 0 ; (!found) && i < root->nChildren() ; i++) {
+ SGPropertyNode *aiEntry = root->getChild( i );
+ if ( !strcmp( aiEntry->getName(), "scenario" ) ) {
+ string filename = aiEntry->getStringValue();
+ SGPropertyNode_ptr scenarioTop = loadScenarioFile(filename);
+ if (scenarioTop) {
+ SGPropertyNode* scenarios = scenarioTop->getChild("scenario");
+ if (scenarios) {
+ for (int i = 0; i < scenarios->nChildren(); i++) {
+ SGPropertyNode* scEntry = scenarios->getChild(i);
+ std::string type = scEntry->getStringValue("type");
+ std::string pnumber = scEntry->getStringValue("pennant-number");
+ std::string name = scEntry->getStringValue("name");
+ if (type == "carrier" && (pnumber == id || name == id)) {
+ osg::ref_ptr<FGAICarrier> carrier = new FGAICarrier;
+ carrier->readFromScenario(scEntry);
+
+ if (carrier->getParkPosition(pid, geodPos, hdng, uvw)) {
+ found = true;
+ break;
+ }
+ }
+ }