From 9b05b2f941e8dad0a281a12a7c6e9eab1fcfa30f Mon Sep 17 00:00:00 2001 From: Michael Danilov Date: Sun, 19 Sep 2021 10:38:18 +0100 Subject: [PATCH] src/Instrumentation/tcas.*: improved treatment of AI, MP and Swift aircraft. Change the assumption that velocity < 40kt implies the transponder is off, to only apply to AI aircraft, because exact information is available for other (i.e. multiplayer and swift) aircraft. Add new check for multiplayer/swift aircraft where if the altitude is -9999, we treat the transponder as off. With swift and multiplayer aircraft, use the transponder altitude information, not the sim's internal altitude data for the aircraft. --- src/Instrumentation/tcas.cxx | 44 +++++++++++++++++++++++------------- src/Instrumentation/tcas.hxx | 1 + 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/Instrumentation/tcas.cxx b/src/Instrumentation/tcas.cxx index 6900560b1..4520977fd 100644 --- a/src/Instrumentation/tcas.cxx +++ b/src/Instrumentation/tcas.cxx @@ -586,27 +586,39 @@ bool TCAS::ThreatDetector::checkTransponder(const SGPropertyNode* pModel, float velocityKt) { const string name = pModel->getName(); - if (name != "multiplayer" && name != "aircraft" && name != "swift") + if (name == "aircraft") { - // assume non-MP/non-AI planes (e.g. ships) have no transponder - return false; - } - - if (velocityKt < 40) - { - /* assume all pilots have their transponder switched off while taxiing/parking + /* assume all non-MP and non-Swift aircraft have their transponder switched off while taxiing/parking * (at low speed) */ - return false; + return velocityKt >= 40.0; } - - if ((name == "multiplayer")&& - (pModel->getBoolValue("controls/invisible"))) + else if (pModel->getIntValue("instrumentation/transponder/altitude", -9999) != -9999) { - // ignored MP plane: pretend transponder is switched off - return false; + // must have Mode C (altitude) transponder to be visible. + // "-9999" is a special value used by src/Instrumentation/transponder.cxx to indicate the non-transmission of a value. + if (name == "multiplayer") + { + // ignored MP plane: pretend transponder is switched off + return !(pModel->getBoolValue("controls/invisible")); + } + if (name == "swift"){ + return true; + } } + // assume non-MP/non-AI planes (e.g. ships) have no transponder + return false; +} - return true; +/** Get altitude reported by transponder. */ +float +TCAS::ThreatDetector::getAltitude(const SGPropertyNode* pModel) +{ + const string name = pModel->getName(); + if (name == "multiplayer" || name == "swift") + { + return pModel->getIntValue("instrumentation/transponder/altitude"); + } + return pModel->getDoubleValue("position/altitude-ft"); } /** Check if plane is a threat. */ @@ -625,7 +637,7 @@ TCAS::ThreatDetector::checkThreat(int mode, const SGPropertyNode* pModel) return ThreatInvisible; int threatLevel = ThreatNone; - float altFt = pModel->getDoubleValue("position/altitude-ft"); + float altFt = getAltitude(pModel); currentThreat.relativeAltitudeFt = altFt - self.pressureAltFt; // save computation time: don't care when relative altitude is excessive diff --git a/src/Instrumentation/tcas.hxx b/src/Instrumentation/tcas.hxx index 1f0c5d543..08ecacdf0 100644 --- a/src/Instrumentation/tcas.hxx +++ b/src/Instrumentation/tcas.hxx @@ -317,6 +317,7 @@ class TCAS : public SGSubsystem void update (void); bool checkTransponder (const SGPropertyNode* pModel, float velocityKt); + float getAltitude (const SGPropertyNode* pModel); int checkThreat (int mode, const SGPropertyNode* pModel); void checkVerticalThreat (void); void horizontalThreat (float bearing, float distanceNm, float heading,