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