]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIScenario.cxx
David Culp:
[flightgear.git] / src / AIModel / AIScenario.cxx
1 // FGAIScenario - class for loading an AI scenario
2 // Written by David Culp, started May 2004
3 // - davidculp2@comcast.net
4 //
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.
9 //
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.
14 //
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.
18
19
20 #include "AIScenario.hxx"
21 #include <simgear/misc/sg_path.hxx>
22 #include <simgear/debug/logstream.hxx>
23 #include <simgear/structure/exception.hxx>
24 #include <simgear/constants.h>
25 #ifdef __BORLANDC__
26 #  define exception c_exception
27 #endif
28 #include <simgear/props/props.hxx>
29 #include <Main/globals.hxx>
30 #include <Main/fg_props.hxx>
31
32
33 FGAIScenario::FGAIScenario(string filename)
34 {
35   int i;
36   SGPath path( globals->get_fg_root() );
37   path.append( ("/Data/AI/" + filename + ".xml").c_str() );
38   SGPropertyNode root;
39
40   try {
41       readProperties(path.str(), &root);
42   } catch (const sg_exception &e) {
43       SG_LOG(SG_GENERAL, SG_ALERT,
44        "Incorrect path specified for AI scenario: ");
45        cout << path.str() << endl;
46       return;
47   }
48
49   SGPropertyNode * node = root.getNode("scenario");
50   for (i = 0; i < node->nChildren(); i++) { 
51      //cout << "Reading entry " << i << endl;        
52      entry* en = new entry;
53      entries.push_back( en );
54      SGPropertyNode * entry_node = node->getChild(i);
55      en->callsign       = entry_node->getStringValue("callsign", "none");
56      en->aitype         = entry_node->getStringValue("type", "aircraft");
57      en->aircraft_class = entry_node->getStringValue("class", "jet_transport");
58      en->model_path     = entry_node->getStringValue("model", "Models/Geometry/glider.ac");
59      en->flightplan     = entry_node->getStringValue("flightplan", "");
60      en->repeat         = entry_node->getDoubleValue("repeat", 0.0); 
61      en->latitude       = entry_node->getDoubleValue("latitude", 0.0); 
62      en->longitude      = entry_node->getDoubleValue("longitude", 0.0); 
63      en->altitude       = entry_node->getDoubleValue("altitude", 0.0); 
64      en->speed          = entry_node->getDoubleValue("speed", 0.0); 
65      en->heading        = entry_node->getDoubleValue("heading", 0.0); 
66      en->roll           = entry_node->getDoubleValue("roll", 0.0); 
67      en->azimuth        = entry_node->getDoubleValue("azimuth", 0.0); 
68      en->elevation      = entry_node->getDoubleValue("elevation", 0.0); 
69      en->rudder         = entry_node->getDoubleValue("rudder", 0.0);
70      en->strength       = entry_node->getDoubleValue("strength", 0.0);
71      en->diameter       = entry_node->getDoubleValue("diameter", 0.0);
72    }
73
74   entry_iterator = entries.begin();
75   //cout << entries.size() << " entries read." << endl;
76 }
77
78
79 FGAIScenario::~FGAIScenario()
80 {
81   entries.clear();
82 }
83
84
85 FGAIScenario::entry*
86 FGAIScenario::getNextEntry( void )
87 {
88   if (entries.size() == 0) return 0;
89   if (entry_iterator != entries.end()) {
90     return *entry_iterator++;
91   } else {
92     return 0;
93   }
94 }
95
96 int FGAIScenario::nEntries( void )
97 {
98   return entries.size();
99 }
100
101