From af284e4bb922a3782c9bd9d947895e787e41adbf Mon Sep 17 00:00:00 2001 From: ehofman Date: Mon, 30 Aug 2004 09:11:59 +0000 Subject: [PATCH] David Culp: Here are small changes that allow one to set a life-span for submodels. --- src/AIModel/AIBallistic.cxx | 8 ++++++++ src/AIModel/AIBallistic.hxx | 2 ++ src/AIModel/AIBase.cxx | 1 + src/AIModel/AIBase.hxx | 1 + src/AIModel/AIManager.cxx | 5 +++-- src/AIModel/AIManager.hxx | 3 ++- src/AIModel/AIScenario.cxx | 1 + src/AIModel/AIScenario.hxx | 1 + src/Systems/submodel.cxx | 3 ++- src/Systems/submodel.hxx | 1 + 10 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/AIModel/AIBallistic.cxx b/src/AIModel/AIBallistic.cxx index ff1264114..e06bf9f4b 100644 --- a/src/AIModel/AIBallistic.cxx +++ b/src/AIModel/AIBallistic.cxx @@ -32,6 +32,7 @@ FGAIBallistic::FGAIBallistic(FGAIManager* mgr) { _type_str = "ballistic"; _otype = otBallistic; drag_area = 0.007; + life_timer = 0.0; } FGAIBallistic::~FGAIBallistic() { @@ -79,8 +80,15 @@ void FGAIBallistic::setDragArea(double a) { drag_area = a; } +void FGAIBallistic::setLife(double seconds) { + life = seconds; +} + void FGAIBallistic::Run(double dt) { + life_timer += dt; + if (life_timer > life) setDie(true); + double speed_north_deg_sec; double speed_east_deg_sec; diff --git a/src/AIModel/AIBallistic.hxx b/src/AIModel/AIBallistic.hxx index b6bf789d8..8eb022818 100644 --- a/src/AIModel/AIBallistic.hxx +++ b/src/AIModel/AIBallistic.hxx @@ -40,6 +40,7 @@ public: void setElevation( double el ); void setStabilization( bool val ); void setDragArea( double a ); + void setLife( double seconds ); private: @@ -48,6 +49,7 @@ private: double hs; // horizontal speed (fps) bool aero_stabilized; // if true, object will point where it's going double drag_area; // equivalent drag area in ft2 + double life_timer; // seconds void Run(double dt); }; diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index dc48ca2b9..a91f8d0a9 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -51,6 +51,7 @@ FGAIBase::FGAIBase() { in_range = false; invisible = true; no_roll = true; + life = 900; model_path = ""; model = 0; _otype = otNull; diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index 9bb85fa24..a46e94526 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -108,6 +108,7 @@ protected: int id; bool invisible; bool no_roll; + double life; FGAIFlightPlan *fp; void Transform(); diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index 951b61d95..de5f7de45 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -253,7 +253,7 @@ int FGAIManager::createShip( string path, FGAIFlightPlan* flightplan ) { int FGAIManager::createBallistic( string path, double latitude, double longitude, double altitude, double azimuth, double elevation, - double speed, double eda ) { + double speed, double eda, double life ) { FGAIBallistic* ai_ballistic = new FGAIBallistic(this); ai_list.push_back(ai_ballistic); @@ -267,6 +267,7 @@ int FGAIManager::createBallistic( string path, double latitude, double longitude ai_ballistic->setLongitude(longitude); ai_ballistic->setLatitude(latitude); ai_ballistic->setDragArea(eda); + ai_ballistic->setLife(life); ai_ballistic->init(); ai_ballistic->bind(); return ai_ballistic->getID(); @@ -384,7 +385,7 @@ void FGAIManager::processScenario( string filename ) { } else if (en->aitype == "ballistic"){ createBallistic( en->model_path, en->latitude, en->longitude, en->altitude, en->azimuth, en->elevation, en->speed, - en->eda ); + en->eda, en->life ); } } } diff --git a/src/AIModel/AIManager.hxx b/src/AIModel/AIManager.hxx index b3b06a4b8..8db9d6f5f 100644 --- a/src/AIModel/AIManager.hxx +++ b/src/AIModel/AIManager.hxx @@ -98,7 +98,8 @@ public: double azimuth, // in degrees (same as heading) double elevation, // in degrees (same as pitch) double speed, // in feet per second - double eda ); // equivalent drag area, ft2 + double eda, // equivalent drag area, ft2 + double life ); // life span in seconds int createStorm( string path, // path to exterior model double latitude, // in degrees -90 to 90 diff --git a/src/AIModel/AIScenario.cxx b/src/AIModel/AIScenario.cxx index f16991d81..25b484c77 100644 --- a/src/AIModel/AIScenario.cxx +++ b/src/AIModel/AIScenario.cxx @@ -70,6 +70,7 @@ FGAIScenario::FGAIScenario(string filename) en->strength = entry_node->getDoubleValue("strength-fps", 0.0); en->diameter = entry_node->getDoubleValue("diameter-ft", 0.0); en->eda = entry_node->getDoubleValue("eda", 0.007); + en->life = entry_node->getDoubleValue("life", 900.0); } entry_iterator = entries.begin(); diff --git a/src/AIModel/AIScenario.hxx b/src/AIModel/AIScenario.hxx index 26ced88cf..8d1c6b549 100644 --- a/src/AIModel/AIScenario.hxx +++ b/src/AIModel/AIScenario.hxx @@ -49,6 +49,7 @@ public: double strength; // used by thermal objects double diameter; // used by thermal objects double eda; // used by ballistic objects + double life; // life span in seconds } entry; FGAIScenario(string filename); diff --git a/src/Systems/submodel.cxx b/src/Systems/submodel.cxx index 87f79eaa4..f22146281 100644 --- a/src/Systems/submodel.cxx +++ b/src/Systems/submodel.cxx @@ -88,7 +88,7 @@ SubmodelSystem::release (submodel* sm, double dt) //cout << "Creating a submodel." << endl; int rval = ai->createBallistic( sm->model, IC.lat, IC.lon, IC.alt, IC.azimuth, - IC.elevation, IC.speed, sm->drag_area ); + IC.elevation, IC.speed, sm->drag_area, sm->life ); //cout << "Submodel created." << endl; (sm->count)--; @@ -136,6 +136,7 @@ SubmodelSystem::load () sm->yaw_offset = entry_node->getDoubleValue("yaw-offset", 0.0); sm->pitch_offset = entry_node->getDoubleValue("pitch-offset", 0.0); sm->drag_area = entry_node->getDoubleValue("eda", 0.007); + sm->life = entry_node->getDoubleValue("life", 900.0); sm->trigger->setBoolValue(false); sm->timer = sm->delay; diff --git a/src/Systems/submodel.hxx b/src/Systems/submodel.hxx index 93f6ab32e..f088173a0 100644 --- a/src/Systems/submodel.hxx +++ b/src/Systems/submodel.hxx @@ -41,6 +41,7 @@ public: double yaw_offset; double pitch_offset; double drag_area; + double life; } submodel; typedef struct {