| 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 |  | 
|---|
| 24 | // FORWARD DECLARATION | 
|---|
| 25 | template <class T> class tAnimation; | 
|---|
| 26 | class WeaponSlot; | 
|---|
| 27 |  | 
|---|
| 28 | #define    WM_MAX_SLOTS            10             //!< How many slots the WeaponManager has at its max | 
|---|
| 29 | #define    WM_MAX_CONFIGS          4              //!< The maximum number of predefined Configurations | 
|---|
| 30 | #define    WM_MAX_LOADED_WEAPONS   20             //!< The | 
|---|
| 31 |  | 
|---|
| 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. | 
|---|
| 39 |  * 2. define weapons. connect them to the WeaponManager's configurations (have a look at "player.cc", to see how it works) | 
|---|
| 40 |  * 3. go on and run :).... | 
|---|
| 41 |  */ | 
|---|
| 42 | class WeaponManager : public BaseObject { | 
|---|
| 43 |   ObjectListDeclaration(WeaponManager); | 
|---|
| 44 |  | 
|---|
| 45 |   public: | 
|---|
| 46 |     WeaponManager(WorldEntity* parent); | 
|---|
| 47 |     WeaponManager(const TiXmlElement* root); | 
|---|
| 48 |     virtual ~WeaponManager(); | 
|---|
| 49 |  | 
|---|
| 50 |     void init(); | 
|---|
| 51 |     virtual void loadParams(const TiXmlElement* root); | 
|---|
| 52 |     void loadWeapons(const TiXmlElement* root); | 
|---|
| 53 |  | 
|---|
| 54 |     void showCrosshair(); | 
|---|
| 55 |     void hideCrosshair(); | 
|---|
| 56 |     void setRotationSpeed(float speed); | 
|---|
| 57 |  | 
|---|
| 58 |     void setSlotCount(unsigned int slotCount); | 
|---|
| 59 |     unsigned int getSlotCount() const { return this->slotCount; }; | 
|---|
| 60 |     // setting up the WeaponManager with the following functions | 
|---|
| 61 |     void setSlotPosition(int slot, const Vector& position, PNode* parent = NULL); | 
|---|
| 62 |     void setSlotDirection(int slot, const Quaternion& rotation); | 
|---|
| 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; | 
|---|
| 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; | 
|---|
| 68 |  | 
|---|
| 69 |     void setParentEntity(WorldEntity* parent); | 
|---|
| 70 |     WorldEntity* getParentEntity() const { return this->parentEntity; }; | 
|---|
| 71 |  | 
|---|
| 72 |     void setParentNode(PNode* node); | 
|---|
| 73 |     /** @returns the Parent (carrier) of this WeaponManager */ | 
|---|
| 74 |     PNode* getParentNode() const { return this->parentNode; }; | 
|---|
| 75 |  | 
|---|
| 76 |     bool addWeapon(Weapon* weapon, int configID = -1, int slotID = -1); | 
|---|
| 77 |     void removeWeapon(Weapon* weapon, int configID = -1); | 
|---|
| 78 |  | 
|---|
| 79 |     Weapon* getWeapon(int slotID) const; | 
|---|
| 80 |  | 
|---|
| 81 |     // FIXME :: | 
|---|
| 82 | //    bool hasFreeSlot(int configID, long capability = WTYPE_ALL) { return ( getNextFreeSlot(configID, capability ) != -1)? true : false; }; | 
|---|
| 83 |  | 
|---|
| 84 |     void nextWeaponConfig(); | 
|---|
| 85 |     void previousWeaponConfig(); | 
|---|
| 86 |     void changeWeaponConfig(int weaponConfig); | 
|---|
| 87 |  | 
|---|
| 88 |     float increaseAmmunition(const ClassID& projectileType, float ammo); | 
|---|
| 89 |     float increaseAmmunition(const Weapon* weapon, float ammo); | 
|---|
| 90 |  | 
|---|
| 91 |     /** @returns a fixed target namely the Crosshair's 3D position */ | 
|---|
| 92 |     inline PNode* getFixedTarget() const { return this->crosshair; }; | 
|---|
| 93 |  | 
|---|
| 94 |     void fire(); | 
|---|
| 95 |     //! @TODO: implement this function (maybe also in Weapon itself) | 
|---|
| 96 |     void releaseFire(); | 
|---|
| 97 |     //inline void setFire() { this->bFire = true; }; | 
|---|
| 98 |  | 
|---|
| 99 |     void tick(float dt); | 
|---|
| 100 |     void draw() const; | 
|---|
| 101 |  | 
|---|
| 102 |     void debug() const; | 
|---|
| 103 |  | 
|---|
| 104 |  // private: | 
|---|
| 105 |     int getNextFreeSlot(int configID, long capability = WTYPE_ALL); | 
|---|
| 106 |     CountPointer<AmmoContainer>& getAmmoContainer(const ClassID& projectileType); | 
|---|
| 107 |     CountPointer<AmmoContainer>& getAmmoContainer(const Weapon* weapon); | 
|---|
| 108 |  | 
|---|
| 109 |   private: | 
|---|
| 110 |     WorldEntity*            parentEntity;                             //!< The parent, this WeaponManager is connected to. | 
|---|
| 111 |     PNode*                  parentNode;                               //!< The parented Node the WeaponManager is connected to. (by default == parentEntity). | 
|---|
| 112 |  | 
|---|
| 113 |     int                     slotCount;                                //!< number of weapon slots the ship has. | 
|---|
| 114 |     int                     currentConfigID;                          //!< the currently selected config. | 
|---|
| 115 |     Weapon*                 configs[WM_MAX_CONFIGS][WM_MAX_SLOTS];    //!< An array of predefined configurations and assigned weapon. | 
|---|
| 116 |     WeaponSlot*             currentSlotConfig[WM_MAX_SLOTS];          //!< The currentConfigureation. | 
|---|
| 117 |  | 
|---|
| 118 |     Weapon*                 availiableWeapons[WM_MAX_LOADED_WEAPONS]; //!< The availiable Weapons of this WeaponManager | 
|---|
| 119 |  | 
|---|
| 120 |     bool                    weaponChange; | 
|---|
| 121 |  | 
|---|
| 122 |     Crosshair*              crosshair;                                //!< an aim. | 
|---|
| 123 |     tAnimation<Crosshair>*  crossHairSizeAnim;                        //!< An animation for the crosshair (scaling) | 
|---|
| 124 |  | 
|---|
| 125 |     std::vector<CountPointer<AmmoContainer> > ammo;                   //!< Containers | 
|---|
| 126 |  | 
|---|
| 127 |     bool                    bFire; | 
|---|
| 128 | }; | 
|---|
| 129 |  | 
|---|
| 130 |  | 
|---|
| 131 | #endif /* _WEAPON_MANAGER_H */ | 
|---|