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