X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FAIModel%2Fperformancedb.cxx;h=f218e851dab340f809f3b7d4f382009c47d7f01d;hb=7d547d128702a643c40b54809e2b4e1a38c4a16d;hp=f7c286a9a345b8aea1d73ff6d5b9160f151a89b6;hpb=ad9366ed99bdd16980cbcecdefda92bc2bc2aa0f;p=flightgear.git diff --git a/src/AIModel/performancedb.cxx b/src/AIModel/performancedb.cxx index f7c286a9a..f218e851d 100644 --- a/src/AIModel/performancedb.cxx +++ b/src/AIModel/performancedb.cxx @@ -1,4 +1,11 @@ -#include +#ifdef HAVE_CONFIG_H + #include "config.h" +#endif + +#include "performancedb.hxx" + +#include + #include #include #include @@ -8,7 +15,7 @@ #include #include -#include "performancedb.hxx" +#include "performancedata.hxx" using std::string; using std::cerr; @@ -37,14 +44,28 @@ void PerformanceDB::registerPerformanceData(const std::string& id, const std::st registerPerformanceData(id, new PerformanceData(filename)); } -PerformanceData* PerformanceDB::getDataFor(const std::string& id) { - if (_db.find(id) == _db.end()) // id not found -> return jet_transport data +PerformanceData* PerformanceDB::getDataFor(const string& acType, const string& acClass) +{ + // first, try with the specific aircraft type, such as 738 or A322 + if (_db.find(acType) != _db.end()) { + return _db[acType]; + } + + string alias = findAlias(acType); + if (_db.find(alias) != _db.end()) { + return _db[alias]; + } + + SG_LOG(SG_AI, SG_INFO, "no performance data for " << acType); + + if (_db.find(acClass) == _db.end()) { return _db["jet_transport"]; - - return _db[id]; + } + + return _db[acClass]; } -void PerformanceDB::load(SGPath filename) { +void PerformanceDB::load(const SGPath& filename) { string name; double acceleration; double deceleration; @@ -62,14 +83,15 @@ void PerformanceDB::load(SGPath filename) { try { readProperties(filename.str(), &root); } catch (const sg_exception &) { - SG_LOG(SG_GENERAL, SG_ALERT, + SG_LOG(SG_AI, SG_ALERT, "Error reading AI aircraft performance database: " << filename.str()); return; } SGPropertyNode * node = root.getNode("performancedb"); - for (int i = 0; i < node->nChildren(); i++) { + for (int i = 0; i < node->nChildren(); i++) { SGPropertyNode * db_node = node->getChild(i); + if (!strcmp(db_node->getName(), "aircraft")) { name = db_node->getStringValue("type", "heavy_jet"); acceleration = db_node->getDoubleValue("acceleration-kts-hour", 4.0); deceleration = db_node->getDoubleValue("deceleration-kts-hour", 2.0); @@ -86,6 +108,32 @@ void PerformanceDB::load(SGPath filename) { registerPerformanceData(name, new PerformanceData( acceleration, deceleration, climbRate, descentRate, vRotate, vTakeOff, vClimb, vCruise, vDescent, vApproach, vTouchdown, vTaxi)); - } + } else if (!strcmp(db_node->getName(), "alias")) { + string alias(db_node->getStringValue("alias")); + if (alias.empty()) { + SG_LOG(SG_AI, SG_ALERT, "performance DB alias entry with no definition"); + continue; + } + + BOOST_FOREACH(SGPropertyNode* matchNode, db_node->getChildren("match")) { + string match(matchNode->getStringValue()); + _aliases.push_back(StringPair(match, alias)); + } + } else { + SG_LOG(SG_AI, SG_ALERT, "unrecognized performance DB entry:" << db_node->getName()); + } + } // of nodes iteration } +string PerformanceDB::findAlias(const string& acType) const +{ + BOOST_FOREACH(const StringPair& alias, _aliases) { + if (acType.find(alias.first) == 0) { // matched! + return alias.second; + } + } // of alias iteration + + return string(); +} + +