1 #include <simgear/misc/sg_path.hxx>
2 #include <simgear/props/props.hxx>
3 #include <simgear/props/props_io.hxx>
4 #include <simgear/xml/easyxml.hxx>
6 #include <Main/globals.hxx>
10 #include "performancedb.hxx"
15 PerformanceDB::PerformanceDB()
17 SGPath dbpath( globals->get_fg_root() );
20 dbpath.append( "/AI/Aircraft/" );
21 dbpath.append( "performancedb.xml");
26 PerformanceDB::~PerformanceDB()
29 void PerformanceDB::registerPerformanceData(const std::string& id, PerformanceData* data) {
30 //TODO if key exists already replace data "inplace", i.e. copy to existing PerfData instance
31 // this updates all aircraft currently using the PerfData instance.
35 void PerformanceDB::registerPerformanceData(const std::string& id, const std::string& filename) {
36 registerPerformanceData(id, new PerformanceData(filename));
39 PerformanceData* PerformanceDB::getDataFor(const std::string& id) {
40 if (_db.find(id) == _db.end()) // id not found -> return jet_transport data
41 return _db["jet_transport"];
46 void PerformanceDB::load(SGPath filename) {
62 readProperties(filename.str(), &root);
63 } catch (const sg_exception &) {
64 SG_LOG(SG_GENERAL, SG_ALERT,
65 "Error reading AI aircraft performance database: " << filename.str());
69 SGPropertyNode * node = root.getNode("performancedb");
70 for (int i = 0; i < node->nChildren(); i++) {
71 SGPropertyNode * db_node = node->getChild(i);
72 name = db_node->getStringValue("type", "heavy_jet");
73 acceleration = db_node->getDoubleValue("acceleration-kts-hour", 4.0);
74 deceleration = db_node->getDoubleValue("deceleration-kts-hour", 2.0);
75 climbRate = db_node->getDoubleValue("climbrate-fpm", 3000.0);
76 descentRate = db_node->getDoubleValue("decentrate-fpm", 1500.0);
77 vRotate = db_node->getDoubleValue("rotate-speed-kts", 150.0);
78 vTakeOff = db_node->getDoubleValue("takeoff-speed-kts", 160.0);
79 vClimb = db_node->getDoubleValue("climb-speed-kts", 300.0);
80 vCruise = db_node->getDoubleValue("cruise-speed-kts", 430.0);
81 vDescent = db_node->getDoubleValue("decent-speed-kts", 300.0);
82 vApproach = db_node->getDoubleValue("approach-speed-kts", 170.0);
83 vTouchdown = db_node->getDoubleValue("touchdown-speed-kts", 150.0);
84 vTaxi = db_node->getDoubleValue("taxi-speed-kts", 15.0);
86 registerPerformanceData(name, new PerformanceData(
87 acceleration, deceleration, climbRate, descentRate, vRotate, vTakeOff, vClimb, vCruise, vDescent, vApproach, vTouchdown, vTaxi));