1 // fg_init.cxx -- Flight Gear top level initialization routines
3 // Written by Curtis Olson, started August 1997.
5 // Copyright (C) 1997 Curtis L. Olson - http://www.flightgear.org/~curt
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 #include <string.h> // strcmp()
33 # include <io.h> // isatty()
34 # define isatty _isatty
37 // work around a stdc++ lib bug in some versions of linux, but doesn't
38 // seem to hurt to have this here for all versions of Linux.
40 # define _G_NO_EXTERN_TEMPLATES
43 #include <simgear/compiler.h>
46 #include <boost/algorithm/string/compare.hpp>
47 #include <boost/algorithm/string/predicate.hpp>
49 #include <simgear/constants.h>
50 #include <simgear/debug/logstream.hxx>
51 #include <simgear/structure/exception.hxx>
52 #include <simgear/structure/event_mgr.hxx>
53 #include <simgear/structure/SGPerfMon.hxx>
54 #include <simgear/misc/sg_path.hxx>
55 #include <simgear/misc/sg_dir.hxx>
56 #include <simgear/misc/sgstream.hxx>
57 #include <simgear/misc/strutils.hxx>
58 #include <simgear/props/props_io.hxx>
60 #include <simgear/misc/interpolator.hxx>
61 #include <simgear/scene/material/matlib.hxx>
62 #include <simgear/scene/model/particles.hxx>
63 #include <simgear/sound/soundmgr_openal.hxx>
65 #include <Aircraft/controls.hxx>
66 #include <Aircraft/replay.hxx>
67 #include <Airports/apt_loader.hxx>
68 #include <Airports/runways.hxx>
69 #include <Airports/simple.hxx>
70 #include <Airports/dynamics.hxx>
72 #include <AIModel/AIManager.hxx>
74 #include <ATCDCL/ATISmgr.hxx>
75 #include <ATC/atc_mgr.hxx>
77 #include <Autopilot/route_mgr.hxx>
78 #include <Autopilot/autopilotgroup.hxx>
80 #include <Cockpit/panel.hxx>
81 #include <Cockpit/panel_io.hxx>
83 #include <Canvas/canvas_mgr.hxx>
84 #include <GUI/new_gui.hxx>
85 #include <Input/input.hxx>
86 #include <Instrumentation/instrument_mgr.hxx>
87 #include <Model/acmodel.hxx>
88 #include <Model/modelmgr.hxx>
89 #include <AIModel/submodel.hxx>
90 #include <AIModel/AIManager.hxx>
91 #include <Navaids/navdb.hxx>
92 #include <Navaids/navlist.hxx>
93 #include <Navaids/fix.hxx>
94 #include <Navaids/fixlist.hxx>
95 #include <Navaids/airways.hxx>
96 #include <Scenery/scenery.hxx>
97 #include <Scenery/tilemgr.hxx>
98 #include <Scripting/NasalSys.hxx>
99 #include <Sound/voice.hxx>
100 #include <Systems/system_mgr.hxx>
101 #include <Time/light.hxx>
102 #include <Traffic/TrafficMgr.hxx>
103 #include <MultiPlayer/multiplaymgr.hxx>
104 #include <FDM/fdm_shell.hxx>
105 #include <Environment/ephemeris.hxx>
106 #include <Environment/environment_mgr.hxx>
107 #include <Viewer/renderer.hxx>
108 #include <Viewer/viewmgr.hxx>
110 #include "fg_init.hxx"
112 #include "fg_commands.hxx"
113 #include "fg_props.hxx"
114 #include "options.hxx"
115 #include "globals.hxx"
116 #include "logger.hxx"
121 using namespace boost::algorithm;
124 // Return the current base package version
125 string fgBasePackageVersion() {
126 SGPath base_path( globals->get_fg_root() );
127 base_path.append("version");
129 sg_gzifstream in( base_path.str() );
130 if ( !in.is_open() ) {
131 SGPath old_path( globals->get_fg_root() );
132 old_path.append( "Thanks" );
133 sg_gzifstream old( old_path.str() );
134 if ( !old.is_open() ) {
137 return "[old version]";
149 bool fgFindAircraftInDir(const SGPath& dirPath, T* obj, bool (T::*pred)(const SGPath& p))
151 if (!dirPath.exists()) {
152 SG_LOG(SG_GENERAL, SG_WARN, "fgFindAircraftInDir: no such path:" << dirPath.str());
157 simgear::Dir dir(dirPath);
158 simgear::PathList setFiles(dir.children(simgear::Dir::TYPE_FILE, "-set.xml"));
159 simgear::PathList::iterator p;
160 for (p = setFiles.begin(); p != setFiles.end(); ++p) {
161 // check file name ends with -set.xml
163 // if we found a -set.xml at this level, don't recurse any deeper
166 bool done = (obj->*pred)(*p);
170 } // of -set.xml iteration
176 simgear::PathList subdirs(dir.children(simgear::Dir::TYPE_DIR | simgear::Dir::NO_DOT_OR_DOTDOT));
177 for (p = subdirs.begin(); p != subdirs.end(); ++p) {
178 if (p->file() == "CVS") {
182 if (fgFindAircraftInDir(*p, obj, pred)) {
185 } // of subdirs iteration
191 void fgFindAircraft(T* obj, bool (T::*pred)(const SGPath& p))
193 const string_list& paths(globals->get_aircraft_paths());
194 string_list::const_iterator it = paths.begin();
195 for (; it != paths.end(); ++it) {
196 bool done = fgFindAircraftInDir(SGPath(*it), obj, pred);
200 } // of aircraft paths iteration
202 // if we reach this point, search the default location (always last)
203 SGPath rootAircraft(globals->get_fg_root());
204 rootAircraft.append("Aircraft");
205 fgFindAircraftInDir(rootAircraft, obj, pred);
208 class FindAndCacheAircraft
211 FindAndCacheAircraft(SGPropertyNode* autoSave)
213 _cache = autoSave->getNode("sim/startup/path-cache", true);
218 std::string aircraft = fgGetString( "/sim/aircraft", "");
219 if (aircraft.empty()) {
220 SG_LOG(SG_GENERAL, SG_ALERT, "no aircraft specified");
224 _searchAircraft = aircraft + "-set.xml";
225 std::string aircraftDir = fgGetString("/sim/aircraft-dir", "");
226 if (!aircraftDir.empty()) {
227 // aircraft-dir was set, skip any searching at all, if it's valid
228 simgear::Dir acPath(aircraftDir);
229 SGPath setFile = acPath.file(_searchAircraft);
230 if (setFile.exists()) {
231 SG_LOG(SG_GENERAL, SG_INFO, "found aircraft in dir: " << aircraftDir );
234 readProperties(setFile.str(), globals->get_props());
235 } catch ( const sg_exception &e ) {
236 SG_LOG(SG_INPUT, SG_ALERT, "Error reading aircraft: " << e.getFormattedMessage());
242 SG_LOG(SG_GENERAL, SG_ALERT, "aircraft '" << _searchAircraft <<
243 "' not found in specified dir:" << aircraftDir);
249 // prepare cache for re-scan
250 SGPropertyNode *n = _cache->getNode("fg-root", true);
251 n->setStringValue(globals->get_fg_root().c_str());
252 n->setAttribute(SGPropertyNode::USERARCHIVE, true);
253 n = _cache->getNode("fg-aircraft", true);
254 n->setStringValue(getAircraftPaths().c_str());
255 n->setAttribute(SGPropertyNode::USERARCHIVE, true);
256 _cache->removeChildren("aircraft");
258 fgFindAircraft(this, &FindAndCacheAircraft::checkAircraft);
261 if (_foundPath.str().empty()) {
262 SG_LOG(SG_GENERAL, SG_ALERT, "Cannot find specified aircraft: " << aircraft );
266 SG_LOG(SG_GENERAL, SG_INFO, "Loading aircraft -set file from:" << _foundPath.str());
267 fgSetString( "/sim/aircraft-dir", _foundPath.dir().c_str());
268 if (!_foundPath.exists()) {
269 SG_LOG(SG_GENERAL, SG_ALERT, "Unable to find -set file:" << _foundPath.str());
274 readProperties(_foundPath.str(), globals->get_props());
275 } catch ( const sg_exception &e ) {
276 SG_LOG(SG_INPUT, SG_ALERT, "Error reading aircraft: " << e.getFormattedMessage());
284 SGPath getAircraftPaths() {
285 string_list pathList = globals->get_aircraft_paths();
286 SGPath aircraftPaths;
287 string_list::const_iterator it = pathList.begin();
288 if (it != pathList.end()) {
289 aircraftPaths.set(*it);
292 for (; it != pathList.end(); ++it) {
293 aircraftPaths.add(*it);
295 return aircraftPaths;
300 if (globals->get_fg_root() != _cache->getStringValue("fg-root", "")) {
301 return false; // cache mismatch
304 if (getAircraftPaths().str() != _cache->getStringValue("fg-aircraft", "")) {
305 return false; // cache mismatch
308 vector<SGPropertyNode_ptr> cache = _cache->getChildren("aircraft");
309 for (unsigned int i = 0; i < cache.size(); i++) {
310 const char *name = cache[i]->getStringValue("file", "");
311 if (!boost::equals(_searchAircraft, name, is_iequal())) {
315 SGPath xml(cache[i]->getStringValue("path", ""));
323 } // of aircraft in cache iteration
328 bool checkAircraft(const SGPath& p)
333 if (!_cache->getChild("aircraft", i++, false))
337 SGPropertyNode *n, *entry = _cache->getChild("aircraft", --i, true);
339 std::string fileName(p.file());
340 n = entry->getNode("file", true);
341 n->setStringValue(fileName);
342 n->setAttribute(SGPropertyNode::USERARCHIVE, true);
344 n = entry->getNode("path", true);
345 n->setStringValue(p.dir());
346 n->setAttribute(SGPropertyNode::USERARCHIVE, true);
348 if ( boost::equals(fileName, _searchAircraft.c_str(), is_iequal()) ) {
356 std::string _searchAircraft;
358 SGPropertyNode* _cache;
362 static SGPath platformDefaultDataPath()
364 char *envp = ::getenv( "APPDATA" );
365 SGPath config( envp );
366 config.append( "flightgear.org" );
371 #include <CoreServices/CoreServices.h>
373 static SGPath platformDefaultDataPath()
376 OSErr err = FSFindFolder(kUserDomain, kApplicationSupportFolderType, false, &ref);
381 unsigned char path[1024];
382 if (FSRefMakePath(&ref, path, 1024) != noErr) {
387 appData.set((const char*) path);
388 appData.append("FlightGear");
392 static SGPath platformDefaultDataPath()
394 SGPath config( homedir );
395 config.append( ".fgfs" );
400 // Read in configuration (file and command line)
401 bool fgInitConfig ( int argc, char **argv )
403 SGPath dataPath = platformDefaultDataPath();
405 const char *fg_home = getenv("FG_HOME");
409 simgear::Dir exportDir(simgear::Dir(dataPath).file("Export"));
410 if (!exportDir.exists()) {
411 exportDir.create(0777);
414 // Set /sim/fg-home and don't allow malign code to override it until
415 // Nasal security is set up. Use FG_HOME if necessary.
416 SGPropertyNode *home = fgGetNode("/sim", true);
417 home->removeChild("fg-home", 0, false);
418 home = home->getChild("fg-home", 0, true);
419 home->setStringValue(dataPath.c_str());
420 home->setAttribute(SGPropertyNode::WRITE, false);
422 flightgear::Options::sharedInstance()->init(argc, argv, dataPath);
424 // Read global preferences from $FG_ROOT/preferences.xml
425 SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
426 fgLoadProps("preferences.xml", globals->get_props());
427 SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
429 globals->loadUserSettings(dataPath);
431 // Scan user config files and command line for a specified aircraft.
432 flightgear::Options::sharedInstance()->initAircraft();
434 FindAndCacheAircraft f(globals->get_props());
435 if (!f.loadAircraft()) {
439 // parse options after loading aircraft to ensure any user
440 // overrides of defaults are honored.
441 flightgear::Options::sharedInstance()->processOptions();
446 // Set current tower position lon/lat given an airport id
447 static bool fgSetTowerPosFromAirportID( const string& id) {
448 const FGAirport *a = fgFindAirportID( id);
450 SGGeod tower = a->getTowerLocation();
451 fgSetDouble("/sim/tower/longitude-deg", tower.getLongitudeDeg());
452 fgSetDouble("/sim/tower/latitude-deg", tower.getLatitudeDeg());
453 fgSetDouble("/sim/tower/altitude-ft", tower.getElevationFt());
461 struct FGTowerLocationListener : SGPropertyChangeListener {
462 void valueChanged(SGPropertyNode* node) {
463 string id(node->getStringValue());
464 if (fgGetBool("/sim/tower/auto-position",true))
466 // enforce using closest airport when auto-positioning is enabled
467 const char* closest_airport = fgGetString("/sim/airport/closest-airport-id", "");
468 if (closest_airport && (id != closest_airport))
470 id = closest_airport;
471 node->setStringValue(id);
474 fgSetTowerPosFromAirportID(id);
478 struct FGClosestTowerLocationListener : SGPropertyChangeListener
480 void valueChanged(SGPropertyNode* )
482 // closest airport has changed
483 if (fgGetBool("/sim/tower/auto-position",true))
485 // update tower position
486 const char* id = fgGetString("/sim/airport/closest-airport-id", "");
488 fgSetString("/sim/tower/airport-id", id);
493 void fgInitTowerLocationListener() {
494 fgGetNode("/sim/tower/airport-id", true)
495 ->addChangeListener( new FGTowerLocationListener(), true );
496 FGClosestTowerLocationListener* ntcl = new FGClosestTowerLocationListener();
497 fgGetNode("/sim/airport/closest-airport-id", true)
498 ->addChangeListener(ntcl , true );
499 fgGetNode("/sim/tower/auto-position", true)
500 ->addChangeListener(ntcl, true );
503 static void fgApplyStartOffset(const SGGeod& aStartPos, double aHeading, double aTargetHeading = HUGE_VAL)
505 SGGeod startPos(aStartPos);
506 if (aTargetHeading == HUGE_VAL) {
507 aTargetHeading = aHeading;
510 if ( fabs( fgGetDouble("/sim/presets/offset-distance-nm") ) > SG_EPSILON ) {
511 double offsetDistance = fgGetDouble("/sim/presets/offset-distance-nm");
512 offsetDistance *= SG_NM_TO_METER;
513 double offsetAzimuth = aHeading;
514 if ( fabs(fgGetDouble("/sim/presets/offset-azimuth-deg")) > SG_EPSILON ) {
515 offsetAzimuth = fgGetDouble("/sim/presets/offset-azimuth-deg");
516 aHeading = aTargetHeading;
521 SGGeodesy::direct(startPos, offsetAzimuth + 180, offsetDistance, offset, az2);
526 fgSetDouble("/sim/presets/longitude-deg", startPos.getLongitudeDeg() );
527 fgSetDouble("/sim/presets/latitude-deg", startPos.getLatitudeDeg() );
528 fgSetDouble("/sim/presets/heading-deg", aHeading );
530 // other code depends on the actual values being set ...
531 fgSetDouble("/position/longitude-deg", startPos.getLongitudeDeg() );
532 fgSetDouble("/position/latitude-deg", startPos.getLatitudeDeg() );
533 fgSetDouble("/orientation/heading-deg", aHeading );
536 // Set current_options lon/lat given an airport id and heading (degrees)
537 bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
541 // set initial position from runway and heading
542 SG_LOG( SG_GENERAL, SG_INFO,
543 "Attempting to set starting position from airport code "
544 << id << " heading " << tgt_hdg );
546 const FGAirport* apt = fgFindAirportID(id);
547 if (!apt) return false;
548 FGRunway* r = apt->findBestRunwayForHeading(tgt_hdg);
549 fgSetString("/sim/atc/runway", r->ident().c_str());
551 SGGeod startPos = r->pointOnCenterline(fgGetDouble("/sim/airport/runways/start-offset-m", 5.0));
552 fgApplyStartOffset(startPos, r->headingDeg(), tgt_hdg);
556 // Set current_options lon/lat given an airport id and parkig position name
557 static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& parkpos ) {
561 // can't see an easy way around this const_cast at the moment
562 FGAirport* apt = const_cast<FGAirport*>(fgFindAirportID(id));
564 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to find airport " << id );
567 FGAirportDynamics* dcs = apt->getDynamics();
569 SG_LOG( SG_GENERAL, SG_ALERT,
570 "Airport " << id << "does not appear to have parking information available");
574 int park_index = dcs->getNrOfParkings() - 1;
576 double radius = fgGetDouble("/sim/dimensions/radius-m");
577 if ((parkpos == string("AVAILABLE")) && (radius > 0)) {
578 double lat, lon, heading;
583 acData = fgGetString("/sim/fg-home");
584 acData.append("aircraft-data");
585 string acfile = fgGetString("/sim/aircraft") + string(".xml");
586 acData.append(acfile);
588 readProperties(acData.str(), &root);
589 SGPropertyNode * node = root.getNode("sim");
590 fltType = node->getStringValue("aircraft-class", "NONE" );
591 acOperator = node->getStringValue("aircraft-operator", "NONE" );
592 } catch (const sg_exception &) {
593 SG_LOG(SG_GENERAL, SG_INFO,
594 "Could not load aircraft aircrat type and operator information from: " << acData.str() << ". Using defaults");
596 // cout << path.str() << endl;
598 if (fltType.empty() || fltType == "NONE") {
599 SG_LOG(SG_GENERAL, SG_INFO,
600 "Aircraft type information not found in: " << acData.str() << ". Using default value");
601 fltType = fgGetString("/sim/aircraft-class" );
603 if (acOperator.empty() || fltType == "NONE") {
604 SG_LOG(SG_GENERAL, SG_INFO,
605 "Aircraft operator information not found in: " << acData.str() << ". Using default value");
606 acOperator = fgGetString("/sim/aircraft-operator" );
609 cerr << "Running aircraft " << fltType << " of livery " << acOperator << endl;
610 string acType; // Currently not used by findAvailable parking, so safe to leave empty.
611 succes = dcs->getAvailableParking(&lat, &lon, &heading, &park_index, radius, fltType, acType, acOperator);
613 fgGetString("/sim/presets/parkpos");
614 fgSetString("/sim/presets/parkpos", dcs->getParking(park_index)->getName());
616 SG_LOG( SG_GENERAL, SG_ALERT,
617 "Failed to find a suitable parking at airport " << id );
621 //cerr << "We shouldn't get here when AVAILABLE" << endl;
622 while (park_index >= 0 && dcs->getParkingName(park_index) != parkpos) park_index--;
623 if (park_index < 0) {
624 SG_LOG( SG_GENERAL, SG_ALERT,
625 "Failed to find parking position " << parkpos <<
626 " at airport " << id );
630 FGParking* parking = dcs->getParking(park_index);
631 parking->setAvailable(false);
633 SGGeod::fromDeg(parking->getLongitude(), parking->getLatitude()),
634 parking->getHeading());
639 // Set current_options lon/lat given an airport id and runway number
640 static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy, bool rwy_req ) {
644 // set initial position from airport and runway number
645 SG_LOG( SG_GENERAL, SG_INFO,
646 "Attempting to set starting position for "
647 << id << ":" << rwy );
649 const FGAirport* apt = fgFindAirportID(id);
651 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to find airport:" << id);
655 if (!apt->hasRunwayWithIdent(rwy)) {
656 SG_LOG( SG_GENERAL, rwy_req ? SG_ALERT : SG_INFO,
657 "Failed to find runway " << rwy <<
658 " at airport " << id << ". Using default runway." );
662 FGRunway* r(apt->getRunwayByIdent(rwy));
663 fgSetString("/sim/atc/runway", r->ident().c_str());
664 SGGeod startPos = r->pointOnCenterline( fgGetDouble("/sim/airport/runways/start-offset-m", 5.0));
665 fgApplyStartOffset(startPos, r->headingDeg());
670 static void fgSetDistOrAltFromGlideSlope() {
671 // cout << "fgSetDistOrAltFromGlideSlope()" << endl;
672 string apt_id = fgGetString("/sim/presets/airport-id");
673 double gs = fgGetDouble("/sim/presets/glideslope-deg")
674 * SG_DEGREES_TO_RADIANS ;
675 double od = fgGetDouble("/sim/presets/offset-distance-nm");
676 double alt = fgGetDouble("/sim/presets/altitude-ft");
678 double apt_elev = 0.0;
679 if ( ! apt_id.empty() ) {
680 apt_elev = fgGetAirportElev( apt_id );
681 if ( apt_elev < -9990.0 ) {
688 if( fabs(gs) > 0.01 && fabs(od) > 0.1 && alt < -9990 ) {
689 // set altitude from glideslope and offset-distance
690 od *= SG_NM_TO_METER * SG_METER_TO_FEET;
691 alt = fabs(od*tan(gs)) + apt_elev;
692 fgSetDouble("/sim/presets/altitude-ft", alt);
693 fgSetBool("/sim/presets/onground", false);
694 SG_LOG( SG_GENERAL, SG_INFO, "Calculated altitude as: "
696 } else if( fabs(gs) > 0.01 && alt > 0 && fabs(od) < 0.1) {
697 // set offset-distance from glideslope and altitude
698 od = (alt - apt_elev) / tan(gs);
699 od *= -1*SG_FEET_TO_METER * SG_METER_TO_NM;
700 fgSetDouble("/sim/presets/offset-distance-nm", od);
701 fgSetBool("/sim/presets/onground", false);
702 SG_LOG( SG_GENERAL, SG_INFO, "Calculated offset distance as: "
704 } else if( fabs(gs) > 0.01 ) {
705 SG_LOG( SG_GENERAL, SG_ALERT,
706 "Glideslope given but not altitude or offset-distance." );
707 SG_LOG( SG_GENERAL, SG_ALERT, "Resetting glideslope to zero" );
708 fgSetDouble("/sim/presets/glideslope-deg", 0);
709 fgSetBool("/sim/presets/onground", true);
714 // Set current_options lon/lat given an airport id and heading (degrees)
715 static bool fgSetPosFromNAV( const string& id, const double& freq, FGPositioned::Type type ) {
717 const nav_list_type navlist
718 = globals->get_navlist()->findByIdentAndFreq( id.c_str(), freq, type );
720 if (navlist.size() == 0 ) {
721 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
722 << id << ":" << freq );
726 if( navlist.size() > 1 ) {
728 buf << "Ambigous NAV-ID: '" << id << "'. Specify id and frequency. Available stations:" << endl;
729 for( nav_list_type::const_iterator it = navlist.begin(); it != navlist.end(); ++it ) {
730 // NDB stored in kHz, VOR stored in MHz * 100 :-P
731 double factor = (*it)->type() == FGPositioned::NDB ? 1.0 : 1/100.0;
732 string unit = (*it)->type() == FGPositioned::NDB ? "kHz" : "MHz";
733 buf << (*it)->ident() << " "
734 << setprecision(5) << (double)((*it)->get_freq() * factor) << " "
735 << (*it)->get_lat() << "/" << (*it)->get_lon()
739 SG_LOG( SG_GENERAL, SG_ALERT, buf.str() );
743 FGNavRecord *nav = navlist[0];
744 fgApplyStartOffset(nav->geod(), fgGetDouble("/sim/presets/heading-deg"));
748 // Set current_options lon/lat given an aircraft carrier id
749 static bool fgSetPosFromCarrier( const string& carrier, const string& posid ) {
751 // set initial position from runway and heading
755 if (FGAIManager::getStartPosition(carrier, posid, geodPos, heading, uvw)) {
756 double lon = geodPos.getLongitudeDeg();
757 double lat = geodPos.getLatitudeDeg();
758 double alt = geodPos.getElevationFt();
760 SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
761 << carrier << " at lat = " << lat << ", lon = " << lon
762 << ", alt = " << alt << ", heading = " << heading);
764 fgSetDouble("/sim/presets/longitude-deg", lon);
765 fgSetDouble("/sim/presets/latitude-deg", lat);
766 fgSetDouble("/sim/presets/altitude-ft", alt);
767 fgSetDouble("/sim/presets/heading-deg", heading);
768 fgSetDouble("/position/longitude-deg", lon);
769 fgSetDouble("/position/latitude-deg", lat);
770 fgSetDouble("/position/altitude-ft", alt);
771 fgSetDouble("/orientation/heading-deg", heading);
773 fgSetString("/sim/presets/speed-set", "UVW");
774 fgSetDouble("/velocities/uBody-fps", uvw(0));
775 fgSetDouble("/velocities/vBody-fps", uvw(1));
776 fgSetDouble("/velocities/wBody-fps", uvw(2));
777 fgSetDouble("/sim/presets/uBody-fps", uvw(0));
778 fgSetDouble("/sim/presets/vBody-fps", uvw(1));
779 fgSetDouble("/sim/presets/wBody-fps", uvw(2));
781 fgSetBool("/sim/presets/onground", true);
785 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate aircraft carrier = "
791 // Set current_options lon/lat given an airport id and heading (degrees)
792 static bool fgSetPosFromFix( const string& id )
794 FGPositioned::TypeFilter fixFilter(FGPositioned::FIX);
795 FGPositioned* fix = FGPositioned::findNextWithPartialId(NULL, id, &fixFilter);
797 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate fix = " << id );
801 fgApplyStartOffset(fix->geod(), fgGetDouble("/sim/presets/heading-deg"));
806 * Initialize vor/ndb/ils/fix list management and query systems (as
807 * well as simple airport db list)
812 SG_LOG(SG_GENERAL, SG_INFO, "Loading Airport Database ...");
814 SGPath aptdb( globals->get_fg_root() );
815 aptdb.append( "Airports/apt.dat" );
817 SGPath p_metar( globals->get_fg_root() );
818 p_metar.append( "Airports/metar.dat" );
820 fgAirportDBLoad( aptdb.str(), p_metar.str() );
822 FGNavList *navlist = new FGNavList;
823 FGNavList *loclist = new FGNavList;
824 FGNavList *gslist = new FGNavList;
825 FGNavList *dmelist = new FGNavList;
826 FGNavList *tacanlist = new FGNavList;
827 FGNavList *carrierlist = new FGNavList;
828 FGTACANList *channellist = new FGTACANList;
830 globals->set_navlist( navlist );
831 globals->set_loclist( loclist );
832 globals->set_gslist( gslist );
833 globals->set_dmelist( dmelist );
834 globals->set_tacanlist( tacanlist );
835 globals->set_carrierlist( carrierlist );
836 globals->set_channellist( channellist );
838 if ( !fgNavDBInit(navlist, loclist, gslist, dmelist, tacanlist, carrierlist, channellist) ) {
839 SG_LOG( SG_GENERAL, SG_ALERT,
840 "Problems loading one or more navigational database" );
843 SG_LOG(SG_GENERAL, SG_INFO, " Fixes");
844 SGPath p_fix( globals->get_fg_root() );
845 p_fix.append( "Navaids/fix.dat" );
847 fixlist.init( p_fix ); // adds fixes to the DB in positioned.cxx
849 SG_LOG(SG_GENERAL, SG_INFO, " Airways");
850 flightgear::Airway::load();
856 // Set the initial position based on presets (or defaults)
857 bool fgInitPosition() {
858 // cout << "fgInitPosition()" << endl;
859 double gs = fgGetDouble("/sim/presets/glideslope-deg")
860 * SG_DEGREES_TO_RADIANS ;
861 double od = fgGetDouble("/sim/presets/offset-distance-nm");
862 double alt = fgGetDouble("/sim/presets/altitude-ft");
864 bool set_pos = false;
866 // If glideslope is specified, then calculate offset-distance or
867 // altitude relative to glide slope if either of those was not
869 if ( fabs( gs ) > 0.01 ) {
870 fgSetDistOrAltFromGlideSlope();
874 // If we have an explicit, in-range lon/lat, don't change it, just use it.
875 // If not, check for an airport-id and use that.
876 // If not, default to the middle of the KSFO field.
877 // The default values for lon/lat are deliberately out of range
878 // so that the airport-id can take effect; valid lon/lat will
879 // override airport-id, however.
880 double lon_deg = fgGetDouble("/sim/presets/longitude-deg");
881 double lat_deg = fgGetDouble("/sim/presets/latitude-deg");
882 if ( lon_deg >= -180.0 && lon_deg <= 180.0
883 && lat_deg >= -90.0 && lat_deg <= 90.0 )
888 string apt = fgGetString("/sim/presets/airport-id");
889 string rwy_no = fgGetString("/sim/presets/runway");
890 bool rwy_req = fgGetBool("/sim/presets/runway-requested");
891 string vor = fgGetString("/sim/presets/vor-id");
892 double vor_freq = fgGetDouble("/sim/presets/vor-freq");
893 string ndb = fgGetString("/sim/presets/ndb-id");
894 double ndb_freq = fgGetDouble("/sim/presets/ndb-freq");
895 string carrier = fgGetString("/sim/presets/carrier");
896 string parkpos = fgGetString("/sim/presets/parkpos");
897 string fix = fgGetString("/sim/presets/fix");
898 SGPropertyNode *hdg_preset = fgGetNode("/sim/presets/heading-deg", true);
899 double hdg = hdg_preset->getDoubleValue();
901 // save some start parameters, so that we can later say what the
902 // user really requested. TODO generalize that and move it to options.cxx
903 static bool start_options_saved = false;
904 if (!start_options_saved) {
905 start_options_saved = true;
906 SGPropertyNode *opt = fgGetNode("/sim/startup/options", true);
908 opt->setDoubleValue("latitude-deg", lat_deg);
909 opt->setDoubleValue("longitude-deg", lon_deg);
910 opt->setDoubleValue("heading-deg", hdg);
911 opt->setStringValue("airport", apt.c_str());
912 opt->setStringValue("runway", rwy_no.c_str());
916 hdg = fgGetDouble("/environment/config/boundary/entry/wind-from-heading-deg", 270);
918 if ( !set_pos && !apt.empty() && !parkpos.empty() ) {
919 // An airport + parking position is requested
920 if ( fgSetPosFromAirportIDandParkpos( apt, parkpos ) ) {
921 // set tower position
922 fgSetString("/sim/airport/closest-airport-id", apt.c_str());
923 fgSetString("/sim/tower/airport-id", apt.c_str());
928 if ( !set_pos && !apt.empty() && !rwy_no.empty() ) {
929 // An airport + runway is requested
930 if ( fgSetPosFromAirportIDandRwy( apt, rwy_no, rwy_req ) ) {
931 // set tower position (a little off the heading for single
933 fgSetString("/sim/airport/closest-airport-id", apt.c_str());
934 fgSetString("/sim/tower/airport-id", apt.c_str());
939 if ( !set_pos && !apt.empty() ) {
940 // An airport is requested (find runway closest to hdg)
941 if ( fgSetPosFromAirportIDandHdg( apt, hdg ) ) {
942 // set tower position (a little off the heading for single
944 fgSetString("/sim/airport/closest-airport-id", apt.c_str());
945 fgSetString("/sim/tower/airport-id", apt.c_str());
950 if (hdg_preset->getDoubleValue() > 9990.0)
951 hdg_preset->setDoubleValue(hdg);
953 if ( !set_pos && !vor.empty() ) {
954 // a VOR is requested
955 if ( fgSetPosFromNAV( vor, vor_freq, FGPositioned::VOR ) ) {
960 if ( !set_pos && !ndb.empty() ) {
961 // an NDB is requested
962 if ( fgSetPosFromNAV( ndb, ndb_freq, FGPositioned::NDB ) ) {
967 if ( !set_pos && !carrier.empty() ) {
968 // an aircraft carrier is requested
969 if ( fgSetPosFromCarrier( carrier, parkpos ) ) {
974 if ( !set_pos && !fix.empty() ) {
975 // a Fix is requested
976 if ( fgSetPosFromFix( fix ) ) {
982 // No lon/lat specified, no airport specified, default to
983 // middle of KSFO field.
984 fgSetDouble("/sim/presets/longitude-deg", -122.374843);
985 fgSetDouble("/sim/presets/latitude-deg", 37.619002);
988 fgSetDouble( "/position/longitude-deg",
989 fgGetDouble("/sim/presets/longitude-deg") );
990 fgSetDouble( "/position/latitude-deg",
991 fgGetDouble("/sim/presets/latitude-deg") );
992 fgSetDouble( "/orientation/heading-deg", hdg_preset->getDoubleValue());
994 // determine if this should be an on-ground or in-air start
995 if ((fabs(gs) > 0.01 || fabs(od) > 0.1 || alt > 0.1) && carrier.empty()) {
996 fgSetBool("/sim/presets/onground", false);
998 fgSetBool("/sim/presets/onground", true);
1005 // General house keeping initializations
1006 bool fgInitGeneral() {
1009 SG_LOG( SG_GENERAL, SG_INFO, "General Initialization" );
1010 SG_LOG( SG_GENERAL, SG_INFO, "======= ==============" );
1012 root = globals->get_fg_root();
1013 if ( ! root.length() ) {
1014 // No root path set? Then bail ...
1015 SG_LOG( SG_GENERAL, SG_ALERT,
1016 "Cannot continue without a path to the base package "
1017 << "being defined." );
1020 SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
1022 globals->set_browser(fgGetString("/sim/startup/browser-app", "firefox %u"));
1024 simgear::Dir cwd(simgear::Dir::current());
1025 SGPropertyNode *curr = fgGetNode("/sim", true);
1026 curr->removeChild("fg-current", 0, false);
1027 curr = curr->getChild("fg-current", 0, true);
1028 curr->setStringValue(cwd.path().str());
1029 curr->setAttribute(SGPropertyNode::WRITE, false);
1031 fgSetBool("/sim/startup/stdout-to-terminal", isatty(1) != 0 );
1032 fgSetBool("/sim/startup/stderr-to-terminal", isatty(2) != 0 );
1036 // This is the top level init routine which calls all the other
1037 // initialization routines. If you are adding a subsystem to flight
1038 // gear, its initialization call should located in this routine.
1039 // Returns non-zero if a problem encountered.
1040 bool fgInitSubsystems() {
1042 SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
1043 SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
1045 ////////////////////////////////////////////////////////////////////
1046 // Initialize the sound subsystem.
1047 ////////////////////////////////////////////////////////////////////
1048 // Sound manager uses an own subsystem group "SOUND" which is the last
1049 // to be updated in every loop.
1050 // Sound manager is updated last so it can use the CPU while the GPU
1051 // is processing the scenery (doubled the frame-rate for me) -EMH-
1052 globals->add_subsystem("sound", new SGSoundMgr, SGSubsystemMgr::SOUND);
1054 ////////////////////////////////////////////////////////////////////
1055 // Initialize the event manager subsystem.
1056 ////////////////////////////////////////////////////////////////////
1058 globals->get_event_mgr()->init();
1059 globals->get_event_mgr()->setRealtimeProperty(fgGetNode("/sim/time/delta-realtime-sec", true));
1061 ////////////////////////////////////////////////////////////////////
1062 // Initialize the property interpolator subsystem. Put into the INIT
1063 // group because the "nasal" subsystem may need it at GENERAL take-down.
1064 ////////////////////////////////////////////////////////////////////
1065 globals->add_subsystem("interpolator", new SGInterpolator, SGSubsystemMgr::INIT);
1068 ////////////////////////////////////////////////////////////////////
1069 // Add the FlightGear property utilities.
1070 ////////////////////////////////////////////////////////////////////
1071 globals->add_subsystem("properties", new FGProperties);
1074 ////////////////////////////////////////////////////////////////////
1075 // Add the performance monitoring system.
1076 ////////////////////////////////////////////////////////////////////
1077 globals->add_subsystem("performance-mon",
1078 new SGPerformanceMonitor(globals->get_subsystem_mgr(),
1079 fgGetNode("/sim/performance-monitor", true)));
1081 ////////////////////////////////////////////////////////////////////
1082 // Initialize the material property subsystem.
1083 ////////////////////////////////////////////////////////////////////
1085 SGPath mpath( globals->get_fg_root() );
1086 mpath.append( fgGetString("/sim/rendering/materials-file") );
1087 if ( ! globals->get_matlib()->load(globals->get_fg_root(), mpath.str(),
1088 globals->get_props()) ) {
1089 SG_LOG( SG_GENERAL, SG_ALERT,
1090 "Error loading materials file " << mpath.str() );
1095 ////////////////////////////////////////////////////////////////////
1096 // Initialize the scenery management subsystem.
1097 ////////////////////////////////////////////////////////////////////
1099 globals->get_scenery()->get_scene_graph()
1100 ->addChild(simgear::Particles::getCommonRoot());
1101 simgear::GlobalParticleCallback::setSwitch(fgGetNode("/sim/rendering/particles", true));
1103 ////////////////////////////////////////////////////////////////////
1104 // Initialize the flight model subsystem.
1105 ////////////////////////////////////////////////////////////////////
1107 globals->add_subsystem("flight", new FDMShell, SGSubsystemMgr::FDM);
1109 ////////////////////////////////////////////////////////////////////
1110 // Initialize the weather subsystem.
1111 ////////////////////////////////////////////////////////////////////
1113 // Initialize the weather modeling subsystem
1114 globals->add_subsystem("environment", new FGEnvironmentMgr);
1115 globals->add_subsystem("ephemeris", new Ephemeris);
1117 ////////////////////////////////////////////////////////////////////
1118 // Initialize the aircraft systems and instrumentation (before the
1120 ////////////////////////////////////////////////////////////////////
1122 globals->add_subsystem("instrumentation", new FGInstrumentMgr, SGSubsystemMgr::FDM);
1123 globals->add_subsystem("systems", new FGSystemMgr, SGSubsystemMgr::FDM);
1125 ////////////////////////////////////////////////////////////////////
1126 // Initialize the XML Autopilot subsystem.
1127 ////////////////////////////////////////////////////////////////////
1129 globals->add_subsystem( "xml-autopilot", FGXMLAutopilotGroup::createInstance("autopilot"), SGSubsystemMgr::FDM );
1130 globals->add_subsystem( "xml-proprules", FGXMLAutopilotGroup::createInstance("property-rule"), SGSubsystemMgr::GENERAL );
1131 globals->add_subsystem( "route-manager", new FGRouteMgr );
1133 ////////////////////////////////////////////////////////////////////
1134 // Initialize the Input-Output subsystem
1135 ////////////////////////////////////////////////////////////////////
1136 globals->add_subsystem( "io", new FGIO );
1138 ////////////////////////////////////////////////////////////////////
1139 // Create and register the logger.
1140 ////////////////////////////////////////////////////////////////////
1142 globals->add_subsystem("logger", new FGLogger);
1144 ////////////////////////////////////////////////////////////////////
1145 // Create and register the XML GUI.
1146 ////////////////////////////////////////////////////////////////////
1148 globals->add_subsystem("gui", new NewGUI, SGSubsystemMgr::INIT);
1150 //////////////////////////////////////////////////////////////////////
1151 // Initialize the 2D cloud subsystem.
1152 ////////////////////////////////////////////////////////////////////
1153 fgGetBool("/sim/rendering/bump-mapping", false);
1155 ////////////////////////////////////////////////////////////////////
1156 // Initialize the canvas 2d drawing subsystem.
1157 ////////////////////////////////////////////////////////////////////
1158 globals->add_subsystem("Canvas2D", new CanvasMgr, SGSubsystemMgr::DISPLAY);
1160 ////////////////////////////////////////////////////////////////////
1161 // Initialise the ATIS Manager
1162 // Note that this is old stuff, but is necessary for the
1163 // current ATIS implementation. Therefore, leave it in here
1164 // until the ATIS system is ported over to make use of the ATIS
1165 // sub system infrastructure.
1166 ////////////////////////////////////////////////////////////////////
1168 globals->add_subsystem("ATIS", new FGATISMgr, SGSubsystemMgr::INIT, 0.4);
1170 ////////////////////////////////////////////////////////////////////
1171 // Initialize the ATC subsystem
1172 ////////////////////////////////////////////////////////////////////
1173 globals->add_subsystem("ATC", new FGATCManager, SGSubsystemMgr::POST_FDM);
1175 ////////////////////////////////////////////////////////////////////
1176 // Initialize multiplayer subsystem
1177 ////////////////////////////////////////////////////////////////////
1179 globals->add_subsystem("mp", new FGMultiplayMgr, SGSubsystemMgr::POST_FDM);
1181 ////////////////////////////////////////////////////////////////////
1182 // Initialise the AI Model Manager
1183 ////////////////////////////////////////////////////////////////////
1184 SG_LOG(SG_GENERAL, SG_INFO, " AI Model Manager");
1185 globals->add_subsystem("ai-model", new FGAIManager, SGSubsystemMgr::POST_FDM);
1186 globals->add_subsystem("submodel-mgr", new FGSubmodelMgr, SGSubsystemMgr::POST_FDM);
1189 // It's probably a good idea to initialize the top level traffic manager
1190 // After the AI and ATC systems have been initialized properly.
1191 // AI Traffic manager
1192 globals->add_subsystem("traffic-manager", new FGTrafficManager, SGSubsystemMgr::POST_FDM);
1194 ////////////////////////////////////////////////////////////////////
1195 // Add a new 2D panel.
1196 ////////////////////////////////////////////////////////////////////
1198 fgSetArchivable("/sim/panel/visibility");
1199 fgSetArchivable("/sim/panel/x-offset");
1200 fgSetArchivable("/sim/panel/y-offset");
1201 fgSetArchivable("/sim/panel/jitter");
1203 ////////////////////////////////////////////////////////////////////
1204 // Initialize the controls subsystem.
1205 ////////////////////////////////////////////////////////////////////
1207 globals->get_controls()->init();
1208 globals->get_controls()->bind();
1211 ////////////////////////////////////////////////////////////////////
1212 // Initialize the input subsystem.
1213 ////////////////////////////////////////////////////////////////////
1215 globals->add_subsystem("input", new FGInput);
1218 ////////////////////////////////////////////////////////////////////
1219 // Initialize the replay subsystem
1220 ////////////////////////////////////////////////////////////////////
1221 globals->add_subsystem("replay", new FGReplay);
1223 #ifdef ENABLE_AUDIO_SUPPORT
1224 ////////////////////////////////////////////////////////////////////
1225 // Initialize the sound-effects subsystem.
1226 ////////////////////////////////////////////////////////////////////
1227 globals->add_subsystem("voice", new FGVoiceMgr, SGSubsystemMgr::DISPLAY);
1230 ////////////////////////////////////////////////////////////////////
1231 // Initialize the lighting subsystem.
1232 ////////////////////////////////////////////////////////////////////
1234 globals->add_subsystem("lighting", new FGLight, SGSubsystemMgr::DISPLAY);
1236 // ordering here is important : Nasal (via events), then models, then views
1237 globals->add_subsystem("events", globals->get_event_mgr(), SGSubsystemMgr::DISPLAY);
1239 FGAircraftModel* acm = new FGAircraftModel;
1240 globals->set_aircraft_model(acm);
1241 globals->add_subsystem("aircraft-model", acm, SGSubsystemMgr::DISPLAY);
1243 FGModelMgr* mm = new FGModelMgr;
1244 globals->set_model_mgr(mm);
1245 globals->add_subsystem("model-manager", mm, SGSubsystemMgr::DISPLAY);
1247 FGViewMgr *viewmgr = new FGViewMgr;
1248 globals->set_viewmgr( viewmgr );
1249 globals->add_subsystem("view-manager", viewmgr, SGSubsystemMgr::DISPLAY);
1251 globals->add_subsystem("tile-manager", globals->get_tile_mgr(),
1252 SGSubsystemMgr::DISPLAY);
1254 ////////////////////////////////////////////////////////////////////
1255 // Bind and initialize subsystems.
1256 ////////////////////////////////////////////////////////////////////
1258 globals->get_subsystem_mgr()->bind();
1259 globals->get_subsystem_mgr()->init();
1261 ////////////////////////////////////////////////////////////////////////
1262 // Initialize the Nasal interpreter.
1263 // Do this last, so that the loaded scripts see initialized state
1264 ////////////////////////////////////////////////////////////////////////
1265 FGNasalSys* nasal = new FGNasalSys();
1266 globals->add_subsystem("nasal", nasal, SGSubsystemMgr::INIT);
1269 // initialize methods that depend on other subsystems.
1270 globals->get_subsystem_mgr()->postinit();
1272 ////////////////////////////////////////////////////////////////////
1273 // TODO FIXME! UGLY KLUDGE!
1274 ////////////////////////////////////////////////////////////////////
1276 /* Scenarios require Nasal, so FGAIManager loads the scenarios,
1277 * including its models such as a/c carriers, in its 'postinit',
1278 * which is the very last thing we do.
1279 * fgInitPosition is called very early in main.cxx/fgIdleFunction,
1280 * one of the first things we do, long before scenarios/carriers are
1281 * loaded. => When requested "initial preset position" relates to a
1282 * carrier, recalculate the 'initial' position here (how have things
1283 * ever worked before this hack - this init sequence has always been
1285 std::string carrier = fgGetString("/sim/presets/carrier","");
1288 // clear preset location and re-trigger position setup
1289 fgSetDouble("/sim/presets/longitude-deg", 9999);
1290 fgSetDouble("/sim/presets/latitude-deg", 9999);
1295 ////////////////////////////////////////////////////////////////////////
1296 // End of subsystem initialization.
1297 ////////////////////////////////////////////////////////////////////
1299 fgSetBool("/sim/crashed", false);
1300 fgSetBool("/sim/initialized", true);
1302 SG_LOG( SG_GENERAL, SG_INFO, endl);
1304 // Save the initial state for future
1306 globals->saveInitialState();
1311 // Reset: this is what the 'reset' command (and hence, GUI) is attached to
1312 void fgReInitSubsystems()
1314 static const SGPropertyNode *master_freeze
1315 = fgGetNode("/sim/freeze/master");
1317 SG_LOG( SG_GENERAL, SG_INFO, "fgReInitSubsystems()");
1319 // setup state to begin re-init
1320 bool freeze = master_freeze->getBoolValue();
1322 fgSetBool("/sim/freeze/master", true);
1325 fgSetBool("/sim/signals/reinit", true);
1326 fgSetBool("/sim/crashed", false);
1328 // do actual re-init steps
1329 globals->get_subsystem("flight")->unbind();
1331 // reset control state, before restoring initial state; -set or config files
1332 // may specify values for flaps, trim tabs, magnetos, etc
1333 globals->get_controls()->reset_all();
1335 globals->restoreInitialState();
1337 // update our position based on current presets
1340 // Force reupdating the positions of the ai 3d models. They are used for
1341 // initializing ground level for the FDM.
1342 globals->get_subsystem("ai-model")->reinit();
1344 // Initialize the FDM
1345 globals->get_subsystem("flight")->reinit();
1347 // reset replay buffers
1348 globals->get_subsystem("replay")->reinit();
1350 // reload offsets from config defaults
1351 globals->get_viewmgr()->reinit();
1353 globals->get_subsystem("time")->reinit();
1355 // need to bind FDMshell again, since we manually unbound it above...
1356 globals->get_subsystem("flight")->bind();
1358 // setup state to end re-init
1359 fgSetBool("/sim/signals/reinit", false);
1361 fgSetBool("/sim/freeze/master", false);
1363 fgSetBool("/sim/sceneryloaded",false);
1367 ///////////////////////////////////////////////////////////////////////////////
1368 // helper object to implement the --show-aircraft command.
1369 // resides here so we can share the fgFindAircraftInDir template above,
1370 // and hence ensure this command lists exectly the same aircraft as the normal
1377 _minStatus = getNumMaturity(fgGetString("/sim/aircraft-min-status", "all"));
1381 void show(const SGPath& path)
1383 fgFindAircraftInDir(path, this, &ShowAircraft::processAircraft);
1385 std::sort(_aircraft.begin(), _aircraft.end(), ciLessLibC());
1386 SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on Windows
1387 cout << "Available aircraft:" << endl;
1388 for ( unsigned int i = 0; i < _aircraft.size(); i++ ) {
1389 cout << _aircraft[i] << endl;
1394 bool processAircraft(const SGPath& path)
1396 SGPropertyNode root;
1398 readProperties(path.str(), &root);
1399 } catch (sg_exception& ) {
1404 string descStr(" ");
1405 descStr += path.file();
1406 // trim common suffix from file names
1407 int nPos = descStr.rfind("-set.xml");
1408 if (nPos == (int)(descStr.size() - 8)) {
1409 descStr.resize(nPos);
1412 SGPropertyNode *node = root.getNode("sim");
1414 SGPropertyNode* desc = node->getNode("description");
1415 // if a status tag is found, read it in
1416 if (node->hasValue("status")) {
1417 maturity = getNumMaturity(node->getStringValue("status"));
1421 if (descStr.size() <= 27+3) {
1422 descStr.append(29+3-descStr.size(), ' ');
1425 descStr.append( 32, ' ');
1427 descStr += desc->getStringValue();
1429 } // of have 'sim' node
1431 if (maturity < _minStatus) {
1435 _aircraft.push_back(descStr);
1440 int getNumMaturity(const char * str)
1442 // changes should also be reflected in $FG_ROOT/data/options.xml &
1443 // $FG_ROOT/data/Translations/string-default.xml
1444 const char* levels[] = {"alpha","beta","early-production","production"};
1446 if (!strcmp(str, "all")) {
1450 for (size_t i=0; i<(sizeof(levels)/sizeof(levels[0]));i++)
1451 if (strcmp(str,levels[i])==0)
1457 // recommended in Meyers, Effective STL when internationalization and embedded
1458 // NULLs aren't an issue. Much faster than the STL or Boost lex versions.
1459 struct ciLessLibC : public std::binary_function<string, string, bool>
1461 bool operator()(const std::string &lhs, const std::string &rhs) const
1463 return strcasecmp(lhs.c_str(), rhs.c_str()) < 0 ? 1 : 0;
1468 string_list _aircraft;
1471 void fgShowAircraft(const SGPath &path)
1477 cout << "Hit a key to continue..." << endl;