]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIMultiplayer.hxx
new FSF address
[flightgear.git] / src / AIModel / AIMultiplayer.hxx
1 // FGAIMultiplayer - AIBase derived class creates an AI multiplayer aircraft
2 //
3 // Written by David Culp, started October 2003.
4 //
5 // Copyright (C) 2003  David P. Culp - davidculp2@comcast.net
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
21 #ifndef _FG_AIMultiplayer_HXX
22 #define _FG_AIMultiplayer_HXX
23
24 #include <map>
25 #include <string>
26
27 #include <MultiPlayer/mpmessages.hxx>
28 #include "AIBase.hxx"
29
30 class FGAIMultiplayer : public FGAIBase {
31 public:
32   FGAIMultiplayer();
33   virtual ~FGAIMultiplayer();
34   
35   virtual bool init();
36   virtual void bind();
37   virtual void unbind();
38   virtual void update(double dt);
39   
40   void addMotionInfo(const FGExternalMotionData& motionInfo, long stamp);
41   void setDoubleProperty(const std::string& prop, double val);
42   
43   void setCallSign(const string& callSign)
44   { mCallSign = callSign; }
45   const char* getCallSign(void) const
46   { return mCallSign.c_str(); }
47   
48   long getLastTimestamp(void) const
49   { return mLastTimestamp; }
50
51   void setAllowExtrapolation(bool allowExtrapolation)
52   { mAllowExtrapolation = allowExtrapolation; }
53   bool getAllowExtrapolation(void) const
54   { return mAllowExtrapolation; }
55   void setLagAdjustSystemSpeed(double lagAdjustSystemSpeed)
56   {
57     if (lagAdjustSystemSpeed < 0)
58       lagAdjustSystemSpeed = 0;
59     mLagAdjustSystemSpeed = lagAdjustSystemSpeed;
60   }
61   double getLagAdjustSystemSpeed(void) const
62   { return mLagAdjustSystemSpeed; }
63
64   void addPropertyId(unsigned id, const char* name)
65   { mPropertyMap[id] = props->getNode(name, true); }
66
67   virtual const char* getTypeString(void) const { return "multiplayer"; }
68
69 private:
70
71   // Automatic sorting of motion data according to its timestamp
72   typedef std::map<double,FGExternalMotionData> MotionInfo;
73   MotionInfo mMotionInfo;
74   
75   // Map between the property id's from the multiplayers network packets
76   // and the property nodes
77   typedef std::map<unsigned, SGSharedPtr<SGPropertyNode> > PropertyMap;
78   PropertyMap mPropertyMap;
79
80   std::string mCallSign;
81   
82   double mTimeOffset;
83   bool mTimeOffsetSet;
84   
85   /// Properties which are for now exposed for testing
86   bool mAllowExtrapolation;
87   double mLagAdjustSystemSpeed;
88
89   long mLastTimestamp;
90 };
91
92 #endif  // _FG_AIMultiplayer_HXX