diff --git a/src/AIModel/AIAircraft.cxx b/src/AIModel/AIAircraft.cxx index bbed46642..8e773d481 100644 --- a/src/AIModel/AIAircraft.cxx +++ b/src/AIModel/AIAircraft.cxx @@ -52,12 +52,12 @@ const FGAIAircraft::PERF_STRUCT FGAIAircraft::settings[] = { FGAIAircraft *FGAIAircraft::_self = NULL; FGAIAircraft::FGAIAircraft(FGAIManager* mgr) { + _self = this; // This needs to be the first entry. manager = mgr; - _self = this; _type_str = "aircraft"; _otype = otAircraft; fp = 0; - fp_count = 0; + dt_count = 0; use_perf_vs = true; // set heading and altitude locks @@ -113,7 +113,7 @@ void FGAIAircraft::Run(double dt) { FGAIAircraft::dt = dt; - if (fp) ProcessFlightPlan(); + if (fp) ProcessFlightPlan(dt); double turn_radius_ft; double turn_circum_ft; @@ -336,14 +336,14 @@ void FGAIAircraft::SetFlightPlan(FGAIFlightPlan *f) { fp = f; } -void FGAIAircraft::ProcessFlightPlan( void ) { +void FGAIAircraft::ProcessFlightPlan( double dt ) { FGAIFlightPlan::waypoint* prev = 0; // the one behind you FGAIFlightPlan::waypoint* curr = 0; // the one ahead FGAIFlightPlan::waypoint* next = 0; // the next plus 1 prev = fp->getPreviousWaypoint(); curr = fp->getCurrentWaypoint(); next = fp->getNextWaypoint(); - ++fp_count; + dt_count += dt; if (!prev) { //beginning of flightplan, do this initialization once fp->IncrementWaypoint(); @@ -375,11 +375,12 @@ void FGAIAircraft::ProcessFlightPlan( void ) { return; } // end of initialization - // let's only process the flight plan every 11 time steps - if (fp_count < 11) { + // let's only process the flight plan every 500 ms. + if (dt_count < 0.5) { return; } else { - fp_count = 0; + while (dt_count > 0.5) + dt_count -= dt; // check to see if we've reached the lead point for our next turn double dist_to_go = fp->getDistanceToGo(pos.lat(), pos.lon(), curr); @@ -388,7 +389,7 @@ void FGAIAircraft::ProcessFlightPlan( void ) { //cout << "dist_to_go: " << dist_to_go << ", lead_dist: " << lead_dist << endl; if ( dist_to_go < lead_dist ) { - if (curr->name == "END") { //end of the flight plan, so terminate + if (curr->finished) { //end of the flight plan, so terminate setDie(true); return; } diff --git a/src/AIModel/AIAircraft.hxx b/src/AIModel/AIAircraft.hxx index fb62588e2..4048deb9e 100644 --- a/src/AIModel/AIAircraft.hxx +++ b/src/AIModel/AIAircraft.hxx @@ -66,7 +66,7 @@ public: void YawTo(double angle); void ClimbTo(double altitude); void TurnTo(double heading); - void ProcessFlightPlan( void ); + void ProcessFlightPlan( double dt ); //double getHeading(double lat1, double lon1, double lat2, double lon2); protected: @@ -77,7 +77,7 @@ private: bool hdg_lock; bool alt_lock; FGAIFlightPlan *fp; - int fp_count; + double dt_count; double dt; const PERF_STRUCT *performance; @@ -91,7 +91,6 @@ private: inline bool FGAIAircraft::_getGearDown() { return ((fgGetFloat("/position/altitude-agl-ft") < 150.0) - && (fgGetFloat("/orientation/pitch-deg") < 0.0) && (fgGetFloat("/velocities/airspeed-kt") < _self->performance->land_speed*1.5)); } diff --git a/src/AIModel/AIFlightPlan.cxx b/src/AIModel/AIFlightPlan.cxx index 3bde497ca..d8c95e75e 100644 --- a/src/AIModel/AIFlightPlan.cxx +++ b/src/AIModel/AIFlightPlan.cxx @@ -50,7 +50,6 @@ FGAIFlightPlan::FGAIFlightPlan(string filename) for (i = 0; i < node->nChildren(); i++) { //cout << "Reading waypoint " << i << endl; waypoint* wpt = new waypoint; - waypoints.push_back( wpt ); SGPropertyNode * wpt_node = node->getChild(i); wpt->name = wpt_node->getStringValue("name", "END"); wpt->latitude = wpt_node->getDoubleValue("lat", 0); @@ -60,6 +59,11 @@ FGAIFlightPlan::FGAIFlightPlan(string filename) wpt->crossat = wpt_node->getDoubleValue("crossat", -10000); wpt->gear_down = wpt_node->getBoolValue("gear-down", false); wpt->flaps_down= wpt_node->getBoolValue("flaps-down", false); + + if (wpt->name == "END") wpt->finished = true; + else wpt->finished = false; + + waypoints.push_back( wpt ); } wpt_iterator = waypoints.begin(); @@ -163,6 +167,8 @@ double FGAIFlightPlan::getBearing(double lat, double lon, waypoint* wp){ if (!southerly && easterly) return 90.0 - angle; if (southerly && !easterly) return 270.0 - angle; if (!southerly && !easterly) return 270.0 + angle; + + // Omit a compiler warning. + return 0; } - diff --git a/src/AIModel/AIFlightPlan.hxx b/src/AIModel/AIFlightPlan.hxx index e511c2c16..9eaf57029 100644 --- a/src/AIModel/AIFlightPlan.hxx +++ b/src/AIModel/AIFlightPlan.hxx @@ -37,6 +37,7 @@ public: double altitude; double speed; double crossat; + bool finished; bool gear_down; bool flaps_down; } waypoint;