]> git.mxchange.org Git - flightgear.git/commitdiff
Allow the AI Traffic controller to set a transponder code. This code is
authordurk <durk>
Sun, 22 Mar 2009 13:49:51 +0000 (13:49 +0000)
committerTim Moore <timoore@redhat.com>
Wed, 1 Apr 2009 07:23:54 +0000 (09:23 +0200)
used in ATC chatter, and writted to the property, so it can -in principle-
be picked up by the radar.

src/AIModel/AIAircraft.cxx
src/AIModel/AIAircraft.hxx
src/ATC/trafficcontrol.cxx
src/ATC/trafficcontrol.hxx

index e7258d60eacc85ac23b334a0038165d4c4f030f3..6559bbcbd7ffee1c014d01c772b3feec8e7822c5 100644 (file)
@@ -113,6 +113,9 @@ void FGAIAircraft::bind() {
     props->tie("controls/gear/gear-down",
                SGRawValueMethods<FGAIAircraft,bool>(*this,
                                                     &FGAIAircraft::_getGearDown));
+    props->tie("transponder-id",
+               SGRawValueMethods<FGAIAircraft,const char*>(*this,
+                                                    &FGAIAircraft::_getTransponderCode));
 }
 
 
@@ -120,6 +123,7 @@ void FGAIAircraft::unbind() {
     FGAIBase::unbind();
 
     props->untie("controls/gear/gear-down");
+    props->untie("transponder-id");
 }
 
 
@@ -343,6 +347,11 @@ bool FGAIAircraft::_getGearDown() const {
 }
 
 
+const char * FGAIAircraft::_getTransponderCode() const {
+  return transponderCode.c_str();
+}
+
+
 bool FGAIAircraft::loadNextLeg() {
 
     int leg;
index fd4fd2ad0813c2423006304b6ef6ccc4c823a613..49639799a19de71d367330e0f201e5a64517dfb0 100644 (file)
@@ -75,6 +75,9 @@ public:
 
     virtual const char* getTypeString(void) const { return "aircraft"; }
 
+    string GetTransponderCode() { return transponderCode; };
+    void SetTransponderCode(string tc) { transponderCode = tc;};
+
     // included as performance data needs them, who else?
     inline PerformanceData* getPerformance() { return _performance; };
     inline bool onGround() const { return no_roll; };
@@ -133,6 +136,7 @@ private:
 
     string acType;
     string company;
+    string transponderCode;
 
     int spinCounter;
     double prevSpeed;
@@ -142,6 +146,8 @@ private:
 
     bool _getGearDown() const;
 
+    const char * _getTransponderCode() const;
+
     bool reachedWaypoint;
     time_t timeElapsed;
 
index c8657ba1d0e910c678a3abac7c9481ad8607a812..0d08fb52aa984c9feb332d7f2bda2c91e43e85f9 100644 (file)
@@ -385,7 +385,9 @@ void FGATCController::transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir m
     string fltType;
     string rwyClass;
     string SID;
+    string transponderCode;
     FGAIFlightPlan *fp;
+    string fltRules;
     switch (msgId) {
           case MSG_ANNOUNCE_ENGINE_START:
                text = sender + ". Ready to Start up";
@@ -416,8 +418,11 @@ void FGATCController::transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir m
                    SID = "fly runway heading ";
                }
                //snprintf(buffer, 7, "%3.2f", heading);
+               fltRules = rec->getAircraft()->getTrafficRef()->getFlightRules();
+               transponderCode = genTransponderCode(fltRules);
+               rec->getAircraft()->SetTransponderCode(transponderCode);
                text = receiver + ". Start-up approved. " + atisInformation + " correct, runway " + activeRunway
-                       + ", " + SID + ", squawk BBBB. " +
+                       + ", " + SID + ", squawk " + transponderCode + ". " +
                       "For push-back and taxi clearance call " + taxiFreqStr + ". " + sender + " control.";
                break;
           case MSG_DENY_ENGINE_START:
@@ -432,8 +437,9 @@ void FGATCController::transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir m
                }
                taxiFreqStr = formatATCFrequency3_2(taxiFreq);
                activeRunway = rec->getAircraft()->GetFlightPlan()->getRunway();
+               transponderCode = rec->getAircraft()->GetTransponderCode();
                text = receiver + ". Start-up approved. " + atisInformation + " correct, runway " +
-                      activeRunway + ", " + SID + ", squawk BBBB. " +
+                      activeRunway + ", " + SID + ", squawk " + transponderCode + ". " +
                       "For push-back and taxi clearance call " + taxiFreqStr + ". " + sender;
                break;
            default:
@@ -461,6 +467,16 @@ string FGATCController::formatATCFrequency3_2(int freq) {
     return string(buffer);
 }
 
+string FGATCController::genTransponderCode(string fltRules) {
+    if (fltRules == "VFR") {
+        return string("1200");
+    } else {
+        char buffer[5];
+        snprintf(buffer, 5, "%d%d%d%d", rand() % 8, rand() % 8,rand() % 8, rand() % 8);
+        return string(buffer);
+    }
+}
+
 /***************************************************************************
  * class FGTowerController
  *
index 850a0f930c6fa1c81867b69bc6633a4d04c60da4..7ca8e88bf42cd04fe5ccb96f72151567741a8414 100644 (file)
@@ -207,6 +207,7 @@ private:
 
 
   string formatATCFrequency3_2(int );
+  string genTransponderCode(string fltRules);
 
 public:
   typedef enum {