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