Cafu Engine
CompCarriedWeapon.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_GAMESYS_COMPONENT_CARRIED_WEAPON_HPP_INCLUDED
8 #define CAFU_GAMESYS_COMPONENT_CARRIED_WEAPON_HPP_INCLUDED
9 
10 #include "../CompBase.hpp"
11 
12 
13 namespace cf
14 {
15  namespace GameSys
16  {
17  /// This component represents a weapon that a player can pick up and use.
19  {
20  public:
21 
22  /// The constructor.
24 
25  /// The copy constructor.
26  /// @param Comp The component to create a copy of.
28 
29  /// Returns whether this weapon is available to the player.
30  /// A weapon is usually available to the player only after it has been picked up in the world.
31  /// Alternatively, it is possible to configure the player prototype to spawn the player with the
32  /// weapon readily available.
33  /// Only weapons that are available can be selected and drawn.
34  bool IsAvail() const { return m_IsAvail.Get(); }
35 
36  // Base class overrides.
37  ComponentCarriedWeaponT* Clone() const override;
38  const char* GetName() const override { return "CarriedWeapon"; }
39  void PreCache() override;
40  void OnPostLoad(bool OnlyStatic) override;
41 
42 
43  // The TypeSys related declarations for this class.
44  const cf::TypeSys::TypeInfoT* GetType() const { return &TypeInfo; }
45  static void* CreateInstance(const cf::TypeSys::CreateParamsT& Params);
46  static const cf::TypeSys::TypeInfoT TypeInfo;
47 
48 
49  protected:
50 
51  // The Lua API methods of this class.
52  static int toString(lua_State* LuaState);
53 
54  static const luaL_Reg MethodsList[]; ///< The list of Lua methods for this class.
55  static const char* DocClass;
56  static const cf::TypeSys::MethsDocT DocMethods[];
57  static const cf::TypeSys::MethsDocT DocCallbacks[];
58  static const cf::TypeSys::VarsDocT DocVars[];
59 
60 
61  private:
62 
63  void FillMemberVars(); ///< A helper method for the constructors.
64 
65  TypeSys::VarT<std::string> m_Label; ///< A short informational name for this weapon. Used for reference e.g. in the Map Editor, in log output, or in script code.
66  TypeSys::VarT<bool> m_IsAvail; ///< Is this weapon available to the player? A weapon is usually available to the player only after it has been picked up in the world. Alternatively, it is possible to configure the player prototype to spawn the player with the weapon readily available. Only weapons that are available can be selected and drawn.
67  TypeSys::VarT<std::string> m_Script; ///< The filename of the script that implements the behaviour of this weapon.
68  TypeSys::VarT<uint16_t> m_PrimaryAmmo; ///< The current amount of ammo for the primary fire of this weapon.
69  TypeSys::VarT<uint16_t> m_MaxPrimaryAmmo; ///< The maximum amount of ammo for the primary fire of this weapon.
70  TypeSys::VarT<uint16_t> m_SecondaryAmmo; ///< The current amount of ammo for the secondary fire of this weapon.
71  TypeSys::VarT<uint16_t> m_MaxSecondaryAmmo; ///< The maximum amount of ammo for the secondary fire of this weapon.
72  };
73  }
74 }
75 
76 #endif
void PreCache() override
Initializes any resources that may be needed on the client or server ahead of time.
Definition: CompCarriedWeapon.cpp:97
ComponentCarriedWeaponT()
The constructor.
Definition: CompCarriedWeapon.cpp:51
ComponentCarriedWeaponT * Clone() const override
The virtual copy constructor.
Definition: CompCarriedWeapon.cpp:91
This component represents a weapon that a player can pick up and use.
Definition: CompCarriedWeapon.hpp:18
bool IsAvail() const
Returns whether this weapon is available to the player.
Definition: CompCarriedWeapon.hpp:34
static const luaL_Reg MethodsList[]
The list of Lua methods for this class.
Definition: CompCarriedWeapon.hpp:54
const char * GetName() const override
Returns the name of this component.
Definition: CompCarriedWeapon.hpp:38
void OnPostLoad(bool OnlyStatic) override
This method is called after all entities and their components have been loaded.
Definition: CompCarriedWeapon.cpp:103
Definition: TypeSys.hpp:52
Definition: TypeSys.hpp:57
This class keeps type information (about an entity class that occurs in the game).
Definition: TypeSys.hpp:79
const T & Get() const
Returns the value of this variable.
Definition: Variables.hpp:182
Definition: TypeSys.hpp:68
This is the base class for the components that an entity is composed/aggregated of.
Definition: CompBase.hpp:54