From 22cd6dfb2a56f6198277076a3c00dc90c8a5c2b8 Mon Sep 17 00:00:00 2001 From: ehofman Date: Fri, 21 May 2004 16:50:19 +0000 Subject: [PATCH] David Culp: 1. Removed aircraft roll on ground. 2. Decreased descent pitch angle. 3. Updated flightplans to include 4. Fixed property indexing, so all AI aircraft have their own property branch The default value of is false, so you only need to specify it when on the ground. For takeoff you need to specify true for the first waypoint, and for the acceleration waypoint. For landing you need to specify it for the touchdown point and any taxi points. One problem. WARNING **** There is a bug in the way the property system works, which causes a segfault, but I don't know if the problem is in the property code, or in how I'm using it. After an AI object terminates, if you access the property tree through the property browser the sim will segfault. --- src/AIModel/AIAircraft.cxx | 27 +++++++++++++++++++++------ src/AIModel/AIBase.cxx | 24 ++++++++++++++---------- src/AIModel/AIBase.hxx | 11 +++++++++-- src/AIModel/AIFlightPlan.cxx | 1 + src/AIModel/AIFlightPlan.hxx | 1 + src/AIModel/AIManager.cxx | 16 +++++++++++++++- src/AIModel/AIManager.hxx | 1 + 7 files changed, 62 insertions(+), 19 deletions(-) diff --git a/src/AIModel/AIAircraft.cxx b/src/AIModel/AIAircraft.cxx index bb5107d6b..c725fee67 100644 --- a/src/AIModel/AIAircraft.cxx +++ b/src/AIModel/AIAircraft.cxx @@ -132,7 +132,13 @@ void FGAIAircraft::Run(double dt) { double speed_diff = tgt_speed - speed; if (fabs(speed_diff) > 0.2) { if (speed_diff > 0.0) speed += performance->accel * dt; - if (speed_diff < 0.0) speed -= performance->decel * dt; + if (speed_diff < 0.0) { + if (!no_roll) { + speed -= performance->decel * dt * 3; + } else { + speed -= performance->decel * dt; + } + } } // convert speed to degrees per second @@ -202,25 +208,32 @@ void FGAIAircraft::Run(double dt) { } if (alt_lock && !use_perf_vs) { - double max_vs = 2*(tgt_altitude - altitude); + double max_vs = 4*(tgt_altitude - altitude); + double min_vs = 100; + if (tgt_altitude < altitude) min_vs = -100.0; if ((fabs(tgt_altitude - altitude) < 1500.0) && (fabs(max_vs) < fabs(tgt_vs))) tgt_vs = max_vs; + if (fabs(tgt_vs) < fabs(min_vs)) tgt_vs = min_vs; } // adjust vertical speed double vs_diff = tgt_vs - vs; if (fabs(vs_diff) > 10.0) { if (vs_diff > 0.0) { - vs += 400.0 * dt; + vs += 900.0 * dt; if (vs > tgt_vs) vs = tgt_vs; } else { - vs -= 300.0 * dt; + vs -= 400.0 * dt; if (vs < tgt_vs) vs = tgt_vs; } } // match pitch angle to vertical speed - pitch = vs * 0.005; + if (vs > 0){ + pitch = vs * 0.005; + } else { + pitch = vs * 0.002; + } //###########################// // do calculations for radar // @@ -357,7 +370,7 @@ void FGAIAircraft::ProcessFlightPlan( double dt ) { setHeading(fp->getBearing(prev->latitude, prev->longitude, curr)); if (next) fp->setLeadDistance(speed, hdg, curr, next); - if (curr->crossat > -1000.0) { //start descent/climb now + if (curr->crossat > -1000.0) { //use a calculated descent/climb rate use_perf_vs = false; tgt_vs = (curr->crossat - prev->altitude)/ (fp->getDistanceToGo(pos.lat(), pos.lon(), curr)/ @@ -368,6 +381,7 @@ void FGAIAircraft::ProcessFlightPlan( double dt ) { tgt_altitude = prev->altitude; } alt_lock = hdg_lock = true; + no_roll = prev->on_ground; //cout << "First waypoint: " << prev->name << endl; //cout << " Target speed: " << tgt_speed << endl; //cout << " Target altitude: " << tgt_altitude << endl; @@ -410,6 +424,7 @@ void FGAIAircraft::ProcessFlightPlan( double dt ) { } tgt_speed = prev->speed; hdg_lock = alt_lock = true; + no_roll = prev->on_ground; //cout << "Crossing waypoint: " << prev->name << endl; //cout << " Target speed: " << tgt_speed << endl; //cout << " Target altitude: " << tgt_altitude << endl; diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index 18af4a9aa..e59207a65 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -41,6 +41,7 @@ #include "AIBase.hxx" +#include "AIManager.hxx" FGAIBase *FGAIBase::_self = NULL; @@ -51,13 +52,18 @@ FGAIBase::FGAIBase() { bearing = elevation = range = rdot = 0.0; x_shift = y_shift = rotation = 0.0; invisible = true; + no_roll = true; model_path = ""; + model = 0; _otype = otNull; + index = 0; } FGAIBase::~FGAIBase() { globals->get_scenery()->get_scene_graph()->removeKid(aip.getSceneGraph()); unbind(); + SGPropertyNode *root = globals->get_props()->getNode("ai/models", true); + root->removeChild(_type_str.c_str(), index); _self = NULL; } @@ -68,7 +74,11 @@ void FGAIBase::update(double dt) { void FGAIBase::Transform() { if (!invisible) { aip.setPosition(pos.lon(), pos.lat(), pos.elev() * SG_METER_TO_FEET); - aip.setOrientation(roll, pitch, hdg); + if (no_roll) { + aip.setOrientation(0.0, pitch, hdg); + } else { + aip.setOrientation(roll, pitch, hdg); + } aip.update( globals->get_scenery()->get_center() ); } } @@ -77,12 +87,8 @@ void FGAIBase::Transform() { bool FGAIBase::init() { SGPropertyNode *root = globals->get_props()->getNode("ai/models", true); - vector p_vec = root->getChildren(_type_str); - unsigned num = p_vec.size(); - p_vec.clear(); - - props = root->getNode(_type_str, num, true); - ssgBranch *model = 0; + index = manager->getNum(_otype) - 1; + props = root->getNode(_type_str.c_str(), index, true); if (model_path != "") { model = sgLoad3DModel( globals->get_fg_root(), model_path.c_str(), @@ -135,7 +141,6 @@ void FGAIBase::bind() { props->tie("radar/bearing-deg", SGRawValueFunctions(FGAIBase::_getBearing)); props->tie("radar/elevation-deg", SGRawValueFunctions(FGAIBase::_getElevation)); props->tie("radar/range-nm", SGRawValueFunctions(FGAIBase::_getRange)); -// props->tie("radar/rdot-kts", SGRawValueFunctions(FGAIBase::_getRdot)); props->tie("radar/h-offset", SGRawValueFunctions(FGAIBase::_getH_offset)); props->tie("radar/v-offset", SGRawValueFunctions(FGAIBase::_getV_offset)); props->tie("radar/x-shift", SGRawValueFunctions(FGAIBase::_getX_shift)); @@ -164,13 +169,12 @@ void FGAIBase::unbind() { props->untie("radar/bearing-deg"); props->untie("radar/elevation-deg"); props->untie("radar/range-nm"); -// props->untie("radar/rdot-kts"); props->untie("radar/h-offset"); props->untie("radar/v-offset"); props->untie("radar/x-shift"); props->untie("radar/y-shift"); props->untie("radar/rotation"); - props->untie("controls/controls/lighting/nav-lights"); + props->untie("controls/lighting/nav-lights"); } diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index 44ebd61e8..3436a1332 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -97,19 +97,25 @@ protected: string model_path; //Path to the 3D model + ssgBranch * model; //The 3D model object SGModelPlacement aip; bool delete_me; int id; bool invisible; + bool no_roll; void Transform(); static FGAIBase *_self; - const char *_type_str; + string _type_str; object_type _otype; + int index; public: + object_type getType(); + bool isa( object_type otype ); + static double _getVS_fps(); static void _setVS_fps( double _vs ); @@ -133,7 +139,6 @@ public: static double _getRotation(); static bool _isNight(); - bool isa( object_type otype ); }; @@ -205,5 +210,7 @@ inline bool FGAIBase::_isNight() { inline void FGAIBase::setID( int ID ) { id = ID; } inline int FGAIBase::getID() { return id; } +inline FGAIBase::object_type FGAIBase::getType() { return _otype; } + #endif // _FG_AIBASE_HXX diff --git a/src/AIModel/AIFlightPlan.cxx b/src/AIModel/AIFlightPlan.cxx index d8c95e75e..289d850dd 100644 --- a/src/AIModel/AIFlightPlan.cxx +++ b/src/AIModel/AIFlightPlan.cxx @@ -59,6 +59,7 @@ 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); + wpt->on_ground = wpt_node->getBoolValue("on-ground", false); if (wpt->name == "END") wpt->finished = true; else wpt->finished = false; diff --git a/src/AIModel/AIFlightPlan.hxx b/src/AIModel/AIFlightPlan.hxx index 9eaf57029..bc75b9ab3 100644 --- a/src/AIModel/AIFlightPlan.hxx +++ b/src/AIModel/AIFlightPlan.hxx @@ -40,6 +40,7 @@ public: bool finished; bool gear_down; bool flaps_down; + bool on_ground; } waypoint; FGAIFlightPlan(string filename); diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index 68f60474e..b53ac439b 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -393,9 +393,23 @@ void FGAIManager::processScenario( string filename ) { FGAIScenario::entry* en = s->getNextEntry(); if (en) { FGAIFlightPlan* f = new FGAIFlightPlan( en->flightplan ); - createAircraft("jet_transport", "Aircraft/737/Models/boeing733.xml", f); + if (en->aitype == "aircraft"){ + createAircraft( en->aircraft_class, en->model_path, f); + } } } delete s; } +int FGAIManager::getNum( FGAIBase::object_type ot ) { + ai_list_iterator itr = ai_list.begin(); + int count = 0; + while(itr != ai_list.end()) { + if ((*itr)->getType() == ot) { + ++count; + } + ++itr; + } + return count; +} + diff --git a/src/AIModel/AIManager.hxx b/src/AIModel/AIManager.hxx index 449b03b40..2e154fd6a 100644 --- a/src/AIModel/AIManager.hxx +++ b/src/AIModel/AIManager.hxx @@ -121,6 +121,7 @@ public: inline double get_user_speed() {return user_speed; } void processScenario( string filename ); + int getNum( FGAIBase::object_type ot); private: