From: ehofman Date: Sat, 4 Jun 2005 09:38:52 +0000 (+0000) Subject: David Culp: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ab83702c16d7c5c2fea991ab485ff81f9778bf92;p=flightgear.git David Culp: I added an AIStatic object to my OV-10 sim for use in putting city signs, vehicles, or anything else that will be static, but that I don't want to put in the scenery files. It's inexpensive. Before, I was making such things from AIShip. I also added the ability to set flight plans to repeat, so that when an airplane reaches the end it just starts over at the beginning. This is useful for my OV-10 sim. I have C-141 and KC-135 traffic flying approaches to Ramstein, and I only have to define two AI objects to do this. Also, I found an inefficiency in AIBase, where every AI object was calculating Mach number at every dt. Now only AIBallistic objects do this. --- diff --git a/src/AIModel/AIAircraft.cxx b/src/AIModel/AIAircraft.cxx index 3c73b7825..efe563057 100644 --- a/src/AIModel/AIAircraft.cxx +++ b/src/AIModel/AIAircraft.cxx @@ -584,7 +584,12 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) // Current waypoint's elevation according to Terrain Elevation if (curr->finished) { //end of the flight plan { - setDie(true); + if (fp->getRepeat()) { + fp->restart(); + } else { + setDie(true); + } + //cerr << "Done die end of fp" << endl; } return; diff --git a/src/AIModel/AIAircraft.hxx b/src/AIModel/AIAircraft.hxx index ad1c7dae1..022572563 100644 --- a/src/AIModel/AIAircraft.hxx +++ b/src/AIModel/AIAircraft.hxx @@ -61,6 +61,7 @@ public: void SetPerformance(const PERF_STRUCT *ps); void SetFlightPlan(FGAIFlightPlan *f); + FGAIFlightPlan* GetFlightPlan() { return fp; }; void AccelTo(double speed); void PitchTo(double angle); void RollTo(double angle); diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index 8a618ab2d..d66de0300 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -81,41 +81,11 @@ FGAIBase::~FGAIBase() { } void FGAIBase::update(double dt) { + if (_otype == otStatic) return; + if (_otype == otBallistic) CalculateMach(); + ft_per_deg_lat = 366468.96 - 3717.12 * cos(pos.lat()*SGD_DEGREES_TO_RADIANS); ft_per_deg_lon = 365228.16 * cos(pos.lat()*SGD_DEGREES_TO_RADIANS); - - // Calculate rho at altitude, using standard atmosphere - // For the temperature T and the pressure p, - - if (altitude < 36152) { // curve fits for the troposphere - T = 59 - 0.00356 * altitude; - p = 2116 * pow( ((T + 459.7) / 518.6) , 5.256); - - } else if ( 36152 < altitude && altitude < 82345 ) { // lower stratosphere - T = -70; - p = 473.1 * pow( e , 1.73 - (0.000048 * altitude) ); - - } else { // upper stratosphere - T = -205.05 + (0.00164 * altitude); - p = 51.97 * pow( ((T + 459.7) / 389.98) , -11.388); - } - - rho = p / (1718 * (T + 459.7)); - - // calculate the speed of sound at altitude - // a = sqrt ( g * R * (T + 459.7)) - // where: - // a = speed of sound [ft/s] - // g = specific heat ratio, which is usually equal to 1.4 - // R = specific gas constant, which equals 1716 ft-lb/slug/°R - - a = sqrt ( 1.4 * 1716 * (T + 459.7)); - - // calculate Mach number - - Mach = speed/a; - -// cout << "Speed(ft/s) "<< speed <<" Altitude(ft) "<< altitude << " Mach " << Mach; } void FGAIBase::Transform() { @@ -393,3 +363,39 @@ bool FGAIBase::_isNight() { int FGAIBase::_getID() const { return (int)(this); } + +void FGAIBase::CalculateMach() { + // Calculate rho at altitude, using standard atmosphere + // For the temperature T and the pressure p, + + if (altitude < 36152) { // curve fits for the troposphere + T = 59 - 0.00356 * altitude; + p = 2116 * pow( ((T + 459.7) / 518.6) , 5.256); + + } else if ( 36152 < altitude && altitude < 82345 ) { // lower stratosphere + T = -70; + p = 473.1 * pow( e , 1.73 - (0.000048 * altitude) ); + + } else { // upper stratosphere + T = -205.05 + (0.00164 * altitude); + p = 51.97 * pow( ((T + 459.7) / 389.98) , -11.388); + } + + rho = p / (1718 * (T + 459.7)); + + // calculate the speed of sound at altitude + // a = sqrt ( g * R * (T + 459.7)) + // where: + // a = speed of sound [ft/s] + // g = specific heat ratio, which is usually equal to 1.4 + // R = specific gas constant, which equals 1716 ft-lb/slug/°R + + a = sqrt ( 1.4 * 1716 * (T + 459.7)); + + // calculate Mach number + + Mach = speed/a; + + // cout << "Speed(ft/s) "<< speed <<" Altitude(ft) "<< altitude << " Mach " << Mach; +} + diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index 88c6bde7c..14467a236 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -40,7 +40,7 @@ class FGAIFlightPlan; typedef struct { string callsign; - // can be aircraft, ship, storm, thermal or ballistic + // can be aircraft, ship, storm, thermal, static or ballistic string m_type; string m_class; string path; @@ -93,7 +93,7 @@ public: inline Point3D GetPos() { return(pos); } enum object_type { otNull = 0, otAircraft, otShip, otCarrier, otBallistic, - otRocket, otStorm, otThermal, + otRocket, otStorm, otThermal, otStatic, MAX_OBJECTS }; // Needs to be last!!! virtual bool init(); @@ -167,7 +167,7 @@ protected: FGAIFlightPlan *fp; void Transform(); - + void CalculateMach(); double UpdateRadar(FGAIManager* manager); string _type_str; diff --git a/src/AIModel/AIFlightPlan.cxx b/src/AIModel/AIFlightPlan.cxx index 19321f2bf..025f03e21 100644 --- a/src/AIModel/AIFlightPlan.cxx +++ b/src/AIModel/AIFlightPlan.cxx @@ -50,6 +50,7 @@ FGAIFlightPlan::FGAIFlightPlan(string filename) SGPath path( globals->get_fg_root() ); path.append( ("/Data/AI/FlightPlans/" + filename).c_str() ); SGPropertyNode root; + repeat = false; try { readProperties(path.str(), &root); @@ -472,3 +473,9 @@ void FGAIFlightPlan::resetWaypoints() waypoints.push_back(wpt); } } + +// Start flightplan over from the beginning +void FGAIFlightPlan::restart() +{ + wpt_iterator = waypoints.begin(); +} diff --git a/src/AIModel/AIFlightPlan.hxx b/src/AIModel/AIFlightPlan.hxx index c527a5782..a6ae1182e 100644 --- a/src/AIModel/AIFlightPlan.hxx +++ b/src/AIModel/AIFlightPlan.hxx @@ -85,18 +85,23 @@ public: double getLeadInAngle() { return leadInAngle; }; string getRunway() { return rwy._rwy_no; }; string getRunwayId() { return rwy._id; }; + void setRepeat(bool r) { repeat = r; }; + bool getRepeat(void) { return repeat; }; + void restart(void); + private: FGRunway rwy; - typedef vector wpt_vector_type; - typedef wpt_vector_type::iterator wpt_vector_iterator; + typedef vector wpt_vector_type; + typedef wpt_vector_type::iterator wpt_vector_iterator; - wpt_vector_type waypoints; - wpt_vector_iterator wpt_iterator; + wpt_vector_type waypoints; + wpt_vector_iterator wpt_iterator; - double distance_to_go; - double lead_distance; + bool repeat; + double distance_to_go; + double lead_distance; double leadInAngle; - time_t start_time; + time_t start_time; int leg; int gateId; diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index d5d639292..fd121ed28 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -36,6 +36,7 @@ #include "AIStorm.hxx" #include "AIThermal.hxx" #include "AICarrier.hxx" +#include "AIStatic.hxx" SG_USING_STD(list); @@ -176,7 +177,9 @@ FGAIManager::createAircraft( FGAIModelEntity *entity, FGAISchedule *ref) { if ( entity->fp ) { ai_plane->SetFlightPlan(entity->fp); } - + if (entity->repeat) { + ai_plane->GetFlightPlan()->setRepeat(true); + } ai_plane->init(); ai_plane->bind(); return ai_plane; @@ -310,6 +313,25 @@ FGAIManager::createThermal( FGAIModelEntity *entity ) { return ai_thermal; } +void* +FGAIManager::createStatic( FGAIModelEntity *entity ) { + + // cout << "creating static object" << endl; + + FGAIStatic* ai_static = new FGAIStatic(this); + ai_list.push_back(ai_static); + ++numObjects[0]; + ++numObjects[FGAIBase::otStatic]; + ai_static->setHeading(entity->heading); + ai_static->setPath(entity->path.c_str()); + ai_static->setAltitude(entity->altitude); + ai_static->setLongitude(entity->longitude); + ai_static->setLatitude(entity->latitude); + ai_static->init(); + ai_static->bind(); + return ai_static; +} + void FGAIManager::destroyObject( void* ID ) { ai_list_iterator ai_list_itr = ai_list.begin(); while(ai_list_itr != ai_list.end()) { @@ -371,7 +393,10 @@ void FGAIManager::processScenario( string &filename ) { } else if ( en->m_type == "ballistic") { createBallistic( en ); - } + + } else if ( en->m_type == "static") { + createStatic( en ); + } } } diff --git a/src/AIModel/AIManager.hxx b/src/AIModel/AIManager.hxx index cc18831ab..25c3b3d9b 100644 --- a/src/AIModel/AIManager.hxx +++ b/src/AIModel/AIManager.hxx @@ -1,4 +1,4 @@ -// AIManager.hxx - experimental! - David Culp - based on: +// AIManager.hxx - David Culp - based on: // AIMgr.hxx - definition of FGAIMgr // - a global management class for FlightGear generated AI traffic // @@ -87,6 +87,7 @@ public: void* createStorm( FGAIModelEntity *entity ); void* createShip( FGAIModelEntity *entity ); void* createCarrier( FGAIModelEntity *entity ); + void* createStatic( FGAIModelEntity *entity ); void destroyObject( void* ID ); diff --git a/src/AIModel/AIStatic.cxx b/src/AIModel/AIStatic.cxx new file mode 100644 index 000000000..148aaacfa --- /dev/null +++ b/src/AIModel/AIStatic.cxx @@ -0,0 +1,65 @@ +// FGAIStatic - FGAIBase-derived class creates an AI static object +// +// Written by David Culp, started Jun 2005. +// +// Copyright (C) 2005 David P. Culp - davidculp2@comcast.net +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include
+#include
+#include +#include +#include + +SG_USING_STD(string); + +#include "AIStatic.hxx" + + +FGAIStatic::FGAIStatic(FGAIManager* mgr) { + manager = mgr; + _type_str = "static"; + _otype = otStatic; +} + + +FGAIStatic::~FGAIStatic() { +} + + +bool FGAIStatic::init() { + return FGAIBase::init(); +} + +void FGAIStatic::bind() { + FGAIBase::bind(); +} + +void FGAIStatic::unbind() { + FGAIBase::unbind(); +} + + +void FGAIStatic::update(double dt) { + FGAIBase::update(dt); + Transform(); +} + diff --git a/src/AIModel/AIStatic.hxx b/src/AIModel/AIStatic.hxx new file mode 100644 index 000000000..25c9b011f --- /dev/null +++ b/src/AIModel/AIStatic.hxx @@ -0,0 +1,51 @@ +// FGAIStatic - AIBase derived class creates AI static object +// +// Written by David Culp, started Jun 2005. +// +// Copyright (C) 2005 David P. Culp - davidculp2@comcast.net +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef _FG_AIStatic_HXX +#define _FG_AIStatic_HXX + +#include "AIManager.hxx" +#include "AIBase.hxx" + +#include +SG_USING_STD(string); + + +class FGAIStatic : public FGAIBase { + +public: + + FGAIStatic(FGAIManager* mgr); + ~FGAIStatic(); + + bool init(); + virtual void bind(); + virtual void unbind(); + void update(double dt); + +private: + + double dt; + +}; + + + +#endif // _FG_AISTATIC_HXX diff --git a/src/AIModel/Makefile.am b/src/AIModel/Makefile.am index fc2aafeec..e02adc4f0 100644 --- a/src/AIModel/Makefile.am +++ b/src/AIModel/Makefile.am @@ -11,6 +11,7 @@ libAIModel_a_SOURCES = \ AIThermal.hxx AIThermal.cxx \ AIFlightPlan.hxx AIFlightPlan.cxx AIFlightPlanCreate.cxx \ AIScenario.hxx AIScenario.cxx \ - AICarrier.hxx AICarrier.cxx + AICarrier.hxx AICarrier.cxx \ + AIStatic.hxx AIStatic.cxx INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src