]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIMultiplayer.hxx
Merge branch 'jmt/positioned'
[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(bool search_in_AI_path=false);
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   long getLastTimestamp(void) const
44   { return mLastTimestamp; }
45
46   void setAllowExtrapolation(bool allowExtrapolation)
47   { mAllowExtrapolation = allowExtrapolation; }
48   bool getAllowExtrapolation(void) const
49   { return mAllowExtrapolation; }
50   void setLagAdjustSystemSpeed(double lagAdjustSystemSpeed)
51   {
52     if (lagAdjustSystemSpeed < 0)
53       lagAdjustSystemSpeed = 0;
54     mLagAdjustSystemSpeed = lagAdjustSystemSpeed;
55   }
56   double getLagAdjustSystemSpeed(void) const
57   { return mLagAdjustSystemSpeed; }
58
59   void addPropertyId(unsigned id, const char* name)
60   { mPropertyMap[id] = props->getNode(name, true); }
61
62   virtual const char* getTypeString(void) const { return "multiplayer"; }
63
64 private:
65
66   // Automatic sorting of motion data according to its timestamp
67   typedef std::map<double,FGExternalMotionData> MotionInfo;
68   MotionInfo mMotionInfo;
69
70   // Map between the property id's from the multiplayers network packets
71   // and the property nodes
72   typedef std::map<unsigned, SGSharedPtr<SGPropertyNode> > PropertyMap;
73   PropertyMap mPropertyMap;
74
75   double mTimeOffset;
76   bool mTimeOffsetSet;
77
78   /// Properties which are for now exposed for testing
79   bool mAllowExtrapolation;
80   double mLagAdjustSystemSpeed;
81
82   long mLastTimestamp;
83
84   // Propertiies for tankers
85   SGPropertyNode_ptr refuel_node;
86   bool isTanker;
87   bool contact;          // set if this tanker is within fuelling range
88 };
89
90 #endif  // _FG_AIMultiplayer_HXX