From 50bdf6098ab7f45a044b5cb313923136f52f41fa Mon Sep 17 00:00:00 2001 From: ehofman Date: Sat, 19 Mar 2005 09:57:18 +0000 Subject: [PATCH] =?utf8?q?Mathias=20Fr=F6hlich:?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit I have done some cleanup where I moved some values out of classes where they do not belong and such stuff. Also the fols offsets are now named in the carrier xml file with a more verbose name (flols-pos/offset-*) than before (only offset-*). There is a little preparation for definitions of parking positions on the carrier which should later be used for starting flightgear directly on the carrier. --- src/AIModel/AIBase.hxx | 32 ++++++--------------- src/AIModel/AICarrier.cxx | 57 +++++++++++++++++++++++++++++--------- src/AIModel/AICarrier.hxx | 32 +++++++++------------ src/AIModel/AIManager.cxx | 16 ++++++----- src/AIModel/AIManager.hxx | 1 - src/AIModel/AIScenario.cxx | 37 +++++++++++++++++++------ src/AIModel/AIShip.cxx | 6 ++++ src/AIModel/AIShip.hxx | 5 ++++ 8 files changed, 113 insertions(+), 73 deletions(-) diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index 82c4de886..dacd7f9ec 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -73,12 +73,13 @@ typedef struct { list solid_objects; // List of solid object names list wire_objects; // List of wire object names list catapult_objects; // List of catapult object names - double radius; // used by ship ojects, in feet - double x_offset; // used by ship ojects, in meters - double y_offset; // used by ship ojects, in meters - double z_offset; // used by ship ojects, in meters - string acType; // used by aircraft objects - string company; // used by aircraft objects + list ppositions; // List of positions on a carrier where an aircraft can start. + Point3D flols_offset; // used by carrier objects, in meters + double radius; // used by ship objects, in feet + string name; // used by carrier objects + string pennant_number; // used by carrier objects + string acType; // used by aircraft objects + string company; // used by aircraft objects } FGAIModelEntity; @@ -91,7 +92,7 @@ public: virtual void update(double dt); inline Point3D GetPos() { return(pos); } - enum object_type { otNull = 0, otAircraft, otShip, otBallistic, + enum object_type { otNull = 0, otAircraft, otShip, otCarrier, otBallistic, otRocket, otStorm, otThermal, MAX_OBJECTS }; // Needs to be last!!! @@ -131,12 +132,6 @@ protected: double vs; // vertical speed, feet per minute double turn_radius_ft; // turn radius ft at 15 kts rudder angle 15 degrees - // these describe the flols - Point3D flolspos; // WGS84 lat & lon in degrees, elev above sea-level in meters - double flols_x_offset; // longitudinal distance, in meters - double flols_y_offset; // lateral distance, in meters - double flols_z_offset; // height, in meters - double ft_per_deg_lon; double ft_per_deg_lat; @@ -238,17 +233,6 @@ inline void FGAIBase::setRadius( double radius ) { turn_radius_ft = radius; } -inline void FGAIBase::setXoffset( double x_offset ) { - flols_x_offset = x_offset; -} - -inline void FGAIBase::setYoffset( double y_offset ) { - flols_y_offset = y_offset; -} - -inline void FGAIBase::setZoffset( double z_offset ) { - flols_z_offset = z_offset; -} inline void FGAIBase::setHeading( double heading ) { hdg = tgt_heading = heading; } diff --git a/src/AIModel/AICarrier.cxx b/src/AIModel/AICarrier.cxx index e6ab56147..45757dd9a 100644 --- a/src/AIModel/AICarrier.cxx +++ b/src/AIModel/AICarrier.cxx @@ -34,6 +34,8 @@ FGAICarrier::FGAICarrier(FGAIManager* mgr) : FGAIShip(mgr) { + _type_str = "carrier"; + _otype = otCarrier; } FGAICarrier::~FGAICarrier() { @@ -51,6 +53,18 @@ void FGAICarrier::setCatapultObjects(const list& co) { catapult_objects = co; } +void FGAICarrier::setParkingPositions(const list& p) { + ppositions = p; +} + +void FGAICarrier::setSign(const string& s) { + sign = s; +} + +void FGAICarrier::setFlolsOffset(const Point3D& off) { + flols_off = off; +} + void FGAICarrier::getVelocityWrtEarth(sgVec3 v) { sgCopyVec3(v, vel_wrt_earth ); } @@ -96,28 +110,31 @@ bool FGAICarrier::init() { return true; } + void FGAICarrier::bind() { - FGAIBase::bind(); + FGAIShip::bind(); props->tie("controls/flols/source-lights", SGRawValuePointer(&source)); props->tie("controls/flols/distance-m", - SGRawValuePointer(&dist)); + SGRawValuePointer(&dist)); props->tie("controls/flols/angle-degs", - SGRawValuePointer(&angle)); + SGRawValuePointer(&angle)); props->setBoolValue("controls/flols/cut-lights", false); props->setBoolValue("controls/flols/wave-off-lights", false); - props->setBoolValue("controls/flols/cond-datum-lights", true); - props->setBoolValue("controls/crew", false); - } + props->setBoolValue("controls/flols/cond-datum-lights", true); + props->setBoolValue("controls/crew", false); + + props->setStringValue("sign", sign.c_str()); +} void FGAICarrier::unbind() { - FGAIBase::unbind(); + FGAIShip::unbind(); props->untie("controls/flols/source-lights"); - props->untie("controls/flols/distance-m"); - props->untie("controls/flols/angle-degs"); + props->untie("controls/flols/distance-m"); + props->untie("controls/flols/angle-degs"); } - + void FGAICarrier::mark_nohot(ssgEntity* e) { if (e->isAKindOf(ssgTypeBranch())) { ssgBranch* br = (ssgBranch*)e; @@ -300,6 +317,20 @@ bool FGAICarrier::mark_cat(ssgEntity* e, const list& cat_objects, bool m } void FGAICarrier::UpdateFlols( double dt) { + + float trans[3][3]; + float in[3]; + float out[3]; + + float cosRx, sinRx; + float cosRy, sinRy; + float cosRz, sinRz; + + double flolsXYZ[3], eyeXYZ[3]; + double lat, lon, alt; + Point3D eyepos; + Point3D flolspos; + /* cout << "x_offset " << flols_x_offset << " y_offset " << flols_y_offset << " z_offset " << flols_z_offset << endl; @@ -326,9 +357,9 @@ void FGAICarrier::UpdateFlols( double dt) { << "flols_y_offset " << flols_y_offset << endl << "flols_z_offset " << flols_z_offset << endl;*/ - in[0] = flols_x_offset; - in[1] = flols_y_offset; - in[2] = flols_z_offset; + in[0] = flols_off.x(); + in[1] = flols_off.y(); + in[2] = flols_off.z(); // pre-process the trig functions diff --git a/src/AIModel/AICarrier.hxx b/src/AIModel/AICarrier.hxx index 6c9e77013..2844e7b4b 100644 --- a/src/AIModel/AICarrier.hxx +++ b/src/AIModel/AICarrier.hxx @@ -78,6 +78,9 @@ public: void setSolidObjects(const list& solid_objects); void setWireObjects(const list& wire_objects); void setCatapultObjects(const list& catapult_objects); + void setParkingPositions(const list& p); + void setSign(const string& ); + void setFlolsOffset(const Point3D& off); void getVelocityWrtEarth(sgVec3 v); virtual void bind(); @@ -86,6 +89,8 @@ public: bool init(); + static SGPropertyNode* getStartPosition(const string& id); + private: void update(double dt); @@ -97,29 +102,18 @@ private: list solid_objects; // List of solid object names list wire_objects; // List of wire object names list catapult_objects; // List of catapult object names + list ppositions; // List of positions where an aircraft can start. + string sign; // The sign of this carrier. // Velocity wrt earth. sgVec3 vel_wrt_earth; + + // these describe the flols + Point3D flols_off; - float trans[3][3]; - float in[3]; - float out[3]; - - double Rx, Ry, Rz; - double Sx, Sy, Sz; - double Tx, Ty, Tz; - - float cosRx, sinRx; - float cosRy, sinRy; - float cosRz, sinRz; - - double flolsXYZ[3], eyeXYZ[3]; - double lat, lon, alt; - double dist, angle; - int source; - - Point3D eyepos; - Point3D flolspos; + double dist; // the distance of the eyepoint from the flols + double angle; + int source; // the flols light which is visible at the moment }; #endif // _FG_AICARRIER_HXX diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index 52d8e3da9..6fc225e37 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -51,7 +51,7 @@ FGAIManager::FGAIManager() { } FGAIManager::~FGAIManager() { - ai_list_itr = ai_list.begin(); + ai_list_iterator ai_list_itr = ai_list.begin(); while(ai_list_itr != ai_list.end()) { (*ai_list_itr)->unbind(); delete (*ai_list_itr); @@ -105,7 +105,7 @@ void FGAIManager::update(double dt) { _dt = dt; - ai_list_itr = ai_list.begin(); + ai_list_iterator ai_list_itr = ai_list.begin(); while(ai_list_itr != ai_list.end()) { if ((*ai_list_itr)->getDie()) { tmgr->release((*ai_list_itr)->getID()); @@ -191,6 +191,7 @@ FGAIManager::createShip( FGAIModelEntity *entity ) { ai_ship->setLongitude(entity->longitude); ai_ship->setLatitude(entity->latitude); ai_ship->setBank(entity->rudder); + ai_ship->setName(entity->name); if ( entity->fp ) { ai_ship->setFlightPlan(entity->fp); @@ -209,7 +210,7 @@ FGAIManager::createCarrier( FGAIModelEntity *entity ) { FGAICarrier* ai_carrier = new FGAICarrier(this); ai_list.push_back(ai_carrier); ++numObjects[0]; - ++numObjects[FGAIBase::otShip]; + ++numObjects[FGAIBase::otCarrier]; ai_carrier->setHeading(entity->heading); ai_carrier->setSpeed(entity->speed); ai_carrier->setPath(entity->path.c_str()); @@ -220,10 +221,11 @@ FGAIManager::createCarrier( FGAIModelEntity *entity ) { ai_carrier->setSolidObjects(entity->solid_objects); ai_carrier->setWireObjects(entity->wire_objects); ai_carrier->setCatapultObjects(entity->catapult_objects); + ai_carrier->setParkingPositions(entity->ppositions); ai_carrier->setRadius(entity->radius); - ai_carrier->setXoffset(entity->x_offset); - ai_carrier->setYoffset(entity->y_offset); - ai_carrier->setZoffset(entity->z_offset); + ai_carrier->setSign(entity->pennant_number); + ai_carrier->setName(entity->name); + ai_carrier->setFlolsOffset(entity->flols_offset); if ( entity->fp ) { ai_carrier->setFlightPlan(entity->fp); @@ -298,7 +300,7 @@ FGAIManager::createThermal( FGAIModelEntity *entity ) { } void FGAIManager::destroyObject( void* ID ) { - ai_list_itr = ai_list.begin(); + ai_list_iterator ai_list_itr = ai_list.begin(); while(ai_list_itr != ai_list.end()) { if ((*ai_list_itr)->getID() == ID) { --numObjects[0]; diff --git a/src/AIModel/AIManager.hxx b/src/AIModel/AIManager.hxx index 4dfe74932..9874859aa 100644 --- a/src/AIModel/AIManager.hxx +++ b/src/AIModel/AIManager.hxx @@ -69,7 +69,6 @@ private: // Everything put in this list should be created dynamically // on the heap and ***DELETED WHEN REMOVED!!!!!*** ai_list_type ai_list; - ai_list_iterator ai_list_itr; ModelVec loadedModels; public: diff --git a/src/AIModel/AIScenario.cxx b/src/AIModel/AIScenario.cxx index 6c8a75770..f8c6e56ce 100644 --- a/src/AIModel/AIScenario.cxx +++ b/src/AIModel/AIScenario.cxx @@ -34,7 +34,9 @@ #include "AIFlightPlan.hxx" static list -getAllNodeVals(const char* name, SGPropertyNode * entry_node); +getAllStringNodeVals(const char* name, SGPropertyNode * entry_node); +static list +getAllOffsetNodeVals(const char* name, SGPropertyNode * entry_node); FGAIScenario::FGAIScenario(string &filename) { @@ -96,13 +98,14 @@ FGAIScenario::FGAIScenario(string &filename) en->cd = entry_node->getDoubleValue("cd", 0.029); en->mass = entry_node->getDoubleValue("mass", 0.007); en->radius = entry_node->getDoubleValue("turn-radius-ft", 2000); - en->x_offset = entry_node->getDoubleValue("x-offset-m", 5.5); - en->y_offset = entry_node->getDoubleValue("y-offset-m", 1.0); - en->z_offset = entry_node->getDoubleValue("z-offset-m", 1.0); - /* en->name = entry_node->getStringValue("name", "");*/ - en->wire_objects = getAllNodeVals("wire", entry_node); - en->catapult_objects = getAllNodeVals("catapult", entry_node); - en->solid_objects = getAllNodeVals("solid", entry_node); + en->name = entry_node->getStringValue("name", ""); + en->pennant_number = entry_node->getStringValue("pennant-number", ""); + en->wire_objects = getAllStringNodeVals("wire", entry_node); + en->catapult_objects = getAllStringNodeVals("catapult", entry_node); + en->solid_objects = getAllStringNodeVals("solid", entry_node); + en->ppositions = getAllOffsetNodeVals("parking-pos", entry_node); + list flolspos = getAllOffsetNodeVals("flols-pos", entry_node); + en->flols_offset = flolspos.front(); en->fp = NULL; if (en->flightplan != ""){ @@ -139,7 +142,7 @@ int FGAIScenario::nEntries( void ) } static list -getAllNodeVals(const char* name, SGPropertyNode * entry_node) +getAllStringNodeVals(const char* name, SGPropertyNode * entry_node) { list retval; int i=0; @@ -157,6 +160,22 @@ getAllNodeVals(const char* name, SGPropertyNode * entry_node) return retval; } +static list +getAllOffsetNodeVals(const char* name, SGPropertyNode * entry_node) +{ + list retval; + + vector::iterator it; + vector children = entry_node->getChildren(name); + for (it = children.begin(); it != children.end(); ++it) { + double offset_x = (*it)->getDoubleValue("x-offset-m", 0); + double offset_y = (*it)->getDoubleValue("y-offset-m", 0); + double offset_z = (*it)->getDoubleValue("z-offset-m", 0); + retval.push_back(Point3D(offset_x, offset_y, offset_z)); + } + + return retval; +} // end scenario.cxx diff --git a/src/AIModel/AIShip.cxx b/src/AIModel/AIShip.cxx index 1aabe5875..2d8fc31a8 100644 --- a/src/AIModel/AIShip.cxx +++ b/src/AIModel/AIShip.cxx @@ -49,6 +49,8 @@ void FGAIShip::bind() { props->tie("surface-positions/rudder-pos-deg", SGRawValuePointer(&rudder)); + + props->setStringValue("name", name.c_str()); } void FGAIShip::unbind() { @@ -194,6 +196,10 @@ void FGAIShip::setFlightPlan(FGAIFlightPlan* f) { fp = f; } +void FGAIShip::setName(const string& n) { + name = n; +} + void FGAIShip::ProcessFlightPlan(double dt) { // not implemented yet } diff --git a/src/AIModel/AIShip.hxx b/src/AIModel/AIShip.hxx index 25d8b4495..97412a922 100644 --- a/src/AIModel/AIShip.hxx +++ b/src/AIModel/AIShip.hxx @@ -36,6 +36,7 @@ public: virtual void unbind(); void update(double dt); void setFlightPlan(FGAIFlightPlan* f); + void setName(const string&); void ProcessFlightPlan( double dt ); void AccelTo(double speed); @@ -45,6 +46,10 @@ public: void ClimbTo(double altitude); void TurnTo(double heading); +protected: + + string name; // The name of this ship. + private: bool hdg_lock; -- 2.39.5