1 // FGAIScenario.cxx - class for loading an AI scenario
2 // Written by David Culp, started May 2004
3 // - davidculp2@comcast.net
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <simgear/misc/sg_path.hxx>
21 #include <simgear/debug/logstream.hxx>
22 #include <simgear/structure/exception.hxx>
23 #include <simgear/constants.h>
25 # define exception c_exception
27 #include <simgear/props/props.hxx>
29 #include <Main/globals.hxx>
30 #include <Main/fg_props.hxx>
32 #include "AIScenario.hxx"
33 #include "AIFlightPlan.hxx"
37 FGAIScenario::FGAIScenario(string &filename)
40 SGPath path( globals->get_fg_root() );
41 path.append( ("/Data/AI/" + filename + ".xml").c_str() );
45 readProperties(path.str(), &root);
46 } catch (const sg_exception &e) {
47 SG_LOG(SG_GENERAL, SG_ALERT,
48 "Incorrect path specified for AI scenario: ");
49 cout << path.str() << endl;
54 SGPropertyNode * node = root.getNode("scenario");
55 for (i = 0; i < node->nChildren(); i++) {
56 //cout << "Reading entry " << i << endl;
57 SGPropertyNode * entry_node = node->getChild(i);
59 FGAIModelEntity* en = new FGAIModelEntity;
60 en->callsign = entry_node->getStringValue("callsign", "none");
61 en->m_type = entry_node->getStringValue("type", "aircraft");
62 en->m_class = entry_node->getStringValue("class", "jet_transport");
63 en->path = entry_node->getStringValue("model", "Models/Geometry/glider.ac");
64 en->flightplan = entry_node->getStringValue("flightplan", "");
65 en->repeat = entry_node->getDoubleValue("repeat", 0.0);
66 en->latitude = entry_node->getDoubleValue("latitude", 0.0);
67 en->longitude = entry_node->getDoubleValue("longitude", 0.0);
68 en->altitude = entry_node->getDoubleValue("altitude", 0.0);
69 en->speed = entry_node->getDoubleValue("speed", 0.0);
70 en->heading = entry_node->getDoubleValue("heading", 0.0);
71 en->roll = entry_node->getDoubleValue("roll", 0.0);
72 en->azimuth = entry_node->getDoubleValue("azimuth", 0.0);
73 en->elevation = entry_node->getDoubleValue("elevation", 0.0);
74 en->rudder = entry_node->getDoubleValue("rudder", 0.0);
75 en->strength = entry_node->getDoubleValue("strength-fps", 0.0);
76 en->diameter = entry_node->getDoubleValue("diameter-ft", 0.0);
77 en->eda = entry_node->getDoubleValue("eda", 0.007);
78 en->life = entry_node->getDoubleValue("life", 900.0);
79 en->buoyancy = entry_node->getDoubleValue("buoyancy", 0);
80 en->wind_from_east = entry_node->getDoubleValue("wind_from_east", 0);
81 en->wind_from_north = entry_node->getDoubleValue("wind_from_north", 0);
82 en->wind = entry_node->getBoolValue("wind", false);
83 en->cd = entry_node->getDoubleValue ("cd", 0.029);
84 en->weight = entry_node->getDoubleValue ("weight", 0.030);
87 if (en->flightplan != ""){
88 en->fp = new FGAIFlightPlan( en->flightplan );
90 entries.push_back( en );
93 entry_iterator = entries.begin();
94 //cout << entries.size() << " entries read." << endl;
98 FGAIScenario::~FGAIScenario()
105 FGAIScenario::getNextEntry( void )
107 if (entries.size() == 0) return 0;
108 if (entry_iterator != entries.end()) {
109 return *entry_iterator++;
115 int FGAIScenario::nEntries( void )
117 return entries.size();