]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/tower.cxx
Alex Romosan:
[flightgear.git] / src / ATC / tower.cxx
index c4ccc96bbf59b9378a6c18f0f22d918ec5490268..cbd8ddc9f7b2be4f27a3368e45da8411a1073492 100644 (file)
@@ -72,7 +72,7 @@ TowerPlaneRec::TowerPlaneRec() :
        plane.callsign = "UNKNOWN";
 }
 
-TowerPlaneRec::TowerPlaneRec(PlaneRec p) :
+TowerPlaneRec::TowerPlaneRec(const PlaneRec& p) :
        planePtr(NULL),
        clearedToLand(false),
        clearedToLineUp(false),
@@ -99,7 +99,7 @@ TowerPlaneRec::TowerPlaneRec(PlaneRec p) :
        plane = p;
 }
 
-TowerPlaneRec::TowerPlaneRec(Point3D pt) :
+TowerPlaneRec::TowerPlaneRec(const Point3D& pt) :
        planePtr(NULL),
        clearedToLand(false),
        clearedToLineUp(false),
@@ -127,7 +127,7 @@ TowerPlaneRec::TowerPlaneRec(Point3D pt) :
        pos = pt;
 }
 
-TowerPlaneRec::TowerPlaneRec(PlaneRec p, Point3D pt) :
+TowerPlaneRec::TowerPlaneRec(const PlaneRec& p, const Point3D& pt) :
        planePtr(NULL),
        clearedToLand(false),
        clearedToLineUp(false),
@@ -508,7 +508,9 @@ void FGTower::Respond() {
                        }
                        trns += ConvertRwyNumToSpokenString(activeRwy);
                        if(_display) {
-                               globals->get_ATC_display()->RegisterSingleMessage(trns, 0);
+                               //globals->get_ATC_display()->RegisterSingleMessage(trns, 0);
+                               pending_transmission = trns;
+                               Transmit();
                        } else {
                                //cout << "Not displaying, trns was " << trns << '\n';
                        }
@@ -543,7 +545,9 @@ void FGTower::Respond() {
                                string trns = t->plane.callsign;
                                trns += " hold position";
                                if(_display) {
-                                       globals->get_ATC_display()->RegisterSingleMessage(trns, 0);
+                                       //globals->get_ATC_display()->RegisterSingleMessage(trns, 0);
+                                       pending_transmission = trns;
+                                       Transmit();
                                }
                                // TODO - add some idea of what traffic is blocking him.
                        }
@@ -581,7 +585,9 @@ void FGTower::Respond() {
                                t->clearedToLand = false;
                        }
                        if(_display && disp) {
-                               globals->get_ATC_display()->RegisterSingleMessage(trns);
+                               //globals->get_ATC_display()->RegisterSingleMessage(trns);
+                               pending_transmission = trns;
+                               Transmit();
                        }
                        t->finalAcknowledged = true;
                } else if(t->rwyVacatedReported && !(t->rwyVacatedAcknowledged)) {
@@ -649,13 +655,19 @@ void FGTower::ProcessDownwindReport(TowerPlaneRec* t) {
                s = s.substr(0,p);
                trns += s;
                if((tt->opType) == CIRCUIT) {
-                       if(tt->planePtr->GetLeg() == FINAL) {
+                       PatternLeg leg;
+                       if(t->isUser) {
+                               leg = tt->leg;
+                       } else {
+                               leg = tt->planePtr->GetLeg();
+                       }
+                       if(leg == FINAL) {
                                trns += " on final";
-                       } else if(tt->planePtr->GetLeg() == TURN4) {
+                       } else if(leg == TURN4) {
                                trns += " turning final";
-                       } else if(tt->planePtr->GetLeg() == BASE) {
+                       } else if(leg == BASE) {
                                trns += " on base";
-                       } else if(tt->planePtr->GetLeg() == TURN3) {
+                       } else if(leg == TURN3) {
                                trns += " turning base";
                        }
                } else {
@@ -670,7 +682,9 @@ void FGTower::ProcessDownwindReport(TowerPlaneRec* t) {
                }
        }
        if(_display) {
-               globals->get_ATC_display()->RegisterSingleMessage(trns);
+               //globals->get_ATC_display()->RegisterSingleMessage(trns);
+               pending_transmission = trns;
+               Transmit();
        }
        if(t->isUser) {
                if(t->opType == TTT_UNKNOWN) t->opType = CIRCUIT;
@@ -702,7 +716,9 @@ void FGTower::ProcessRunwayVacatedReport(TowerPlaneRec* t) {
        }
        //cout << "trns = " << trns << '\n';
        if(_display) {
-               globals->get_ATC_display()->RegisterSingleMessage(trns);
+               //globals->get_ATC_display()->RegisterSingleMessage(trns);
+               pending_transmission = trns;
+               Transmit();
        }
        RemoveFromRwyList(t->plane.callsign);
        AddToVacatedList(t);
@@ -813,7 +829,9 @@ void FGTower::ClearHoldingPlane(TowerPlaneRec* t) {
                timeSinceLastDeparture = 0.0;
        }
        if(_display) {
-               globals->get_ATC_display()->RegisterSingleMessage(trns, 0);
+               //globals->get_ATC_display()->RegisterSingleMessage(trns, 0);
+               pending_transmission = trns;
+               Transmit();
        }
        //cout << "Done ClearHoldingPlane " << endl;
 }
@@ -892,7 +910,7 @@ void FGTower::CheckCircuitList(double dt) {
                        //cout << " ho = " << ho << " abs(ho = " << abs(ho) << '\n';
                        // TODO FIXME - get the wind and convert this to track, or otherwise use track somehow!!!
                        // If it's gusty might need to filter the value, although we are leaving 30 degrees each way leeway!
-                       if(abs(ho) < 30) {
+                       if(fabs(ho) < 30) {
                                // could be either takeoff, climbout or landing - check orthopos.y
                                //cout << "tortho.y = " << tortho.y() << '\n';
                                if((tortho.y() < 0) || (t->leg == TURN4) || (t->leg == FINAL)) {
@@ -925,7 +943,7 @@ void FGTower::CheckCircuitList(double dt) {
                                                }
                                        }
                                }
-                       } else if(abs(ho) < 60) {
+                       } else if(fabs(ho) < 60) {
                                // turn1 or turn 4
                                // TODO - either fix or doublecheck this hack by looking at heading and pattern direction
                                if((t->leg == CLIMBOUT) || (t->leg == TURN1)) {
@@ -935,7 +953,7 @@ void FGTower::CheckCircuitList(double dt) {
                                        t->leg = TURN4;
                                        //cout << "Turn4\n";
                                }
-                       } else if(abs(ho) < 120) {
+                       } else if(fabs(ho) < 120) {
                                // crosswind or base
                                // TODO - either fix or doublecheck this hack by looking at heading and pattern direction
                                if((t->leg == TURN1) || (t->leg == CROSSWIND)) {
@@ -945,7 +963,7 @@ void FGTower::CheckCircuitList(double dt) {
                                        t->leg = BASE;
                                        //cout << "Base\n";
                                }
-                       } else if(abs(ho) < 150) {
+                       } else if(fabs(ho) < 150) {
                                // turn2 or turn 3
                                // TODO - either fix or doublecheck this hack by looking at heading and pattern direction
                                if((t->leg == CROSSWIND) || (t->leg == TURN2)) {
@@ -1367,26 +1385,26 @@ void FGTower::DoRwyDetails() {
        bool rwyGood = globals->get_runways()->search(ident, int(hdg), &runway);
        if(rwyGood) {
                //cout << "RUNWAY GOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOD\n";
-               activeRwy = runway.rwy_no;
-               rwy.rwyID = runway.rwy_no;
+               activeRwy = runway._rwy_no;
+               rwy.rwyID = runway._rwy_no;
                SG_LOG(SG_ATC, SG_INFO, "Active runway for airport " << ident << " is " << activeRwy);
                
                // Get the threshold position
-               double other_way = runway.heading - 180.0;
+               double other_way = runway._heading - 180.0;
                while(other_way <= 0.0) {
                        other_way += 360.0;
                }
        // move to the +l end/center of the runway
-               //cout << "Runway center is at " << runway.lon << ", " << runway.lat << '\n';
-       Point3D origin = Point3D(runway.lon, runway.lat, aptElev);
+               //cout << "Runway center is at " << runway._lon << ", " << runway._lat << '\n';
+       Point3D origin = Point3D(runway._lon, runway._lat, aptElev);
                Point3D ref = origin;
        double tshlon, tshlat, tshr;
                double tolon, tolat, tor;
-               rwy.length = runway.length * SG_FEET_TO_METER;
-               rwy.width = runway.width * SG_FEET_TO_METER;
+               rwy.length = runway._length * SG_FEET_TO_METER;
+               rwy.width = runway._width * SG_FEET_TO_METER;
        geo_direct_wgs_84 ( aptElev, ref.lat(), ref.lon(), other_way, 
                                rwy.length / 2.0 - 25.0, &tshlat, &tshlon, &tshr );
-       geo_direct_wgs_84 ( aptElev, ref.lat(), ref.lon(), runway.heading, 
+       geo_direct_wgs_84 ( aptElev, ref.lat(), ref.lon(), runway._heading, 
                                rwy.length / 2.0 - 25.0, &tolat, &tolon, &tor );
                // Note - 25 meters in from the runway end is a bit of a hack to put the plane ahead of the user.
                // now copy what we need out of runway into rwy
@@ -1394,7 +1412,7 @@ void FGTower::DoRwyDetails() {
                Point3D takeoff_end = Point3D(tolon, tolat, aptElev);
                //cout << "Threshold position = " << tshlon << ", " << tshlat << ", " << aptElev << '\n';
                //cout << "Takeoff position = " << tolon << ", " << tolat << ", " << aptElev << '\n';
-               rwy.hdg = runway.heading;
+               rwy.hdg = runway._heading;
                // Set the projection for the local area based on this active runway
                ortho.Init(rwy.threshold_pos, rwy.hdg); 
                rwy.end1ortho = ortho.ConvertToLocal(rwy.threshold_pos);        // should come out as zero
@@ -1417,7 +1435,7 @@ void FGTower::DoRwyDetails() {
 
 // Figure out if a given position lies on the active runway
 // Might have to change when we consider more than one active rwy.
-bool FGTower::OnActiveRunway(Point3D pt) {
+bool FGTower::OnActiveRunway(const Point3D& pt) {
        // TODO - check that the centre calculation below isn't confused by displaced thesholds etc.
        Point3D xyc((rwy.end1ortho.x() + rwy.end2ortho.x())/2.0, (rwy.end1ortho.y() + rwy.end2ortho.y())/2.0, 0.0);
        Point3D xyp = ortho.ConvertToLocal(pt);
@@ -1436,7 +1454,7 @@ bool FGTower::OnActiveRunway(Point3D pt) {
 
 // Figure out if a given position lies on any runway or not
 // Only call this at startup - reading the runways database is expensive and needs to be fixed!
-bool FGTower::OnAnyRunway(Point3D pt) {
+bool FGTower::OnAnyRunway(const Point3D& pt) {
        ATCData ad;
        double dist = current_commlist->FindClosest(lon, lat, elev, ad, TOWER, 10.0);
        if(dist < 0.0) {
@@ -1453,9 +1471,9 @@ bool FGTower::OnAnyRunway(Point3D pt) {
                SG_LOG(SG_ATC, SG_WARN, "Unable to find any runways for airport ID " << ad.ident << " in FGTower");
        }
        bool on = false;
-       while(runway.id == ad.ident) {          
+       while(runway._id == ad.ident) {         
                on = OnRunway(pt, runway);
-               //cout << "Runway " << runway.rwy_no << ": On = " << (on ? "true\n" : "false\n");
+               //cout << "Runway " << runway._rwy_no << ": On = " << (on ? "true\n" : "false\n");
                if(on) return(true);
                globals->get_runways()->next(&runway);          
        }
@@ -1464,7 +1482,7 @@ bool FGTower::OnAnyRunway(Point3D pt) {
 
 
 // Returns true if successful
-bool FGTower::RemoveFromTrafficList(string id) {
+bool FGTower::RemoveFromTrafficList(const string& id) {
        tower_plane_rec_list_iterator twrItr;
        for(twrItr = trafficList.begin(); twrItr != trafficList.end(); twrItr++) {
                TowerPlaneRec* tpr = *twrItr;
@@ -1480,7 +1498,7 @@ bool FGTower::RemoveFromTrafficList(string id) {
 
 
 // Returns true if successful
-bool FGTower::RemoveFromAppList(string id) {
+bool FGTower::RemoveFromAppList(const string& id) {
        tower_plane_rec_list_iterator twrItr;
        for(twrItr = appList.begin(); twrItr != appList.end(); twrItr++) {
                TowerPlaneRec* tpr = *twrItr;
@@ -1495,7 +1513,7 @@ bool FGTower::RemoveFromAppList(string id) {
 }
 
 // Returns true if successful
-bool FGTower::RemoveFromRwyList(string id) {
+bool FGTower::RemoveFromRwyList(const string& id) {
        tower_plane_rec_list_iterator twrItr;
        for(twrItr = rwyList.begin(); twrItr != rwyList.end(); twrItr++) {
                TowerPlaneRec* tpr = *twrItr;
@@ -1882,7 +1900,7 @@ double FGTower::GetTrafficETA(unsigned int list_pos, bool printout) {
 }
        
 
-void FGTower::ContactAtHoldShort(PlaneRec plane, FGAIPlane* requestee, tower_traffic_type operation) {
+void FGTower::ContactAtHoldShort(const PlaneRec& plane, FGAIPlane* requestee, tower_traffic_type operation) {
        // HACK - assume that anything contacting at hold short is new for now - FIXME LATER
        TowerPlaneRec* t = new TowerPlaneRec;
        t->plane = plane;
@@ -1916,7 +1934,7 @@ void FGTower::ContactAtHoldShort(PlaneRec plane, FGAIPlane* requestee, tower_tra
 
 // Register the presence of an AI plane at a point where contact would already have been made in real life
 // CAUTION - currently it is assumed that this plane's callsign is unique - it is up to AIMgr to generate unique callsigns.
-void FGTower::RegisterAIPlane(PlaneRec plane, FGAIPlane* ai, tower_traffic_type op, PatternLeg lg) {
+void FGTower::RegisterAIPlane(const PlaneRec& plane, FGAIPlane* ai, const tower_traffic_type& op, const PatternLeg& lg) {
        // At the moment this is only going to be tested with inserting an AI plane on downwind
        TowerPlaneRec* t = new TowerPlaneRec;
        t->plane = plane;
@@ -1936,7 +1954,7 @@ void FGTower::RegisterAIPlane(PlaneRec plane, FGAIPlane* ai, tower_traffic_type
        doThresholdUseOrder();
 }
 
-void FGTower::DeregisterAIPlane(string id) {
+void FGTower::DeregisterAIPlane(const string& id) {
        RemovePlane(id);
 }
 
@@ -1944,7 +1962,7 @@ void FGTower::DeregisterAIPlane(string id) {
 // eg "Cessna Charlie Foxtrot Golf Foxtrot Sierra eight miles South of the airport for full stop with Bravo"
 // This function probably only called via user interaction - AI planes will have an overloaded function taking a planerec.
 // opt defaults to AIP_LT_UNKNOWN
-void FGTower::VFRArrivalContact(string ID, LandingType opt) {
+void FGTower::VFRArrivalContact(const string& ID, const LandingType& opt) {
        //cout << "USER Request Landing Clearance called for ID " << ID << '\n';
        
        // For now we'll assume that the user is a light plane and can get him/her to join the circuit if necessary.
@@ -1995,7 +2013,7 @@ void FGTower::VFRArrivalContact(string ID, LandingType opt) {
 }
 
 // landingType defaults to AIP_LT_UNKNOWN
-void FGTower::VFRArrivalContact(PlaneRec plane, FGAIPlane* requestee, LandingType lt) {
+void FGTower::VFRArrivalContact(const PlaneRec& plane, FGAIPlane* requestee, const LandingType& lt) {
        //cout << "VFRArrivalContact called for plane " << plane.callsign << " at " << ident << '\n';
        // Possible hack - assume this plane is new for now - TODO - should check really
        TowerPlaneRec* t = new TowerPlaneRec;
@@ -2020,17 +2038,18 @@ void FGTower::VFRArrivalContact(PlaneRec plane, FGAIPlane* requestee, LandingTyp
        AddToTrafficList(t);
 }
 
-void FGTower::RequestDepartureClearance(string ID) {
+void FGTower::RequestDepartureClearance(const string& ID) {
        //cout << "Request Departure Clearance called...\n";
 }
        
-void FGTower::ReportFinal(string ID) {
+void FGTower::ReportFinal(const string& ID) {
        //cout << "Report Final Called at tower " << ident << " by plane " << ID << '\n';
+       string uid=ID;
        if(ID == "USER") {
-               ID = fgGetString("/sim/user/callsign");
+               uid = fgGetString("/sim/user/callsign");
                current_atcdialog->remove_entry(ident, USER_REPORT_3_MILE_FINAL, TOWER);
        }
-       TowerPlaneRec* t = FindPlane(ID);
+       TowerPlaneRec* t = FindPlane(uid);
        if(t) {
                t->finalReported = true;
                t->finalAcknowledged = false;
@@ -2047,12 +2066,13 @@ void FGTower::ReportFinal(string ID) {
        }
 }
 
-void FGTower::ReportLongFinal(string ID) {
+void FGTower::ReportLongFinal(const string& ID) {
+       string uid=ID;
        if(ID == "USER") {
-               ID = fgGetString("/sim/user/callsign");
+               uid = fgGetString("/sim/user/callsign");
                current_atcdialog->remove_entry(ident, USER_REPORT_3_MILE_FINAL, TOWER);
        }
-       TowerPlaneRec* t = FindPlane(ID);
+       TowerPlaneRec* t = FindPlane(uid);
        if(t) {
                t->longFinalReported = true;
                t->longFinalAcknowledged = false;
@@ -2068,13 +2088,14 @@ void FGTower::ReportLongFinal(string ID) {
 //void FGTower::ReportMiddleMarker(string ID);
 //void FGTower::ReportInnerMarker(string ID);
 
-void FGTower::ReportRunwayVacated(string ID) {
+void FGTower::ReportRunwayVacated(const string& ID) {
        //cout << "Report Runway Vacated Called at tower " << ident << " by plane " << ID << '\n';
+       string uid=ID;
        if(ID == "USER") {
-               ID = fgGetString("/sim/user/callsign");
+               uid = fgGetString("/sim/user/callsign");
                current_atcdialog->remove_entry(ident, USER_REPORT_RWY_VACATED, TOWER);
        }
-       TowerPlaneRec* t = FindPlane(ID);
+       TowerPlaneRec* t = FindPlane(uid);
        if(t) {
                //cout << "Found it...\n";
                t->rwyVacatedReported = true;
@@ -2086,7 +2107,7 @@ void FGTower::ReportRunwayVacated(string ID) {
        }
 }
 
-TowerPlaneRec* FGTower::FindPlane(string ID) {
+TowerPlaneRec* FGTower::FindPlane(const string& ID) {
        //cout << "FindPlane called for " << ID << "...\n";
        tower_plane_rec_list_iterator twrItr;
        // Do the approach list first
@@ -2119,7 +2140,7 @@ TowerPlaneRec* FGTower::FindPlane(string ID) {
        return(NULL);
 }
 
-void FGTower::RemovePlane(string ID) {
+void FGTower::RemovePlane(const string& ID) {
        //cout << ident << " RemovePlane called for " << ID << '\n';
        // We have to be careful here - we want to erase the plane from all lists it is in,
        // but we can only delete it once, AT THE END.
@@ -2136,6 +2157,7 @@ void FGTower::RemovePlane(string ID) {
                if((*twrItr)->plane.callsign == ID) {
                        t = *twrItr;
                        twrItr = depList.erase(twrItr);
+                       twrItr--;
                        depListItr = depList.begin();
                }
        }
@@ -2178,13 +2200,14 @@ void FGTower::RemovePlane(string ID) {
        if(t) delete t;
 }
 
-void FGTower::ReportDownwind(string ID) {
+void FGTower::ReportDownwind(const string& ID) {
        //cout << "ReportDownwind(...) called\n";
+       string uid=ID;
        if(ID == "USER") {
-               ID = fgGetString("/sim/user/callsign");
+               uid = fgGetString("/sim/user/callsign");
                current_atcdialog->remove_entry(ident, USER_REPORT_DOWNWIND, TOWER);
        }
-       TowerPlaneRec* t = FindPlane(ID);
+       TowerPlaneRec* t = FindPlane(uid);
        if(t) {
                t->downwindReported = true;
                responseReqd = true;
@@ -2208,13 +2231,14 @@ void FGTower::ReportDownwind(string ID) {
        }
 }
 
-void FGTower::ReportGoingAround(string ID) {
+void FGTower::ReportGoingAround(const string& ID) {
+       string uid=ID;
        if(ID == "USER") {
-               ID = fgGetString("/sim/user/callsign");
+               uid = fgGetString("/sim/user/callsign");
                RemoveAllUserDialogOptions();   // TODO - it would be much more efficient if ATCDialog simply had a clear() function!!!
                current_atcdialog->add_entry(ident, "@AP Tower @CS Downwind @RW", "Report Downwind", TOWER, (int)USER_REPORT_DOWNWIND);
        }
-       TowerPlaneRec* t = FindPlane(ID);
+       TowerPlaneRec* t = FindPlane(uid);
        if(t) {
                //t->goAroundReported = true;  // No need to set this until we start responding to it.
                responseReqd = false;   // might change in the future but for now we'll not distract them during the go-around.
@@ -2266,7 +2290,7 @@ string FGTower::GenText(const string& m, int c) {
                        int check = 0;  // If mes gets overflowed the while loop can go infinite
                        while ( strchr(&mes[0], crej) != NULL  ) {      // ie. loop until no more occurances of crej ('@') found
                                pos = strchr( &mes[0], crej );
-                               bcopy(pos, &tag[0], 3);
+                               memmove(&tag[0], pos, 3);
                                tag[3] = '\0';
                                int i;
                                len = 0;