From 943b7b22a703a98e3c1a947884e05976103ba395 Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 16 Jun 2006 14:22:21 +0000 Subject: [PATCH] This patch only affects aircraft (AI Models) that have no predefined flightplan. Such aircraft are given some initial conditions that they fly with. They proceed on in "freeflight" mode indefinitely. For example, there is a refueling demo where the tanker starts at 3000', 280 kts, and in a 15 degree bank, and then continues to orbit indefinitely. For these aircraft with no flightplan, I have added several control nodes in controls/flight that allow a script or menu or external application to set heading, altitude, bank angle, and speed. This permits some level of interactive or scripted control over AI aircraft. --- src/AIModel/AIAircraft.cxx | 29 +++++++++++++++++++++++++++++ src/AIModel/AIBase.cxx | 11 +++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/AIModel/AIAircraft.cxx b/src/AIModel/AIAircraft.cxx index cdc1fbf7e..0f1295276 100644 --- a/src/AIModel/AIAircraft.cxx +++ b/src/AIModel/AIAircraft.cxx @@ -184,6 +184,35 @@ void FGAIAircraft::Run(double dt) { } return; } + } else { + // no flight plan, update target heading, speed, and altitude + // from control properties. These default to the initial + // settings in the config file, but can be changed "on the + // fly". + + string lat_mode = props->getStringValue("controls/flight/lateral-mode"); + if ( lat_mode == "roll" ) { + double angle + = props->getDoubleValue("controls/flight/target-roll" ); + RollTo( angle ); + } else { + double angle + = props->getDoubleValue("controls/flight/target-hdg" ); + TurnTo( angle ); + } + + string lon_mode + = props->getStringValue("controls/flight/longitude-mode"); + if ( lon_mode == "alt" ) { + double alt = props->getDoubleValue("controls/flight/target-alt" ); + ClimbTo( alt ); + } else { + double angle + = props->getDoubleValue("controls/flight/target-pitch" ); + PitchTo( angle ); + } + + AccelTo( props->getDoubleValue("controls/flight/target-spd" ) ); } double turn_radius_ft; diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index 8746af4c1..1b73b39e7 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -223,6 +223,17 @@ void FGAIBase::bind() { props->setBoolValue("controls/lighting/beacon", true); props->setBoolValue("controls/lighting/strobe", true); props->setBoolValue("controls/glide-path", true); + + props->setStringValue("controls/flight/lateral-mode", "roll"); + props->setDoubleValue("controls/flight/target-hdg", hdg); + props->setDoubleValue("controls/flight/target-roll", roll); + + props->setStringValue("controls/flight/longitude-mode", "alt"); + props->setDoubleValue("controls/flight/target-alt", altitude); + props->setDoubleValue("controls/flight/target-pitch", pitch); + + props->setDoubleValue("controls/flight/target-spd", speed); + } void FGAIBase::unbind() {