X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FATCDCL%2Fground.cxx;h=08a3206133fc8d6aabb3a53b451897f8db604ddb;hb=7a14ec7e320bd2786a041e8801b79cd87d6dc1d1;hp=5176f13924d2b5b319525191516c3fc262131e12;hpb=d9bfd5a425df1bad7e3c53a64adce871e299a6b9;p=flightgear.git diff --git a/src/ATCDCL/ground.cxx b/src/ATCDCL/ground.cxx index 5176f1392..08a320613 100644 --- a/src/ATCDCL/ground.cxx +++ b/src/ATCDCL/ground.cxx @@ -22,6 +22,8 @@ # include #endif +#include + #include #include #include @@ -37,8 +39,8 @@ #include "AILocalTraffic.hxx" #include "ATCmgr.hxx" -SG_USING_STD(ifstream); -SG_USING_STD(cout); +using std::ifstream; +using std::cout; node::node() { } @@ -151,11 +153,11 @@ bool FGGround::LoadNetwork() { fin >> buf; np->nodeID = atoi(buf); fin >> buf; - np->pos.setlon(atof(buf)); + np->pos.setLongitudeDeg(atof(buf)); fin >> buf; - np->pos.setlat(atof(buf)); + np->pos.setLatitudeDeg(atof(buf)); fin >> buf; - np->pos.setelev(atof(buf)); + np->pos.setElevationM(atof(buf)); fin >> buf; // node type if(!strcmp(buf, "J")) { np->type = JUNCTION; @@ -239,11 +241,11 @@ bool FGGround::LoadNetwork() { fin >> buf; gp->nodeID = atoi(buf); fin >> buf; - gp->pos.setlon(atof(buf)); + gp->pos.setLongitudeDeg(atof(buf)); fin >> buf; - gp->pos.setlat(atof(buf)); + gp->pos.setLatitudeDeg(atof(buf)); fin >> buf; - gp->pos.setelev(atof(buf)); + gp->pos.setElevationM(atof(buf)); fin >> buf; // gate type - ignore this for now fin >> buf; // gate heading gp->heading = atoi(buf); @@ -358,53 +360,40 @@ void FGGround::Update(double dt) { // will be initialised before ground so we can't do that. void FGGround::DoRwyDetails() { //cout << "GetRwyDetails called" << endl; - - // Based on the airport-id and wind get the active runway - - //wind - double hdg = wind_from_hdg->getDoubleValue(); - double speed = wind_speed_knots->getDoubleValue(); - hdg = (speed == 0.0 ? 270.0 : hdg); - //cout << "Heading = " << hdg << '\n'; - - FGRunway runway; - bool rwyGood = globals->get_runways()->search(ident, int(hdg), &runway); - if(rwyGood) { - activeRwy = runway._rwy_no; - rwy.rwyID = runway._rwy_no; - SG_LOG(SG_ATC, SG_INFO, "In FGGround, active runway for airport " << ident << " is " << activeRwy); - // Get the threshold position - 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); - Point3D ref = origin; - double tshlon, tshlat, tshr; - double tolon, tolat, tor; - rwy.length = runway._length * 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, - 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 - rwy.threshold_pos = Point3D(tshlon, tshlat, aptElev); - 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; - // 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 - rwy.end2ortho = ortho.ConvertToLocal(takeoff_end); - } else { - SG_LOG(SG_ATC, SG_ALERT, "Help - can't get good runway in FGTower!!"); - activeRwy = "NN"; - } + const FGAirport* apt = fgFindAirportID(ident); + assert(apt); + FGRunway* runway = apt->getActiveRunwayForUsage(); + + activeRwy = runway->ident(); + rwy.rwyID = runway->ident(); + SG_LOG(SG_ATC, SG_INFO, "In FGGround, active runway for airport " << ident << " is " << activeRwy); + + // Get the threshold position + double other_way = runway->headingDeg() - 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'; + double tshlon = 0.0, tshlat = 0.0, tshr = 0.0; + double tolon = 0.0, tolat = 0.0, tor = 0.0; + rwy.length = runway->lengthM(); + geo_direct_wgs_84 ( aptElev, runway->latitude(), runway->longitude(), other_way, + rwy.length / 2.0 - 25.0, &tshlat, &tshlon, &tshr ); + geo_direct_wgs_84 ( aptElev, runway->latitude(), runway->longitude(), runway->headingDeg(), + 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 + rwy.threshold_pos = SGGeod::fromDegM(tshlon, tshlat, aptElev); + SGGeod takeoff_end = SGGeod::fromDegM(tolon, tolat, aptElev); + //cout << "Threshold position = " << tshlon << ", " << tshlat << ", " << aptElev << '\n'; + //cout << "Takeoff position = " << tolon << ", " << tolat << ", " << aptElev << '\n'; + rwy.hdg = runway->headingDeg(); + // 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 + rwy.end2ortho = ortho.ConvertToLocal(takeoff_end); } // Return a random gate ID of an unused gate. @@ -681,7 +670,6 @@ void FGGround::RequestDeparture(const PlaneRec& plane, FGAIEntity* requestee) { g->cleared = false; g->incoming = false; // TODO - need to handle the next 3 as well - //Point3D current_pos; //node* destination; //node* last_clearance;