From: durk Date: Sun, 16 Nov 2008 13:41:24 +0000 (+0000) Subject: Changes to the AIModel code, to prepare for the new traffic manager code: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=931c661b40d197110c2acd503365e1e98f27b178;p=flightgear.git Changes to the AIModel code, to prepare for the new traffic manager code: - Leg loading can fail when no additional flights are available - Better support for waypoint interception during pushback (speed ~ 0) --- diff --git a/src/AIModel/AIAircraft.cxx b/src/AIModel/AIAircraft.cxx index c9f185bf0..d66eaa3ea 100644 --- a/src/AIModel/AIAircraft.cxx +++ b/src/AIModel/AIAircraft.cxx @@ -268,7 +268,10 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) { //TODO let the fp handle this (loading of next leg) fp->IncrementWaypoint((bool) trafficRef); if (!(fp->getNextWaypoint()) && trafficRef) - loadNextLeg(); + if (!loadNextLeg()) { + setDie(true); + return; + } prev = fp->getPreviousWaypoint(); curr = fp->getCurrentWaypoint(); @@ -323,11 +326,13 @@ bool FGAIAircraft::_getGearDown() const { } -void FGAIAircraft::loadNextLeg() { +bool FGAIAircraft::loadNextLeg() { int leg; if ((leg = fp->getLeg()) == 10) { - trafficRef->next(); + if (!trafficRef->next()) { + return false; + } setCallSign(trafficRef->getCallSign()); //props->setStringValue("callsign", callsign.c_str()); leg = 1; @@ -354,7 +359,9 @@ void FGAIAircraft::loadNextLeg() { trafficRef->getFlightType(), acType, company); + //cerr << "created leg " << leg << " for " << trafficRef->getCallSign() << endl; } + return true; } @@ -535,7 +542,10 @@ void FGAIAircraft::handleFirstWaypoint() { //TODO fp should handle this fp->IncrementWaypoint(eraseWaypoints); if (!(fp->getNextWaypoint()) && trafficRef) - loadNextLeg(); + if (!loadNextLeg()) { + setDie(true); + return; + } prev = fp->getPreviousWaypoint(); //first waypoint curr = fp->getCurrentWaypoint(); //second waypoint @@ -616,7 +626,11 @@ bool FGAIAircraft::leadPointReached(FGAIFlightPlan::waypoint* curr) { //prev_dist_to_go = dist_to_go; //if (dist_to_go < lead_dist) - // cerr << trafficRef->getCallSign() << " Distance : " << dist_to_go << ": Lead distance " << lead_dist << " " << curr->name << endl; + // cerr << trafficRef->getCallSign() << " Distance : " + // << dist_to_go << ": Lead distance " + // << lead_dist << " " << curr->name + // << " Ground target speed " << groundTargetSpeed << endl; + return dist_to_go < lead_dist; } @@ -631,7 +645,7 @@ bool FGAIAircraft::aiTrafficVisible() { user.CourseAndDistance(current, &course, &distance); - return ((distance * SG_METER_TO_NM) <= TRAFFICTOAIDIST); + return ((distance * SG_METER_TO_NM) <= TRAFFICTOAIDISTTODIE); } @@ -654,6 +668,7 @@ bool FGAIAircraft::handleAirportEndPoints(FGAIFlightPlan::waypoint* prev, time_t // This waypoint marks the fact that the aircraft has passed the initial taxi // departure waypoint, so it can release the parking. + //cerr << trafficRef->getCallSign() << " has passed waypoint " << prev->name << " at speed " << speed << endl; if (prev->name == "PushBackPoint") { dep->getDynamics()->releaseParking(fp->getGate()); time_t holdUntil = now + 120; diff --git a/src/AIModel/AIAircraft.hxx b/src/AIModel/AIAircraft.hxx index 9722e3556..a179c9d7f 100644 --- a/src/AIModel/AIAircraft.hxx +++ b/src/AIModel/AIAircraft.hxx @@ -64,7 +64,7 @@ public: void getGroundElev(double dt); //TODO these 3 really need to be public? void doGroundAltitude(); - void loadNextLeg (); + bool loadNextLeg (); void setAcType(const string& ac) { acType = ac; }; void setCompany(const string& comp) { company = comp;}; diff --git a/src/AIModel/AIFlightPlan.cxx b/src/AIModel/AIFlightPlan.cxx index e9035eddb..438d99125 100644 --- a/src/AIModel/AIFlightPlan.cxx +++ b/src/AIModel/AIFlightPlan.cxx @@ -381,6 +381,10 @@ void FGAIFlightPlan::setLeadDistance(double speed, double bearing, // At a turn rate of 30 degrees per second, it takes 12 seconds to do a full 360 degree turn // So, to get an estimate of the turn radius, calculate the cicumference of the circle // we travel on. Get the turn radius by dividing by PI (*2). + if (speed < 0.5) { + lead_distance = 0.5; + return; + } if (speed < 25) { turn_radius = ((360/30)*15) / (2*M_PI); } else diff --git a/src/AIModel/AIFlightPlanCreate.cxx b/src/AIModel/AIFlightPlanCreate.cxx index 482d16aee..04ae25103 100644 --- a/src/AIModel/AIFlightPlanCreate.cxx +++ b/src/AIModel/AIFlightPlanCreate.cxx @@ -577,7 +577,7 @@ void FGAIFlightPlan::createTakeOff(bool firstFlight, FGAirport *apt, double spee wpt->latitude = lat2; wpt->longitude = lon2; wpt->altitude = apt->getElevation()+5000; - wpt->speed = speed; + wpt->speed = speed; wpt->crossat = -10000; wpt->gear_down = true; wpt->flaps_down= true; @@ -585,6 +585,11 @@ void FGAIFlightPlan::createTakeOff(bool firstFlight, FGAirport *apt, double spee wpt->on_ground = false; wpt->routeIndex = 0; waypoints.push_back(wpt); + //cerr << "Created takeoff plan : " << endl; + //for (wpt_vector_iterator i = waypoints.begin(); i != waypoints.end(); i++) { + // cerr << "Waypoint Name: " << (*i)->name << ". Speed = " << (*i)->speed << endl; + //} + // geo_direct_wgs_84 ( 0, rwy->latitude(), rwy->longitude(), heading, // 100000, diff --git a/src/AIModel/AIFlightPlanCreatePushBack.cxx b/src/AIModel/AIFlightPlanCreatePushBack.cxx index cc2a141e8..3707f2b91 100644 --- a/src/AIModel/AIFlightPlanCreatePushBack.cxx +++ b/src/AIModel/AIFlightPlanCreatePushBack.cxx @@ -141,6 +141,9 @@ void FGAIFlightPlan::createPushBack(bool firstFlight, FGAirport *dep, // some special considerations for the last point: wpt->name = string("PushBackPoint"); wpt->speed = 15; + //for (wpt_vector_iterator i = waypoints.begin(); i != waypoints.end(); i++) { + // cerr << "Waypoint Name: " << (*i)->name << endl; + //} } else { //cerr << "Creating direct forward departure route fragment" << endl; double lat2, lon2, az2; diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index aac54ab9b..820368727 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -20,6 +20,7 @@ #include #include +#include #include