[4826] | 1 | /*! |
---|
[4954] | 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. |
---|
[4826] | 10 | */ |
---|
| 11 | |
---|
[6444] | 12 | #ifndef _WEAPON_MANAGER_H |
---|
| 13 | #define _WEAPON_MANAGER_H |
---|
| 14 | |
---|
[4826] | 15 | #include "base_object.h" |
---|
| 16 | |
---|
[4955] | 17 | #include "crosshair.h" |
---|
[4959] | 18 | #include "weapon.h" |
---|
[4826] | 19 | |
---|
| 20 | // FORWARD DECLARATION |
---|
[4837] | 21 | template <class T> class tAnimation; |
---|
[4826] | 22 | |
---|
[5435] | 23 | #define WM_MAX_SLOTS 10 //!< How many slots the WeaponManager has at its max |
---|
[4951] | 24 | #define WM_MAX_CONFIGS 4 //!< The maximum number of predefined Configurations |
---|
| 25 | #define WM_MAX_LOADED_WEAPONS 20 //!< The |
---|
[4826] | 26 | |
---|
[4953] | 27 | //! This is a special class, that can handle many different Weapons of a ship/man/whatever. |
---|
| 28 | /** |
---|
| 29 | * this class is designed to interactively changeing multiple weapons (or just one), |
---|
| 30 | * and to allow the Weapon itself to enable/disable itself. |
---|
| 31 | * |
---|
| 32 | * How to configure |
---|
| 33 | * 1. set the default values. |
---|
[4972] | 34 | * 2. define weapons. connect them to the WeaponManager's configurations (have a look at "player.cc", to see how it works) |
---|
[4953] | 35 | * 3. go on and run :).... |
---|
| 36 | */ |
---|
[4826] | 37 | class WeaponManager : public BaseObject { |
---|
[6055] | 38 | |
---|
| 39 | //! an enumerator defining a Slot, where a Weapon can be stored inside. |
---|
| 40 | typedef struct |
---|
| 41 | { |
---|
| 42 | PNode position; //!< the relative Position to the position of the carrying entity. (const PNode* parent; of WeaponManager) |
---|
| 43 | long capability; //!< the capabilities of the Slot @see WM_SlotCapability. |
---|
| 44 | |
---|
| 45 | Weapon* currentWeapon; //!< The current weapon this slot is carrying. |
---|
| 46 | Weapon* nextWeapon; //!< either NULL or the next weapon that will be set (require currentWeapon to deactivate) |
---|
| 47 | } WM_Slot; |
---|
| 48 | |
---|
[4826] | 49 | public: |
---|
[6142] | 50 | WeaponManager(WorldEntity* parent); |
---|
[4826] | 51 | WeaponManager(const TiXmlElement* root); |
---|
| 52 | ~WeaponManager(); |
---|
| 53 | |
---|
| 54 | void init(); |
---|
[6512] | 55 | virtual void loadParams(const TiXmlElement* root); |
---|
[4834] | 56 | void loadWeapons(const TiXmlElement* root); |
---|
[4826] | 57 | |
---|
[4964] | 58 | void setSlotCount(unsigned int slotCount); |
---|
[6442] | 59 | unsigned int getSlotCount() const { return this->slotCount; }; |
---|
[4951] | 60 | // setting up the WeaponManager with the following functions |
---|
| 61 | void setSlotPosition(int slot, const Vector& position); |
---|
[4969] | 62 | void setSlotDirection(int slot, const Quaternion& rotation); |
---|
[4954] | 63 | /** @param slot the slot to get the relative position from @returns the relative position of the Carrier to the Slot */ |
---|
| 64 | const Vector& getSlotPosition(int slot) const { return this->currentSlotConfig[slot].position.getRelCoor(); }; |
---|
| 65 | void setSlotCapability(int slot, long slotCapability); |
---|
| 66 | /** @param slot the slot to get the capabilities from @returns the capabilies */ |
---|
| 67 | long getSlotCapability(int slot) const { return this->currentSlotConfig[slot].capability; }; |
---|
| 68 | |
---|
[6142] | 69 | void setParent(WorldEntity* parent); |
---|
[4954] | 70 | /** @returns the Parent (carrier) of this WeaponManager */ |
---|
| 71 | PNode* getParent() const { return this->parent; }; |
---|
[4834] | 72 | |
---|
[4951] | 73 | void addWeapon(Weapon* weapon, int configID = -1, int slotID = -1); |
---|
| 74 | void removeWeapon(Weapon* weapon, int configID = -1); |
---|
[6444] | 75 | Weapon* getWeapon(int slotID) const { return (slotID >= 0 && slotID < this->slotCount)? this->currentSlotConfig[slotID].nextWeapon: NULL; }; |
---|
[4951] | 76 | |
---|
[5750] | 77 | // FIXME :: |
---|
| 78 | // bool hasFreeSlot(int configID, long capability = WTYPE_ALL) { return ( getNextFreeSlot(configID, capability ) != -1)? true : false; }; |
---|
[4955] | 79 | |
---|
[4954] | 80 | void nextWeaponConfig(); |
---|
[4952] | 81 | void previousWeaponConfig(); |
---|
| 82 | void changeWeaponConfig(int weaponConfig); |
---|
[4826] | 83 | |
---|
[4955] | 84 | /** @returns a fixed target namely the Crosshair's 3D position */ |
---|
[5750] | 85 | inline PNode* getFixedTarget() const { return this->crosshair; }; |
---|
| 86 | |
---|
[4826] | 87 | void fire(); |
---|
[5750] | 88 | //! @TODO: implement this function (maybe also in Weapon itself) |
---|
| 89 | void releaseFire(); |
---|
[4951] | 90 | |
---|
[4833] | 91 | void tick(float dt); |
---|
[4951] | 92 | void draw() const; |
---|
[4826] | 93 | |
---|
[4951] | 94 | void debug() const; |
---|
| 95 | |
---|
[5750] | 96 | // private: |
---|
[5440] | 97 | int getNextFreeSlot(int configID, long capability = WTYPE_ALL); |
---|
[4834] | 98 | |
---|
[4837] | 99 | private: |
---|
[6142] | 100 | WorldEntity* parent; //!< The parent, this WeaponManager is connected to. |
---|
[4826] | 101 | |
---|
[4954] | 102 | int slotCount; //!< number of weapon slots the ship has. |
---|
| 103 | int currentConfigID; //!< the currently selected config. |
---|
| 104 | Weapon* configs[WM_MAX_CONFIGS][WM_MAX_SLOTS]; //!< An array of predefined configurations and assigned weapon. |
---|
| 105 | WM_Slot currentSlotConfig[WM_MAX_SLOTS]; //!< The currentConfigureation. |
---|
[4949] | 106 | |
---|
[4954] | 107 | Weapon* availiableWeapons[WM_MAX_LOADED_WEAPONS]; //!< The availiable Weapons of this WeaponManager |
---|
[4951] | 108 | |
---|
| 109 | bool weaponChange; |
---|
| 110 | |
---|
[4954] | 111 | Crosshair* crosshair; //!< an aim. |
---|
| 112 | tAnimation<Crosshair>* crossHairSizeAnim; //!< An animation for the crosshair (scaling) |
---|
[4826] | 113 | }; |
---|
[6444] | 114 | |
---|
| 115 | |
---|
| 116 | #endif /* _WEAPON_MANAGER_H */ |
---|