]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIScenario.cxx
Migrate FlightGear code to use "#include SG_GL*" defined in
[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   //cout << "/Data/AI/" << filename << endl;
42   path.append( ("/Data/AI/" + filename + ".xml").c_str() );
43   SGPropertyNode root;
44   readProperties(path.str(), &root);
45   //cout <<"path " << path.str() << endl;
46   try {
47       readProperties(path.str(), &root);
48   } catch (const sg_exception &e) {
49       SG_LOG(SG_GENERAL, SG_ALERT,
50        "Incorrect path specified for AI scenario: ");
51        //cout << path.str() << endl;
52       return;
53   }
54
55   entries.clear();
56   SGPropertyNode * node = root.getNode("scenario");
57   for (i = 0; i < node->nChildren(); i++) { 
58      //cout << "Reading entity data entry " << i << endl;        
59      SGPropertyNode * entry_node = node->getChild(i);
60
61      FGAIModelEntity* en = new FGAIModelEntity;
62      en->callsign       = entry_node->getStringValue("callsign", "none");
63      en->m_type         = entry_node->getStringValue("type", "aircraft");
64      en->m_class        = entry_node->getStringValue("class", "jet_transport");
65      en->path           = entry_node->getStringValue("model", "Models/Geometry/glider.ac");
66      en->flightplan     = entry_node->getStringValue("flightplan", "");
67      en->repeat         = entry_node->getDoubleValue("repeat", 0.0); 
68      en->latitude       = entry_node->getDoubleValue("latitude", 0.0); 
69      en->longitude      = entry_node->getDoubleValue("longitude", 0.0); 
70      en->altitude       = entry_node->getDoubleValue("altitude", 0.0); 
71      en->speed          = entry_node->getDoubleValue("speed", 0.0); 
72      en->heading        = entry_node->getDoubleValue("heading", 0.0); 
73      en->roll           = entry_node->getDoubleValue("roll", 0.0); 
74      en->azimuth        = entry_node->getDoubleValue("azimuth", 0.0); 
75      en->elevation      = entry_node->getDoubleValue("elevation", 0.0); 
76      en->rudder         = entry_node->getDoubleValue("rudder", 0.0);
77      en->strength       = entry_node->getDoubleValue("strength-fps", 0.0);
78      en->diameter       = entry_node->getDoubleValue("diameter-ft", 0.0);
79      en->height_msl     = entry_node->getDoubleValue("height-msl", 5000.0);
80      en->eda            = entry_node->getDoubleValue("eda", 0.007);
81      en->life           = entry_node->getDoubleValue("life", 900.0);
82      en->buoyancy       = entry_node->getDoubleValue("buoyancy", 0);
83      en->wind_from_east = entry_node->getDoubleValue("wind_from_east", 0);
84      en->wind_from_north = entry_node->getDoubleValue("wind_from_north", 0);
85      en->wind            = entry_node->getBoolValue  ("wind", false);
86      en->cd              = entry_node->getDoubleValue("cd", 0.029); 
87      en->mass            = entry_node->getDoubleValue("mass", 0.007); 
88      en->radius          = entry_node->getDoubleValue("turn-radius-ft", 2000);
89
90  /*    en->name            = entry_node->getStringValue("name", "");
91     en->x_pivot         = entry_node->getDoubleValue("x-pivot", 0.0); 
92      en->y_pivot         = entry_node->getDoubleValue("y-pivot", 0.0); 
93      en->z_pivot         = entry_node->getDoubleValue("z-pivot", 0.0); */
94      
95      en->fp             = NULL;
96      if (en->flightplan != ""){
97         en->fp = new FGAIFlightPlan( en->flightplan );
98      }
99      entries.push_back( en );
100    }
101
102   entry_iterator = entries.begin();
103   //cout << entries.size() << " entries read." << endl;
104 }
105
106
107 FGAIScenario::~FGAIScenario()
108 {
109   entries.clear();
110 }
111
112
113 FGAIModelEntity*
114 FGAIScenario::getNextEntry( void )
115 {
116   if (entries.size() == 0) return 0;
117   if (entry_iterator != entries.end()) {
118     return *entry_iterator++;
119   } else {
120     return 0;
121   }
122 }
123
124 int FGAIScenario::nEntries( void )
125 {
126   return entries.size();
127 }
128
129 // end scenario.cxx
130