Cafu Engine
HumanPlayer.hpp
1 /*
2 =================================================================================
3 This file is part of Cafu, the open-source game engine and graphics engine
4 for multiplayer, cross-platform, real-time 3D action.
5 Copyright (C) 2002-2013 Carsten Fuchs Software.
6 
7 Cafu is free software: you can redistribute it and/or modify it under the terms
8 of the GNU General Public License as published by the Free Software Foundation,
9 either version 3 of the License, or (at your option) any later version.
10 
11 Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with Cafu. If not, see <http://www.gnu.org/licenses/>.
17 
18 For support and more information about Cafu, visit us at <http://www.cafu.de>.
19 =================================================================================
20 */
21 
22 #ifndef CAFU_HUMAN_PLAYER_HPP_INCLUDED
23 #define CAFU_HUMAN_PLAYER_HPP_INCLUDED
24 
25 #include "BaseEntity.hpp"
26 #include "Libs/Physics.hpp"
27 #include "btBulletDynamicsCommon.h"
28 
29 
30 namespace cf { namespace GameSys { class ComponentModelT; } }
31 namespace cf { namespace GuiSys { class GuiImplT; } }
32 struct luaL_Reg;
33 
34 
35 namespace GAME_NAME
36 {
37  class EntHumanPlayerT : public BaseEntityT, public btMotionState
38  {
39  public:
40 
41  // Publicly defined enum for access from the "carried weapons".
42  enum EventTypesT { EVENT_TYPE_PRIMARY_FIRE, EVENT_TYPE_SECONDARY_FIRE, NUM_EVENT_TYPES };
43 
44  EntHumanPlayerT(const EntityCreateParamsT& Params);
45  ~EntHumanPlayerT();
46 
47  EntityStateT& GetState() { return State; }
48  const EntityStateT& GetState() const { return State; }
49  unsigned short GetPitch() const { return m_Pitch; }
50  unsigned short GetBank() const { return m_Bank; }
51  const btRigidBody* GetRigidBody() const { return m_RigidBody; }
52 
53  /// Increases the frag count of this entity by the given number.
54  void AddFrag(int NumFrags=1);
55 
56  // Implement the BaseEntityT interface.
57  void TakeDamage(BaseEntityT* Entity, char Amount, const VectorT& ImpactDir);
58  void ProcessConfigString(const void* ConfigData, const char* ConfigString);
59  void Think(float FrameTime, unsigned long ServerFrameNr);
60 
61  void ProcessEvent(unsigned int EventType, unsigned int NumEvents);
62  bool GetLightSourceInfo(unsigned long& DiffuseColor, unsigned long& SpecularColor, VectorT& Position, float& Radius, bool& CastsShadows) const;
63  void Draw(bool FirstPersonView, float LodDist) const;
64  void PostDraw(float FrameTime, bool FirstPersonView);
65 
66  // Implement the btMotionState interface.
67  void getWorldTransform(btTransform& worldTrans) const;
68  void setWorldTransform(const btTransform& worldTrans);
69 
70 
71  const cf::TypeSys::TypeInfoT* GetType() const;
72  static void* CreateInstance(const cf::TypeSys::CreateParamsT& Params);
73  static const cf::TypeSys::TypeInfoT TypeInfo;
74 
75 
76  private:
77 
78  // Override the base class methods.
79  void NotifyLeaveMap();
80  void DoSerialize(cf::Network::OutStreamT& Stream) const;
81  void DoDeserialize(cf::Network::InStreamT& Stream);
82 
83  /// A helper function for Think().
84  bool CheckGUI(IntrusivePtrT<cf::GameSys::ComponentModelT> CompModel, Vector3fT& MousePos) const;
85 
86  // Script methods.
87  static int GetHealth(lua_State* LuaState);
88  static int GetArmor(lua_State* LuaState);
89  static int GetFrags(lua_State* LuaState);
90  static int GetCrosshair(lua_State* LuaState);
91  static int GetAmmoString(lua_State* LuaState);
92 
93  static const luaL_Reg MethodsList[];
94 
95 
96  EntityStateT State; ///< The current state of this entity.
97  PhysicsHelperT m_Physics;
98  btCollisionShape* m_CollisionShape; ///< The collision shape that is used to approximate and represent this player in the physics world.
99  btRigidBody* m_RigidBody; ///< The rigid body (of "kinematic" type) for use in the physics world.
100 
101  // char ThisHumanPlayerNum; // The sole purpose is to help to make a good descision about the light source color in GetLightSourceInfo().
102  mutable VectorT LastSeenAmbientColor; // This is a client-side variable, unrelated to prediction, and thus allowed.
103  float TimeForLightSource;
104  IntrusivePtrT<cf::GuiSys::GuiImplT> GuiHUD; ///< The HUD GUI for this local human player entity.
105  };
106 }
107 
108 #endif
This class implements the physics for moving entities through the world.
Definition: Physics.hpp:35
This class implements smart (reference-counted) pointers.
Definition: Pointer.hpp:58
Definition: BaseEntity.hpp:56
Definition: HumanPlayer.hpp:37
This class is used for reading data from a StateT instance (deserialization).
Definition: State.hpp:222
Definition: EntityCreateParams.hpp:37
Definition: BaseEntity.hpp:85
This class is used for writing data into a StateT instance (serialization).
Definition: State.hpp:96
Definition: TypeSys.hpp:67
This class keeps type information (about an entity class that occurs in the game).
Definition: TypeSys.hpp:94