diff --git a/src/FDM/YASim/Hitch.cpp b/src/FDM/YASim/Hitch.cpp index f1765e995..3be986d69 100755 --- a/src/FDM/YASim/Hitch.cpp +++ b/src/FDM/YASim/Hitch.cpp @@ -1,8 +1,8 @@ #include "Math.hpp" #include "BodyEnvironment.hpp" #include "RigidBody.hpp" -#include
#include +#include @@ -64,93 +64,90 @@ Hitch::Hitch(const char *name) //tie the properties char text[128]; sprintf(text,"/sim/hitches/%s", _name); - SGPropertyNode * node = fgGetNode(text, true); - node->tie("tow/length",SGRawValuePointer(&_towLength)); - node->tie("tow/elastic-constant",SGRawValuePointer(&_towElasticConstant)); - node->tie("tow/weight-per-m-kg-m",SGRawValuePointer(&_towWeightPerM)); - node->tie("tow/brake-force",SGRawValuePointer(&_towBrakeForce)); - node->tie("winch/max-speed-m-s",SGRawValuePointer(&_winchMaxSpeed)); - node->tie("winch/rel-speed",SGRawValuePointer(&_winchRelSpeed)); - node->tie("winch/initial-tow-length-m",SGRawValuePointer(&_winchInitialTowLength)); - node->tie("winch/min-tow-length-m",SGRawValuePointer(&_winchMinTowLength)); - node->tie("winch/max-tow-length-m",SGRawValuePointer(&_winchMaxTowLength)); - node->tie("winch/global-pos-x",SGRawValuePointer(&_winchPos[0])); - node->tie("winch/global-pos-y",SGRawValuePointer(&_winchPos[1])); - node->tie("winch/global-pos-z",SGRawValuePointer(&_winchPos[2])); - node->tie("winch/max-power",SGRawValuePointer(&_winchPower)); - node->tie("winch/max-force",SGRawValuePointer(&_winchMaxForce)); - node->tie("winch/actual-force",SGRawValuePointer(&_winchActualForce)); - node->tie("tow/end-force-x",SGRawValuePointer(&_reportTowEndForce[0])); - node->tie("tow/end-force-y",SGRawValuePointer(&_reportTowEndForce[1])); - node->tie("tow/end-force-z",SGRawValuePointer(&_reportTowEndForce[2])); - node->tie("force",SGRawValuePointer(&_forceMagnitude)); - node->tie("open",SGRawValuePointer(&_open)); - node->tie("force-is-calculated-by-other",SGRawValuePointer(&_forceIsCalculatedByMaster)); - node->tie("local-pos-x",SGRawValuePointer(&_pos[0])); - node->tie("local-pos-y",SGRawValuePointer(&_pos[1])); - node->tie("local-pos-z",SGRawValuePointer(&_pos[2])); - node->tie("tow/dist",SGRawValuePointer(&_dist)); - node->tie("tow/dist-time-lag-corrected",SGRawValuePointer(&_timeLagCorrectedDist)); - node->tie("tow/connected-to-property-node",SGRawValuePointer(&_towEndIsConnectedToProperty)); - node->tie("tow/connected-to-mp-node",SGRawValuePointer(&_nodeIsMultiplayer)); - node->tie("tow/connected-to-ai-node",SGRawValuePointer(&_nodeIsAiAircraft)); - node->tie("tow/connected-to-ai-or-mp-id",SGRawValuePointer(&_nodeID)); - node->tie("debug/hitch-height-above-ground",SGRawValuePointer(&_height_above_ground)); - node->tie("debug/tow-end-height-above-ground",SGRawValuePointer(&_winch_height_above_ground)); - node->tie("debug/tow-rel-lo-pos",SGRawValuePointer(&_loPosFrac)); - node->tie("debug/tow-lowest-pos-height",SGRawValuePointer(&_lowest_tow_height)); - node->tie("is-slave",SGRawValuePointer(&_isSlave)); - node->tie("speed-in-tow-direction",SGRawValuePointer(&_speed_in_tow_direction)); - node->tie("mp-auto-connect-period",SGRawValuePointer(&_mpAutoConnectPeriod)); - node->tie("mp-time-lag",SGRawValuePointer(&_mp_time_lag)); - node->setStringValue("tow/node",""); - node->setStringValue("tow/connected-to-ai-or-mp-callsign"); - node->setBoolValue("broken",false); + _node = fgGetNode(text, true); + _node->tie("tow/length",SGRawValuePointer(&_towLength)); + _node->tie("tow/elastic-constant",SGRawValuePointer(&_towElasticConstant)); + _node->tie("tow/weight-per-m-kg-m",SGRawValuePointer(&_towWeightPerM)); + _node->tie("tow/brake-force",SGRawValuePointer(&_towBrakeForce)); + _node->tie("winch/max-speed-m-s",SGRawValuePointer(&_winchMaxSpeed)); + _node->tie("winch/rel-speed",SGRawValuePointer(&_winchRelSpeed)); + _node->tie("winch/initial-tow-length-m",SGRawValuePointer(&_winchInitialTowLength)); + _node->tie("winch/min-tow-length-m",SGRawValuePointer(&_winchMinTowLength)); + _node->tie("winch/max-tow-length-m",SGRawValuePointer(&_winchMaxTowLength)); + _node->tie("winch/global-pos-x",SGRawValuePointer(&_winchPos[0])); + _node->tie("winch/global-pos-y",SGRawValuePointer(&_winchPos[1])); + _node->tie("winch/global-pos-z",SGRawValuePointer(&_winchPos[2])); + _node->tie("winch/max-power",SGRawValuePointer(&_winchPower)); + _node->tie("winch/max-force",SGRawValuePointer(&_winchMaxForce)); + _node->tie("winch/actual-force",SGRawValuePointer(&_winchActualForce)); + _node->tie("tow/end-force-x",SGRawValuePointer(&_reportTowEndForce[0])); + _node->tie("tow/end-force-y",SGRawValuePointer(&_reportTowEndForce[1])); + _node->tie("tow/end-force-z",SGRawValuePointer(&_reportTowEndForce[2])); + _node->tie("force",SGRawValuePointer(&_forceMagnitude)); + _node->tie("open",SGRawValuePointer(&_open)); + _node->tie("force-is-calculated-by-other",SGRawValuePointer(&_forceIsCalculatedByMaster)); + _node->tie("local-pos-x",SGRawValuePointer(&_pos[0])); + _node->tie("local-pos-y",SGRawValuePointer(&_pos[1])); + _node->tie("local-pos-z",SGRawValuePointer(&_pos[2])); + _node->tie("tow/dist",SGRawValuePointer(&_dist)); + _node->tie("tow/dist-time-lag-corrected",SGRawValuePointer(&_timeLagCorrectedDist)); + _node->tie("tow/connected-to-property-node",SGRawValuePointer(&_towEndIsConnectedToProperty)); + _node->tie("tow/connected-to-mp-node",SGRawValuePointer(&_nodeIsMultiplayer)); + _node->tie("tow/connected-to-ai-node",SGRawValuePointer(&_nodeIsAiAircraft)); + _node->tie("tow/connected-to-ai-or-mp-id",SGRawValuePointer(&_nodeID)); + _node->tie("debug/hitch-height-above-ground",SGRawValuePointer(&_height_above_ground)); + _node->tie("debug/tow-end-height-above-ground",SGRawValuePointer(&_winch_height_above_ground)); + _node->tie("debug/tow-rel-lo-pos",SGRawValuePointer(&_loPosFrac)); + _node->tie("debug/tow-lowest-pos-height",SGRawValuePointer(&_lowest_tow_height)); + _node->tie("is-slave",SGRawValuePointer(&_isSlave)); + _node->tie("speed-in-tow-direction",SGRawValuePointer(&_speed_in_tow_direction)); + _node->tie("mp-auto-connect-period",SGRawValuePointer(&_mpAutoConnectPeriod)); + _node->tie("mp-time-lag",SGRawValuePointer(&_mp_time_lag)); + _node->setStringValue("tow/node",""); + _node->setStringValue("tow/connected-to-ai-or-mp-callsign"); + _node->setBoolValue("broken",false); } Hitch::~Hitch() { - char text[128]; - sprintf(text,"/sim/hitches/%s", _name); - SGPropertyNode * node = fgGetNode(text, true); - node->untie("tow/length"); - node->untie("tow/elastic-constant"); - node->untie("tow/weight-per-m-kg-m"); - node->untie("tow/brake-force"); - node->untie("winch/max-speed-m-s"); - node->untie("winch/rel-speed"); - node->untie("winch/initial-tow-length-m"); - node->untie("winch/min-tow-length-m"); - node->untie("winch/max-tow-length-m"); - node->untie("winch/global-pos-x"); - node->untie("winch/global-pos-y"); - node->untie("winch/global-pos-z"); - node->untie("winch/max-power"); - node->untie("winch/max-force"); - node->untie("winch/actual-force"); - node->untie("tow/end-force-x"); - node->untie("tow/end-force-y"); - node->untie("tow/end-force-z"); - node->untie("force"); - node->untie("open"); - node->untie("force-is-calculated-by-other"); - node->untie("local-pos-x"); - node->untie("local-pos-y"); - node->untie("local-pos-z"); - node->untie("tow/dist"); - node->untie("tow/dist-time-lag-corrected"); - node->untie("tow/connected-to-property-node"); - node->untie("tow/connected-to-mp-node"); - node->untie("tow/connected-to-ai-node"); - node->untie("tow/connected-to-ai-or-mp-id"); - node->untie("debug/hitch-height-above-ground"); - node->untie("debug/tow-end-height-above-ground"); - node->untie("debug/tow-rel-lo-pos"); - node->untie("debug/tow-lowest-pos-height"); - node->untie("is-slave"); - node->untie("speed-in-tow-direction"); - node->untie("mp-auto-connect-period"); - node->untie("mp-time-lag"); + _node->untie("tow/length"); + _node->untie("tow/elastic-constant"); + _node->untie("tow/weight-per-m-kg-m"); + _node->untie("tow/brake-force"); + _node->untie("winch/max-speed-m-s"); + _node->untie("winch/rel-speed"); + _node->untie("winch/initial-tow-length-m"); + _node->untie("winch/min-tow-length-m"); + _node->untie("winch/max-tow-length-m"); + _node->untie("winch/global-pos-x"); + _node->untie("winch/global-pos-y"); + _node->untie("winch/global-pos-z"); + _node->untie("winch/max-power"); + _node->untie("winch/max-force"); + _node->untie("winch/actual-force"); + _node->untie("tow/end-force-x"); + _node->untie("tow/end-force-y"); + _node->untie("tow/end-force-z"); + _node->untie("force"); + _node->untie("open"); + _node->untie("force-is-calculated-by-other"); + _node->untie("local-pos-x"); + _node->untie("local-pos-y"); + _node->untie("local-pos-z"); + _node->untie("tow/dist"); + _node->untie("tow/dist-time-lag-corrected"); + _node->untie("tow/connected-to-property-node"); + _node->untie("tow/connected-to-mp-node"); + _node->untie("tow/connected-to-ai-node"); + _node->untie("tow/connected-to-ai-or-mp-id"); + _node->untie("debug/hitch-height-above-ground"); + _node->untie("debug/tow-end-height-above-ground"); + _node->untie("debug/tow-rel-lo-pos"); + _node->untie("debug/tow-lowest-pos-height"); + _node->untie("is-slave"); + _node->untie("speed-in-tow-direction"); + _node->untie("mp-auto-connect-period"); + _node->untie("mp-time-lag"); delete _state; } @@ -275,13 +272,10 @@ void Hitch::setWinchPositionAuto(bool doit) _state->posLocalToGlobal(lWinchPos,_winchPos); _towLength=_winchInitialTowLength; - SG_LOG(SG_GENERAL, SG_ALERT,"Set the winch pos to "<<_winchPos[0]<<","<<_winchPos[1]<<","<<_winchPos[2]<setStringValue("coonected to winch!"); _open=false; - char text[512]; - sprintf(text,"/sim/hitches/%s", _name); - SGPropertyNode * node = fgGetNode(text, true); - node->setBoolValue("broken",false); + _node->setBoolValue("broken",false); //set the dist value (if not, the hitch would open in the next calcforce run //float delta[3]; @@ -354,27 +348,30 @@ void Hitch::findBestAIObject(bool doit,bool running_as_autoconnect) bestdist=dist; _towEndNode=n; _towEndIsConnectedToProperty=true; - char text[512]; - sprintf(text,"/sim/hitches/%s", _name); - SGPropertyNode * node = fgGetNode(text, true); - //node->setStringValue("tow/node",n->getPath()); - node->setStringValue("tow/node",n->getDisplayName()); + //_node->setStringValue("tow/node",n->getPath()); + _node->setStringValue("tow/node",n->getDisplayName()); _nodeID=n->getIntValue("id",0); - node->setStringValue("tow/connected-to-ai-or-mp-callsign",n->getStringValue("callsign")); + _node->setStringValue("tow/connected-to-ai-or-mp-callsign",n->getStringValue("callsign")); _open=false; found = true; } } if (found) { - char text[512]; - sprintf(text,"/sim/hitches/%s", _name); - SGPropertyNode * node = fgGetNode(text, true); - //if (!running_as_autoconnect) - SG_LOG(SG_GENERAL, SG_ALERT,"Found aircraft for aerotow: " - <getStringValue("tow/connected-to-ai-or-mp-callsign") - <<", distance "<getStringValue("tow/node")<getStringValue("tow/connected-to-ai-or-mp-callsign") + <<", I am on your hook, distance "<setStringValue(message.str().c_str()); + } + else + { + std::stringstream message; + message<<_node->getStringValue("tow/connected-to-ai-or-mp-callsign") + <<": I am on your hook, distance "<setStringValue(message.str().c_str()); + } if (running_as_autoconnect) _isSlave=true; //set the dist value to some value below the tow lentgh (if not, the hitch @@ -384,7 +381,9 @@ void Hitch::findBestAIObject(bool doit,bool running_as_autoconnect) } else if (!running_as_autoconnect) - SG_LOG(SG_GENERAL, SG_ALERT,"Found no aircraft for aerotow!"<setStringValue("Sorry, no aircraft for aerotow!"); + } } void Hitch::setWinchInitialTowLength(float length) @@ -467,10 +466,7 @@ void Hitch::calcForce(Ground *g_cb, RigidBody* body, State* s) { _forceMagnitude=0; _open=true; - char text[128]; - sprintf(text,"/sim/hitches/%s", _name); - SGPropertyNode * node = fgGetNode(text, true); - node->setBoolValue("broken",true); + _node->setBoolValue("broken",true); _force[0]=_force[1]=_force[2]=0; _towEndForce[0]=_towEndForce[1]=_towEndForce[2]=0; _reportTowEndForce[0]=_reportTowEndForce[1]=_reportTowEndForce[2]=0; @@ -561,10 +557,7 @@ void Hitch::calcForce(Ground *g_cb, RigidBody* body, State* s) { _forceMagnitude=0; _open=true; - char text[128]; - sprintf(text,"/sim/hitches/%s", _name); - SGPropertyNode * node = fgGetNode(text, true); - node->setBoolValue("broken",true); + _node->setBoolValue("broken",true); _force[0]=_force[1]=_force[2]=0; _towEndForce[0]=_towEndForce[1]=_towEndForce[2]=0; } @@ -588,16 +581,20 @@ void Hitch::integrate (float dt) { if (_dist>_towLength*1.00001) { - SG_LOG(SG_GENERAL, SG_ALERT,"Could not lock Hinch (tow length is insufficient) on hitch '"<<_name<<"' !"<setStringValue(message.str().c_str()); _open=true; return; } - char text[512]; - sprintf(text,"/sim/hitches/%s", _name); - SGPropertyNode * node = fgGetNode(text, true); - node->setBoolValue("broken",false); + _node->setBoolValue("broken",false); } - SG_LOG(SG_GENERAL, SG_ALERT,(_open?"Opened hitch (or broken tow) '":"Locked hitch '")<<_name<<"' !"<getBoolValue("broken",false)&&_open) + message<<"Oh no, the tow is broken"; + else + message<<(_open?"Opened hitch '":"Locked hitch '")<<_name<<"' !"; + fgGetNode("/sim/messages/pilot", true)->setStringValue(message.str().c_str()); _oldOpen=_open; } @@ -616,14 +613,11 @@ void Hitch::integrate (float dt) //check, if tow end can be modified by property, if yes: update if(_towEndIsConnectedToProperty) { - char text[128]; - sprintf(text,"/sim/hitches/%s", _name); - SGPropertyNode * node = fgGetNode(text, true); - if (node) + if (_node) { - //_towEndNode=fgGetNode(node->getStringValue("tow/node"), false); + //_towEndNode=fgGetNode(_node->getStringValue("tow/node"), false); char towNode[256]; - strncpy(towNode,node->getStringValue("tow/node"),256); + strncpy(towNode,_node->getStringValue("tow/node"),256); towNode[255]=0; _towEndNode=fgGetNode("ai/models")->getNode(towNode, false); //AI and multiplayer objects seem to change node? @@ -632,7 +626,7 @@ void Hitch::integrate (float dt) { char MPcallsign[256]=""; const char *MPc; - MPc=node->getStringValue("tow/connected-to-ai-or-mp-callsign"); + MPc=_node->getStringValue("tow/connected-to-ai-or-mp-callsign"); if (MPc) { strncpy(MPcallsign,MPc,256); @@ -654,8 +648,8 @@ void Hitch::integrate (float dt) if (strcmp(n->getStringValue("callsign"),MPcallsign)==0)//found { _towEndNode=n; - //node->setStringValue("tow/node",n->getPath()); - node->setStringValue("tow/node",n->getDisplayName()); + //_node->setStringValue("tow/node",n->getPath()); + _node->setStringValue("tow/node",n->getDisplayName()); } } } @@ -701,12 +695,11 @@ void Hitch::integrate (float dt) { if(mp_open) { - _open=true; - char text[512]; - sprintf(text,"/sim/hitches/%s", _name); - SGPropertyNode * node = fgGetNode(text, true); - node->getStringValue("tow/node",""); - SG_LOG(SG_GENERAL, SG_ALERT,"'"<getStringValue("tow/node","")<<"' has opened hitch!"<getStringValue("tow/connected-to-ai-or-mp-callsign") + <<": I have released the tow!"; + fgGetNode("/sim/messages/ai-plane", true)->setStringValue(message.str().c_str()); } } } @@ -775,4 +768,4 @@ void Hitch::integrate (float dt) -}; // namespace yasim \ No newline at end of file +}; // namespace yasim diff --git a/src/FDM/YASim/Hitch.hpp b/src/FDM/YASim/Hitch.hpp index 053680516..d97fa9ae9 100755 --- a/src/FDM/YASim/Hitch.hpp +++ b/src/FDM/YASim/Hitch.hpp @@ -1,6 +1,8 @@ #ifndef _HITCH_HPP #define _HITCH_HPP -class SGPropertyNode; + +#include
+ namespace yasim { class Ground; @@ -76,7 +78,7 @@ private: State* _state; float _dist; float _timeLagCorrectedDist; - SGPropertyNode *_towEndNode; + SGPropertyNode_ptr _towEndNode; const char *_towEndPropertyName; bool _towEndIsConnectedToProperty; bool _nodeIsMultiplayer; @@ -102,10 +104,11 @@ private: float _mp_force[3]; bool _mp_is_slave; bool _mp_open_last_state; - + bool _displayed_len_lower_dist_message; bool _last_wish; + SGPropertyNode_ptr _node; }; }; // namespace yasim