]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIScenario.cxx
Make a subtle change to tile loading/unloading policy in order to make the tile
[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 <simgear/misc/sg_path.hxx>
21 #include <simgear/debug/logstream.hxx>
22 #include <simgear/structure/exception.hxx>
23 #include <simgear/constants.h>
24 #ifdef __BORLANDC__
25 #  define exception c_exception
26 #endif
27 #include <simgear/props/props.hxx>
28
29 #include <Main/globals.hxx>
30 #include <Main/fg_props.hxx>
31
32 #include "AIScenario.hxx"
33
34
35
36 FGAIScenario::FGAIScenario(string filename)
37 {
38   int i;
39   SGPath path( globals->get_fg_root() );
40   path.append( ("/Data/AI/" + filename + ".xml").c_str() );
41   SGPropertyNode root;
42
43   try {
44       readProperties(path.str(), &root);
45   } catch (const sg_exception &e) {
46       SG_LOG(SG_GENERAL, SG_ALERT,
47        "Incorrect path specified for AI scenario: ");
48        cout << path.str() << endl;
49       return;
50   }
51
52   SGPropertyNode * node = root.getNode("scenario");
53   for (i = 0; i < node->nChildren(); i++) { 
54      //cout << "Reading entry " << i << endl;        
55      FGAIModelEntity* en = new FGAIModelEntity;
56      entries.push_back( en );
57      SGPropertyNode * entry_node = node->getChild(i);
58      en->callsign       = entry_node->getStringValue("callsign", "none");
59      en->m_type         = entry_node->getStringValue("type", "aircraft");
60      en->m_class        = entry_node->getStringValue("class", "jet_transport");
61      en->path           = entry_node->getStringValue("model", "Models/Geometry/glider.ac");
62      en->flightplan     = entry_node->getStringValue("flightplan", "");
63      en->repeat         = entry_node->getDoubleValue("repeat", 0.0); 
64      en->latitude       = entry_node->getDoubleValue("latitude", 0.0); 
65      en->longitude      = entry_node->getDoubleValue("longitude", 0.0); 
66      en->altitude       = entry_node->getDoubleValue("altitude", 0.0); 
67      en->speed          = entry_node->getDoubleValue("speed", 0.0); 
68      en->heading        = entry_node->getDoubleValue("heading", 0.0); 
69      en->roll           = entry_node->getDoubleValue("roll", 0.0); 
70      en->azimuth        = entry_node->getDoubleValue("azimuth", 0.0); 
71      en->elevation      = entry_node->getDoubleValue("elevation", 0.0); 
72      en->rudder         = entry_node->getDoubleValue("rudder", 0.0);
73      en->strength       = entry_node->getDoubleValue("strength-fps", 0.0);
74      en->diameter       = entry_node->getDoubleValue("diameter-ft", 0.0);
75      en->eda            = entry_node->getDoubleValue("eda", 0.007);
76      en->life           = entry_node->getDoubleValue("life", 900.0);
77          en->buoyancy       = entry_node->getDoubleValue("buoyancy", 0);
78          en->wind_from_east = entry_node->getDoubleValue("wind_from_east", 0);
79          en->wind_from_north = entry_node->getDoubleValue("wind_from_north", 0);
80          en->wind            = entry_node->getBoolValue("wind", false);
81    }
82
83   entry_iterator = entries.begin();
84   //cout << entries.size() << " entries read." << endl;
85 }
86
87
88 FGAIScenario::~FGAIScenario()
89 {
90   entries.clear();
91 }
92
93
94 FGAIModelEntity*
95 FGAIScenario::getNextEntry( void )
96 {
97   if (entries.size() == 0) return 0;
98   if (entry_iterator != entries.end()) {
99     return *entry_iterator++;
100   } else {
101     return 0;
102   }
103 }
104
105 int FGAIScenario::nEntries( void )
106 {
107   return entries.size();
108 }
109
110