X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FAIModel%2FAIMultiplayer.hxx;h=6b30685aab218708b006ed9ec69e49cdf19d5ff4;hb=388a0a5b6af2b91f2ed36488177813d693ed374e;hp=e931cb60ade54628245fcc66ce5dd4cf290d3ce7;hpb=4bfd1722df24f5be89459b25010e5d7352720a7b;p=flightgear.git diff --git a/src/AIModel/AIMultiplayer.hxx b/src/AIModel/AIMultiplayer.hxx old mode 100755 new mode 100644 index e931cb60a..6b30685aa --- a/src/AIModel/AIMultiplayer.hxx +++ b/src/AIModel/AIMultiplayer.hxx @@ -1,7 +1,6 @@ // FGAIMultiplayer - AIBase derived class creates an AI multiplayer aircraft // // Written by David Culp, started October 2003. -// With additions by Vivian Meazza // // Copyright (C) 2003 David P. Culp - davidculp2@comcast.net // @@ -17,87 +16,75 @@ // // 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. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #ifndef _FG_AIMultiplayer_HXX #define _FG_AIMultiplayer_HXX -#include "AIManager.hxx" +#include +#include + +#include #include "AIBase.hxx" -//#include -//#include +class FGAIMultiplayer : public FGAIBase { +public: + FGAIMultiplayer(); + virtual ~FGAIMultiplayer(); -#include -SG_USING_STD(string); + virtual bool init(bool search_in_AI_path=false); + virtual void bind(); + virtual void unbind(); + virtual void update(double dt); + void addMotionInfo(const FGExternalMotionData& motionInfo, long stamp); + void setDoubleProperty(const std::string& prop, double val); -class FGAIMultiplayer : public FGAIBase { + long getLastTimestamp(void) const + { return mLastTimestamp; } - public: - FGAIMultiplayer(); - ~FGAIMultiplayer(); - - bool init(); - virtual void bind(); - virtual void unbind(); - void update(double dt); - - - void setSpeedN(double sn); - void setSpeedE(double se); - void setSpeedD(double sd); - void setAccN(double an); - void setAccE(double ae); - void setAccD(double ad); - void setRateH(double rh); - void setRateR(double rr); - void setRateP(double rp); - void setRudder( double r ) { rudder = r;} - void setElevator( double e ) { elevator = e; } - void setLeftAileron( double la ) { left_aileron = la; } - void setRightAileron( double ra ) { right_aileron = ra; } - void setTimeStamp(); - - inline SGPropertyNode *FGAIMultiplayer::getProps() { return props; } - - void setAcType(string ac) { acType = ac; }; - void setCompany(string comp); - - virtual const char* getTypeString(void) const { return "multiplayer"; } - - double dt; - double speedN, speedE, speedD; - double rateH, rateR, rateP; - double raw_hdg , raw_roll , raw_pitch ; - double raw_speed_north_deg_sec, raw_speed_east_deg_sec; - double raw_lat, damp_lat, lat_constant; - double raw_lon, damp_lon, lon_constant; - double raw_alt, damp_alt, alt_constant; - double hdg_constant, roll_constant, pitch_constant; - double speed_north_deg_sec_constant, speed_east_deg_sec_constant; - double speed_north_deg_sec, speed_east_deg_sec; - double accN, accE, accD; - double rudder, elevator, left_aileron, right_aileron; - double time_stamp, last_time_stamp; - - SGPropertyNode_ptr _time_node; - - void Run(double dt); - inline double sign(double x) { return (x < 0.0) ? -1.0 : 1.0; } - - string acType; - string company; -}; + void setAllowExtrapolation(bool allowExtrapolation) + { mAllowExtrapolation = allowExtrapolation; } + bool getAllowExtrapolation(void) const + { return mAllowExtrapolation; } + void setLagAdjustSystemSpeed(double lagAdjustSystemSpeed) + { + if (lagAdjustSystemSpeed < 0) + lagAdjustSystemSpeed = 0; + mLagAdjustSystemSpeed = lagAdjustSystemSpeed; + } + double getLagAdjustSystemSpeed(void) const + { return mLagAdjustSystemSpeed; } + + void addPropertyId(unsigned id, const char* name) + { mPropertyMap[id] = props->getNode(name, true); } + + virtual const char* getTypeString(void) const { return "multiplayer"; } -inline void FGAIMultiplayer::setSpeedN(double sn) { speedN = sn; } -inline void FGAIMultiplayer::setSpeedE(double se) { speedE = se; } -inline void FGAIMultiplayer::setSpeedD(double sd) { speedD = sd; } -inline void FGAIMultiplayer::setAccN(double an) { accN = an; } -inline void FGAIMultiplayer::setAccE(double ae) { accE = ae; } -inline void FGAIMultiplayer::setAccD(double ad) { accD = ad; } -inline void FGAIMultiplayer::setRateH(double rh) { rateH = rh; } -inline void FGAIMultiplayer::setRateR(double rr) { rateR = rr; } -inline void FGAIMultiplayer::setRateP(double rp) { rateP = rp; } +private: + + // Automatic sorting of motion data according to its timestamp + typedef std::map MotionInfo; + MotionInfo mMotionInfo; + + // Map between the property id's from the multiplayers network packets + // and the property nodes + typedef std::map > PropertyMap; + PropertyMap mPropertyMap; + + double mTimeOffset; + bool mTimeOffsetSet; + + /// Properties which are for now exposed for testing + bool mAllowExtrapolation; + double mLagAdjustSystemSpeed; + + long mLastTimestamp; + + // Propertiies for tankers + SGPropertyNode_ptr refuel_node; + bool isTanker; + bool contact; // set if this tanker is within fuelling range +}; #endif // _FG_AIMultiplayer_HXX