1 | /*! |
---|
2 | * @file weapon_manager.h |
---|
3 | * every big WorldEntity has the ability to carry many different Weapons. |
---|
4 | * for this to be easy there is the WeaponManager, that handels these weapons, |
---|
5 | * and changes between them. |
---|
6 | * |
---|
7 | * |
---|
8 | * |
---|
9 | * @TODO 1. WeaponManager should also handle a List of availiableWeapons. |
---|
10 | */ |
---|
11 | |
---|
12 | #ifndef _WEAPON_MANAGER_H |
---|
13 | #define _WEAPON_MANAGER_H |
---|
14 | |
---|
15 | #include "base_object.h" |
---|
16 | |
---|
17 | #include "crosshair.h" |
---|
18 | #include "weapon.h" |
---|
19 | |
---|
20 | #include "count_pointer.h" |
---|
21 | #include "ammo_container.h" |
---|
22 | |
---|
23 | // FORWARD DECLARATION |
---|
24 | template <class T> class tAnimation; |
---|
25 | |
---|
26 | #define WM_MAX_SLOTS 10 //!< How many slots the WeaponManager has at its max |
---|
27 | #define WM_MAX_CONFIGS 4 //!< The maximum number of predefined Configurations |
---|
28 | #define WM_MAX_LOADED_WEAPONS 20 //!< The |
---|
29 | |
---|
30 | //! This is a special class, that can handle many different Weapons of a ship/man/whatever. |
---|
31 | /** |
---|
32 | * this class is designed to interactively changeing multiple weapons (or just one), |
---|
33 | * and to allow the Weapon itself to enable/disable itself. |
---|
34 | * |
---|
35 | * How to configure |
---|
36 | * 1. set the default values. |
---|
37 | * 2. define weapons. connect them to the WeaponManager's configurations (have a look at "player.cc", to see how it works) |
---|
38 | * 3. go on and run :).... |
---|
39 | */ |
---|
40 | class WeaponManager : public BaseObject { |
---|
41 | ObjectListDeclaration(WeaponManager); |
---|
42 | |
---|
43 | //! an enumerator defining a Slot, where a Weapon can be stored inside. |
---|
44 | typedef struct |
---|
45 | { |
---|
46 | PNode position; //!< the relative Position to the position of the carrying entity. (const PNode* parent; of WeaponManager) |
---|
47 | long capability; //!< the capabilities of the Slot @see WM_SlotCapability. |
---|
48 | |
---|
49 | Weapon* currentWeapon; //!< The current weapon this slot is carrying. |
---|
50 | Weapon* nextWeapon; //!< either NULL or the next weapon that will be set (require currentWeapon to deactivate) |
---|
51 | } WM_Slot; |
---|
52 | |
---|
53 | public: |
---|
54 | WeaponManager(WorldEntity* parent); |
---|
55 | WeaponManager(const TiXmlElement* root); |
---|
56 | virtual ~WeaponManager(); |
---|
57 | |
---|
58 | void init(); |
---|
59 | virtual void loadParams(const TiXmlElement* root); |
---|
60 | void loadWeapons(const TiXmlElement* root); |
---|
61 | |
---|
62 | void showCrosshair(); |
---|
63 | void hideCrosshair(); |
---|
64 | |
---|
65 | void setSlotCount(unsigned int slotCount); |
---|
66 | unsigned int getSlotCount() const { return this->slotCount; }; |
---|
67 | // setting up the WeaponManager with the following functions |
---|
68 | void setSlotPosition(int slot, const Vector& position, PNode* parent = NULL); |
---|
69 | void setSlotDirection(int slot, const Quaternion& rotation); |
---|
70 | /** @param slot the slot to get the relative position from @returns the relative position of the Carrier to the Slot */ |
---|
71 | const Vector& getSlotPosition(int slot) const { return this->currentSlotConfig[slot].position.getRelCoor(); }; |
---|
72 | void setSlotCapability(int slot, long slotCapability); |
---|
73 | /** @param slot the slot to get the capabilities from @returns the capabilies */ |
---|
74 | long getSlotCapability(int slot) const { return this->currentSlotConfig[slot].capability; }; |
---|
75 | |
---|
76 | void setParentEntity(WorldEntity* parent); |
---|
77 | WorldEntity* getParentEntity() const { return this->parentEntity; }; |
---|
78 | |
---|
79 | void setParentNode(PNode* node); |
---|
80 | /** @returns the Parent (carrier) of this WeaponManager */ |
---|
81 | PNode* getParentNode() const { return this->parentNode; }; |
---|
82 | |
---|
83 | bool addWeapon(Weapon* weapon, int configID = -1, int slotID = -1); |
---|
84 | void removeWeapon(Weapon* weapon, int configID = -1); |
---|
85 | |
---|
86 | Weapon* getWeapon(int slotID) const { return (slotID >= 0 && slotID < this->slotCount)? this->currentSlotConfig[slotID].nextWeapon: NULL; }; |
---|
87 | |
---|
88 | // FIXME :: |
---|
89 | // bool hasFreeSlot(int configID, long capability = WTYPE_ALL) { return ( getNextFreeSlot(configID, capability ) != -1)? true : false; }; |
---|
90 | |
---|
91 | void nextWeaponConfig(); |
---|
92 | void previousWeaponConfig(); |
---|
93 | void changeWeaponConfig(int weaponConfig); |
---|
94 | |
---|
95 | float increaseAmmunition(const ClassID& projectileType, float ammo); |
---|
96 | float increaseAmmunition(const Weapon* weapon, float ammo); |
---|
97 | |
---|
98 | /** @returns a fixed target namely the Crosshair's 3D position */ |
---|
99 | inline PNode* getFixedTarget() const { return this->crosshair; }; |
---|
100 | |
---|
101 | void fire(); |
---|
102 | //! @TODO: implement this function (maybe also in Weapon itself) |
---|
103 | void releaseFire(); |
---|
104 | |
---|
105 | void tick(float dt); |
---|
106 | void draw() const; |
---|
107 | |
---|
108 | void debug() const; |
---|
109 | |
---|
110 | // private: |
---|
111 | int getNextFreeSlot(int configID, long capability = WTYPE_ALL); |
---|
112 | CountPointer<AmmoContainer>& getAmmoContainer(const ClassID& projectileType); |
---|
113 | CountPointer<AmmoContainer>& getAmmoContainer(const Weapon* weapon); |
---|
114 | |
---|
115 | private: |
---|
116 | WorldEntity* parentEntity; //!< The parent, this WeaponManager is connected to. |
---|
117 | PNode* parentNode; //!< The parented Node the WeaponManager is connected to. (by default == parentEntity). |
---|
118 | |
---|
119 | int slotCount; //!< number of weapon slots the ship has. |
---|
120 | int currentConfigID; //!< the currently selected config. |
---|
121 | Weapon* configs[WM_MAX_CONFIGS][WM_MAX_SLOTS]; //!< An array of predefined configurations and assigned weapon. |
---|
122 | WM_Slot currentSlotConfig[WM_MAX_SLOTS]; //!< The currentConfigureation. |
---|
123 | |
---|
124 | Weapon* availiableWeapons[WM_MAX_LOADED_WEAPONS]; //!< The availiable Weapons of this WeaponManager |
---|
125 | |
---|
126 | bool weaponChange; |
---|
127 | |
---|
128 | Crosshair* crosshair; //!< an aim. |
---|
129 | tAnimation<Crosshair>* crossHairSizeAnim; //!< An animation for the crosshair (scaling) |
---|
130 | |
---|
131 | std::vector<CountPointer<AmmoContainer> > ammo; //!< Containers |
---|
132 | }; |
---|
133 | |
---|
134 | |
---|
135 | #endif /* _WEAPON_MANAGER_H */ |
---|