[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 | |
---|
[10437] | 23 | |
---|
[4826] | 24 | // FORWARD DECLARATION |
---|
[4837] | 25 | template <class T> class tAnimation; |
---|
[10437] | 26 | class WeaponSlot; |
---|
[4826] | 27 | |
---|
[5435] | 28 | #define WM_MAX_SLOTS 10 //!< How many slots the WeaponManager has at its max |
---|
[4951] | 29 | #define WM_MAX_CONFIGS 4 //!< The maximum number of predefined Configurations |
---|
[10691] | 30 | // #define WM_MAX_LOADED_WEAPONS 20 //!< The |
---|
[4826] | 31 | |
---|
[4953] | 32 | //! This is a special class, that can handle many different Weapons of a ship/man/whatever. |
---|
| 33 | /** |
---|
| 34 | * this class is designed to interactively changeing multiple weapons (or just one), |
---|
| 35 | * and to allow the Weapon itself to enable/disable itself. |
---|
| 36 | * |
---|
| 37 | * How to configure |
---|
| 38 | * 1. set the default values. |
---|
[4972] | 39 | * 2. define weapons. connect them to the WeaponManager's configurations (have a look at "player.cc", to see how it works) |
---|
[4953] | 40 | * 3. go on and run :).... |
---|
| 41 | */ |
---|
[4826] | 42 | class WeaponManager : public BaseObject { |
---|
[9869] | 43 | ObjectListDeclaration(WeaponManager); |
---|
[6055] | 44 | |
---|
[4826] | 45 | public: |
---|
[6142] | 46 | WeaponManager(WorldEntity* parent); |
---|
[4826] | 47 | WeaponManager(const TiXmlElement* root); |
---|
[6981] | 48 | virtual ~WeaponManager(); |
---|
[4826] | 49 | |
---|
| 50 | void init(); |
---|
[6512] | 51 | virtual void loadParams(const TiXmlElement* root); |
---|
[4834] | 52 | void loadWeapons(const TiXmlElement* root); |
---|
[4826] | 53 | |
---|
[10368] | 54 | void showCrosshair(); |
---|
| 55 | void hideCrosshair(); |
---|
| 56 | void setRotationSpeed(float speed); |
---|
| 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 |
---|
[6803] | 61 | void setSlotPosition(int slot, const Vector& position, PNode* parent = NULL); |
---|
[10669] | 62 | // inline void setSlotPosition(float slot, float x, float y,float z) {setSlotPosition((int)slot, Vector(x,y,z));}; |
---|
[4969] | 63 | void setSlotDirection(int slot, const Quaternion& rotation); |
---|
[4954] | 64 | /** @param slot the slot to get the relative position from @returns the relative position of the Carrier to the Slot */ |
---|
[10437] | 65 | const Vector& getSlotPosition(int slot) const; |
---|
[10669] | 66 | void setSlotCapability(int slot, unsigned long slotCapability); |
---|
[4954] | 67 | /** @param slot the slot to get the capabilities from @returns the capabilies */ |
---|
[10437] | 68 | long getSlotCapability(int slot) const; |
---|
[4954] | 69 | |
---|
[8844] | 70 | void setParentEntity(WorldEntity* parent); |
---|
| 71 | WorldEntity* getParentEntity() const { return this->parentEntity; }; |
---|
| 72 | |
---|
| 73 | void setParentNode(PNode* node); |
---|
[4954] | 74 | /** @returns the Parent (carrier) of this WeaponManager */ |
---|
[8844] | 75 | PNode* getParentNode() const { return this->parentNode; }; |
---|
[4834] | 76 | |
---|
[6679] | 77 | bool addWeapon(Weapon* weapon, int configID = -1, int slotID = -1); |
---|
[4951] | 78 | void removeWeapon(Weapon* weapon, int configID = -1); |
---|
[6669] | 79 | |
---|
[10669] | 80 | inline void createWeaponSlot(int slot, float x, float y, float z, long capability) { |
---|
| 81 | this->setSlotPosition(slot, Vector( x, y, z)); |
---|
| 82 | this->setSlotCapability(slot, capability); }; |
---|
| 83 | |
---|
| 84 | inline void addWeaponToSlot(int config, int slot, const std::string& weaponName){ |
---|
| 85 | this->addWeapon( Weapon::createWeapon( weaponName ), config, slot); }; |
---|
| 86 | |
---|
| 87 | |
---|
[10437] | 88 | Weapon* getWeapon(int slotID) const; |
---|
[4951] | 89 | |
---|
[5750] | 90 | // FIXME :: |
---|
| 91 | // bool hasFreeSlot(int configID, long capability = WTYPE_ALL) { return ( getNextFreeSlot(configID, capability ) != -1)? true : false; }; |
---|
[4955] | 92 | |
---|
[4954] | 93 | void nextWeaponConfig(); |
---|
[4952] | 94 | void previousWeaponConfig(); |
---|
| 95 | void changeWeaponConfig(int weaponConfig); |
---|
[4826] | 96 | |
---|
[9869] | 97 | float increaseAmmunition(const ClassID& projectileType, float ammo); |
---|
[10368] | 98 | float increaseAmmunition(const Weapon* weapon, float ammo); |
---|
[6669] | 99 | |
---|
[4955] | 100 | /** @returns a fixed target namely the Crosshair's 3D position */ |
---|
[5750] | 101 | inline PNode* getFixedTarget() const { return this->crosshair; }; |
---|
| 102 | |
---|
[4826] | 103 | void fire(); |
---|
[5750] | 104 | //! @TODO: implement this function (maybe also in Weapon itself) |
---|
| 105 | void releaseFire(); |
---|
[10368] | 106 | //inline void setFire() { this->bFire = true; }; |
---|
[4951] | 107 | |
---|
[4833] | 108 | void tick(float dt); |
---|
[4951] | 109 | void draw() const; |
---|
[4826] | 110 | |
---|
[4951] | 111 | void debug() const; |
---|
| 112 | |
---|
[5750] | 113 | // private: |
---|
[5440] | 114 | int getNextFreeSlot(int configID, long capability = WTYPE_ALL); |
---|
[9869] | 115 | CountPointer<AmmoContainer>& getAmmoContainer(const ClassID& projectileType); |
---|
[6972] | 116 | CountPointer<AmmoContainer>& getAmmoContainer(const Weapon* weapon); |
---|
[4834] | 117 | |
---|
[4837] | 118 | private: |
---|
[8844] | 119 | WorldEntity* parentEntity; //!< The parent, this WeaponManager is connected to. |
---|
| 120 | PNode* parentNode; //!< The parented Node the WeaponManager is connected to. (by default == parentEntity). |
---|
[4826] | 121 | |
---|
[4954] | 122 | int slotCount; //!< number of weapon slots the ship has. |
---|
| 123 | int currentConfigID; //!< the currently selected config. |
---|
[10676] | 124 | // Weapon* configs[WM_MAX_CONFIGS][WM_MAX_SLOTS]; //!< An array of predefined configurations and assigned weapon. |
---|
| 125 | // WeaponSlot* currentSlotConfig[WM_MAX_SLOTS]; //!< The currentConfigureation. |
---|
| 126 | WeaponSlot* slotConfigs[WM_MAX_SLOTS]; |
---|
[10678] | 127 | // Weapon* availiableWeapons[WM_MAX_LOADED_WEAPONS]; //!< The availiable Weapons of this WeaponSlot |
---|
[4949] | 128 | |
---|
[4951] | 129 | bool weaponChange; |
---|
| 130 | |
---|
[4954] | 131 | Crosshair* crosshair; //!< an aim. |
---|
| 132 | tAnimation<Crosshair>* crossHairSizeAnim; //!< An animation for the crosshair (scaling) |
---|
[6669] | 133 | |
---|
| 134 | std::vector<CountPointer<AmmoContainer> > ammo; //!< Containers |
---|
[10368] | 135 | |
---|
| 136 | bool bFire; |
---|
[4826] | 137 | }; |
---|
[6444] | 138 | |
---|
| 139 | |
---|
| 140 | #endif /* _WEAPON_MANAGER_H */ |
---|