]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIScenario.cxx
Boris Koenig:
[flightgear.git] / src / AIModel / AIScenario.cxx
1 // FGAIScenario.cxx - 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 #include "AIFlightPlan.hxx"
34
35
36
37 FGAIScenario::FGAIScenario(string &filename)
38 {
39   int i;
40   SGPath path( globals->get_fg_root() );
41   path.append( ("/Data/AI/" + filename + ".xml").c_str() );
42   SGPropertyNode root;
43
44   try {
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;
50       return;
51   }
52
53   entries.clear();
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);
58
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->mass            = entry_node->getDoubleValue  ("mass", 0.007); 
85
86
87      en->fp             = NULL;
88      if (en->flightplan != ""){
89         en->fp = new FGAIFlightPlan( en->flightplan );
90      }
91      entries.push_back( en );
92    }
93
94   entry_iterator = entries.begin();
95   //cout << entries.size() << " entries read." << endl;
96 }
97
98
99 FGAIScenario::~FGAIScenario()
100 {
101   entries.clear();
102 }
103
104
105 FGAIModelEntity*
106 FGAIScenario::getNextEntry( void )
107 {
108   if (entries.size() == 0) return 0;
109   if (entry_iterator != entries.end()) {
110     return *entry_iterator++;
111   } else {
112     return 0;
113   }
114 }
115
116 int FGAIScenario::nEntries( void )
117 {
118   return entries.size();
119 }
120
121 // end scenario.cxx
122