]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/trafficcontrol.cxx
Fix MSVC compilation
[flightgear.git] / src / ATC / trafficcontrol.cxx
index 0f7b868575ad594f440e8ad4a2df879a5de2ea41..57f718812ce242bbf680a8eb9371ffd278e3b3fa 100644 (file)
@@ -248,7 +248,7 @@ bool FGTrafficRecord::isOpposing (FGGroundNetwork *net, FGTrafficRecord &other,
       
        for (intVecIterator i = intentions.begin(); i != intentions.end(); i++)
        {
-         if (opp = net->findSegment(other.currentPos)->opposite())
+         if ((opp = net->findSegment(other.currentPos)->opposite()))
            {
              if ((*i) > 0)
                if (opp->getIndex() == net->findSegment(*i)->getIndex())
@@ -267,7 +267,7 @@ bool FGTrafficRecord::isOpposing (FGGroundNetwork *net, FGTrafficRecord &other,
                {  
                  // cerr << "Current segment 1 " << (*i) << endl;
                  if ((*i) > 0) {
-                   if (opp = net->findSegment(*i)->opposite())
+                   if ((opp = net->findSegment(*i)->opposite()))
                      {
                        if (opp->getIndex() == 
                            net->findSegment(*j)->getIndex())
@@ -318,9 +318,9 @@ FGATCInstruction::FGATCInstruction()
   changeAltitude = false;
   resolveCircularWait = false;
 
-  double speed   = 0;
-  double heading = 0;
-  double alt     = 0;
+  speed   = 0;
+  heading = 0;
+  alt     = 0;
 }
 
 bool FGATCInstruction::hasInstruction()
@@ -337,18 +337,21 @@ void FGATCController::transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir m
 {
     string sender, receiver;
     int stationFreq = 0;
+    int taxiFreq    = 0;
+    string atisInformation;
     //double commFreqD;
     switch (msgDir) {
          case ATC_AIR_TO_GROUND:
              sender = rec->getAircraft()->getTrafficRef()->getCallSign();
              switch (rec->getLeg()) {
                  case 2:
+                 case 3:
                      stationFreq =
-                        rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getDynamics()->getGroundFrequency();
-                     receiver = rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getName() + "-Ground";
-                     break;
-                 case 3: 
+                        rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getDynamics()->getGroundFrequency(rec->getLeg());
+                     taxiFreq =
+                        rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getDynamics()->getGroundFrequency(3);
                      receiver = rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getName() + "-Ground";
+                     atisInformation = rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getDynamics()->getAtisInformation();
                      break;
                  case 4: 
                      receiver = rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getName() + "-Tower";
@@ -359,13 +362,15 @@ void FGATCController::transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir m
              receiver = rec->getAircraft()->getTrafficRef()->getCallSign();
              switch (rec->getLeg()) {
                  case 2:
+                 case 3:
                  stationFreq =
-                        rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getDynamics()->getGroundFrequency();
-                     sender = rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getName() + "-Ground";
-                     break;
-                 case 3: 
+                        rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getDynamics()->getGroundFrequency(rec->getLeg());
+                     taxiFreq =
+                        rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getDynamics()->getGroundFrequency(3);
                      sender = rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getName() + "-Ground";
+                     atisInformation = rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getDynamics()->getAtisInformation();
                      break;
+
                  case 4: 
                      sender = rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getName() + "-Tower";
                      break;
@@ -373,26 +378,68 @@ void FGATCController::transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir m
              break;
          }
     string text;
+    string taxiFreqStr;
+    double heading = 0;
+    string activeRunway;
+    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";
                break;
           case MSG_REQUEST_ENGINE_START:
                text = receiver + ", This is " + sender + ". Position " +getGateName(rec->getAircraft()) +
-                       ". Information YY." +
+                       ". Information " + atisInformation + ". " +
                        rec->getAircraft()->getTrafficRef()->getFlightRules() + " to " + 
                        rec->getAircraft()->getTrafficRef()->getArrivalAirport()->getName() + ". Request start-up";
                break;
+          // Acknowledge engine startup permission
+          // Assign departure runway
+          // Assign SID, if necessery (TODO)
           case MSG_PERMIT_ENGINE_START:
-               text = receiver + ". Start-up approved. YY correct, runway ZZ, AAA departure, squawk BBBB. " +
-                      "For push-back and taxi clearance call CCC.CCC. " + sender + " control.";
+               taxiFreqStr = formatATCFrequency3_2(taxiFreq);
+               
+               heading = rec->getAircraft()->getTrafficRef()->getCourse();
+               fltType = rec->getAircraft()->getTrafficRef()->getFlightType();
+               rwyClass= rec->getAircraft()->GetFlightPlan()->getRunwayClassFromTrafficType(fltType);
+
+               rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway, heading);
+               rec->getAircraft()->GetFlightPlan()->setRunway(activeRunway);
+               fp = rec->getAircraft()->getTrafficRef()->getDepartureAirport()->getDynamics()->getSID(activeRunway, heading);
+               rec->getAircraft()->GetFlightPlan()->setSID(fp);
+               if (fp) {
+                   SID = fp->getName() + " departure";
+               } else {
+                   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 " + transponderCode + ". " +
+                      "For push-back and taxi clearance call " + taxiFreqStr + ". " + sender + " control.";
                break;
           case MSG_DENY_ENGINE_START:
                text = receiver + ". Standby";
                break;
          case MSG_ACKNOWLEDGE_ENGINE_START:
-               text = receiver + ". Start-up approved. YY correct, runway ZZ, AAA departure, squawk BBBB. " +
-                      "For push-back and taxi clearance call CCC.CCC. " + sender;
+               fp = rec->getAircraft()->GetFlightPlan()->getSID();
+               if (fp) {
+                  SID = rec->getAircraft()->GetFlightPlan()->getSID()->getName() + " departure";
+               } else {
+                  SID = "fly runway heading ";
+               }
+               taxiFreqStr = formatATCFrequency3_2(taxiFreq);
+               activeRunway = rec->getAircraft()->GetFlightPlan()->getRunway();
+               transponderCode = rec->getAircraft()->GetTransponderCode();
+               text = receiver + ". Start-up approved. " + atisInformation + " correct, runway " +
+                      activeRunway + ", " + SID + ", squawk " + transponderCode + ". " +
+                      "For push-back and taxi clearance call " + taxiFreqStr + ". " + sender;
                break;
            default:
                break;
@@ -406,12 +453,28 @@ void FGATCController::transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir m
     // Display ATC message only when one of the radios is tuned
     // the relevant frequency.
     // Note that distance attenuation is currently not yet implemented
+    //cerr << "Transmitting " << text << " at " << stationFreq;
     if ((onBoardRadioFreqI0 == stationFreq) || (onBoardRadioFreqI1 == stationFreq)) {
         fgSetString("/sim/messages/atc", text.c_str());
         //cerr << "Printing Message: " << endl;
     }
 }
 
+string FGATCController::formatATCFrequency3_2(int freq) {
+    char buffer[7];
+    snprintf(buffer, 7, "%3.2f", ( (float) freq / 100.0) );
+    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