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