From dda15ac4888ec7e99b68060760ee35f202d2cae0 Mon Sep 17 00:00:00 2001 From: ehofman Date: Sun, 6 Jun 2004 08:50:17 +0000 Subject: [PATCH] David Culp: Here's some additions to AI that allow refueling from an AI tanker (the actual onload of fuel must be handled by the user's FDM of course, this just lets the FDM know that the user is in position to refuel). I've added a new class of AIAircraft called "tanker". It uses the same performance struct as a jet transport. An AI tanker is just like an AI jet transport, except it uses the already-existing radar data to control the boolean property systems/refuel/contact. The code change was minimal. An AI tanker can be created like this: Esso 1 aircraft tanker Aircraft/737/Models/boeing733.xml 37.61633 -122.38334 3000 020 280 -15 This puts a tanker over KSFO at 3000 feet, in a left-hand orbit. When the user gets within refueling range (contact position) then the property systems/refuel/contact will be true. Otherwise it is false. The dimensions of the refueling envelope are pretty rough right now, but still usable. The user must be behind the tanker (ie. radar y_offset > 0). The user must be at or below the tanker's altitude (ie. radar elevation > 0). The user's lat/lon must be within 250 feet of the tanker's lat/lon (ie. radar range_ft < 250). This last requirement is loose because the radar data is only updated every 100 ms, which is accurate enough for radar use, but which is sloppy for air refueling. This could be tightened up by increasing the radar update rate to once every sim cycle. I'm going to add a light to the T-38 instrument panel that will monitor the property systems/refuel/contact. This will make it easier to explore the boundaries of the refueling envelope. --- src/AIModel/AIAircraft.cxx | 19 ++++++++++++++++++- src/AIModel/AIAircraft.hxx | 6 +++++- src/AIModel/AIManager.cxx | 7 +++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/AIModel/AIAircraft.cxx b/src/AIModel/AIAircraft.cxx index 9ec2c8be7..3a7f74db3 100644 --- a/src/AIModel/AIAircraft.cxx +++ b/src/AIModel/AIAircraft.cxx @@ -45,7 +45,9 @@ const FGAIAircraft::PERF_STRUCT FGAIAircraft::settings[] = { // jet_transport {5.0, 2.0, 3000.0, 1500.0, 140.0, 300.0, 430.0, 300.0, 130.0}, // jet_fighter - {7.0, 3.0, 4000.0, 2000.0, 150.0, 350.0, 500.0, 350.0, 150.0} + {7.0, 3.0, 4000.0, 2000.0, 150.0, 350.0, 500.0, 350.0, 150.0}, + // tanker + {5.0, 2.0, 3000.0, 1500.0, 140.0, 300.0, 430.0, 300.0, 130.0} }; @@ -56,6 +58,7 @@ FGAIAircraft::FGAIAircraft(FGAIManager* mgr) { fp = 0; dt_count = 0; use_perf_vs = true; + isTanker = false; // set heading and altitude locks hdg_lock = false; @@ -68,6 +71,7 @@ FGAIAircraft::~FGAIAircraft() { bool FGAIAircraft::init() { + refuel_node = fgGetNode("systems/refuel/contact", true); return FGAIBase::init(); } @@ -298,6 +302,19 @@ void FGAIAircraft::Run(double dt) { rotation = hdg - user_heading; if (rotation < 0.0) rotation += 360.0; + //************************************// + // Tanker code // + //************************************// + + if ( isTanker) { + if ( (range_ft < 250.0) && + (y_shift > 0.0) && + (elevation > 0.0) ) { + refuel_node->setBoolValue(true); + } else { + refuel_node->setBoolValue(false); + } + } } diff --git a/src/AIModel/AIAircraft.hxx b/src/AIModel/AIAircraft.hxx index 97227ab1b..bcacae266 100644 --- a/src/AIModel/AIAircraft.hxx +++ b/src/AIModel/AIAircraft.hxx @@ -46,7 +46,7 @@ private: public: - enum aircraft_e {LIGHT=0, WW2_FIGHTER, JET_TRANSPORT, JET_FIGHTER}; + enum aircraft_e {LIGHT=0, WW2_FIGHTER, JET_TRANSPORT, JET_FIGHTER, TANKER}; static const PERF_STRUCT settings[]; FGAIAircraft(FGAIManager* mgr); @@ -67,6 +67,8 @@ public: void TurnTo(double heading); void ProcessFlightPlan( double dt ); + inline void SetTanker(bool setting) { isTanker = setting; }; + private: bool hdg_lock; @@ -76,6 +78,8 @@ private: const PERF_STRUCT *performance; bool use_perf_vs; + SGPropertyNode* refuel_node; + bool isTanker; void Run(double dt); double sign(double x); diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index 3667d1556..c8d55b141 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -115,6 +115,7 @@ void FGAIManager::update(double dt) { ++ai_list_itr; } wind_from_down->setDoubleValue( strength ); + } @@ -168,6 +169,9 @@ int FGAIManager::createAircraft( string model_class, string path, ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_TRANSPORT]); } else if (model_class == "jet_fighter") { ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_FIGHTER]); + } else if (model_class == "tanker") { + ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_TRANSPORT]); + ai_plane->SetTanker(true); } else { ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_TRANSPORT]); } @@ -199,6 +203,9 @@ int FGAIManager::createAircraft( string model_class, string path, ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_TRANSPORT]); } else if (model_class == "jet_fighter") { ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_FIGHTER]); + } else if (model_class == "tanker") { + ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_TRANSPORT]); + ai_plane->SetTanker(true); } else { ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_TRANSPORT]); }