-void FGAIManager::processScenario( string filename ) {
- FGAIScenario* s = new FGAIScenario( filename );
- FGAIFlightPlan* f;
-
- for (int i=0;i<s->nEntries();i++) {
- FGAIScenario::entry* en = s->getNextEntry();
- f = 0;
- if (en) {
- if (en->flightplan != ""){
- f = new FGAIFlightPlan( en->flightplan );
- }
- if (en->aitype == "aircraft"){
- if (f){
- createAircraft( en->aircraft_class, en->model_path, f );
- } else {
- createAircraft( en->aircraft_class, en->model_path, en->latitude,
- en->longitude, en->altitude, en->heading,
- en->speed, en->roll );
- }
- } else if (en->aitype == "ship"){
- if (f){
- createShip( en->model_path, f );
- } else {
- createShip( en->model_path, en->latitude,
- en->longitude, en->altitude, en->heading,
- en->speed, en->rudder );
- }
-
- } else if (en->aitype == "storm"){
- createStorm( en->model_path, en->latitude, en->longitude,
- en->altitude, en->heading, en->speed );
- } else if (en->aitype == "thermal"){
- createThermal( en->latitude, en->longitude, en->strength,
- en->diameter );
- } else if (en->aitype == "ballistic"){
- createBallistic( en->model_path, en->latitude, en->longitude,
- en->altitude, en->azimuth, en->elevation, en->speed );
- }
+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;
+ }
+ }
+ }
+ }
+ }
+ }