/*! * @file weapon_manager.h * every big WorldEntity has the ability to carry many different Weapons. * for this to be easy there is the WeaponManager, that handels these weapons, * and changes between them. * * * * @TODO 1. WeaponManager should also handle a List of availiableWeapons. */ #include "base_object.h" #include "crosshair.h" #include "weapon.h" // FORWARD DECLARATION template class tAnimation; template class tIterator; #define WM_MAX_SLOTS 10 //!< How many slots the WeaponManager has at its max #define WM_MAX_CONFIGS 4 //!< The maximum number of predefined Configurations #define WM_MAX_LOADED_WEAPONS 20 //!< The //! an enumerator defining a Slot, where a Weapon can be stored inside. typedef struct { PNode position; //!< the relative Position to the position of the carrying entity. (const PNode* parent; of WeaponManager) long capability; //!< the capabilities of the Slot @see WM_SlotCapability. Weapon* currentWeapon; //!< The current weapon this slot is carrying. Weapon* nextWeapon; //!< either NULL or the next weapon that will be set (require currentWeapon to deactivate) } WM_Slot; //! This is a special class, that can handle many different Weapons of a ship/man/whatever. /** * this class is designed to interactively changeing multiple weapons (or just one), * and to allow the Weapon itself to enable/disable itself. * * How to configure * 1. set the default values. * 2. define weapons. connect them to the WeaponManager's configurations (have a look at "player.cc", to see how it works) * 3. go on and run :).... */ class WeaponManager : public BaseObject { public: WeaponManager(PNode* parent); WeaponManager(const TiXmlElement* root); ~WeaponManager(); void init(); void loadParams(const TiXmlElement* root); void loadWeapons(const TiXmlElement* root); void setSlotCount(unsigned int slotCount); // setting up the WeaponManager with the following functions void setSlotPosition(int slot, const Vector& position); void setSlotDirection(int slot, const Quaternion& rotation); /** @param slot the slot to get the relative position from @returns the relative position of the Carrier to the Slot */ const Vector& getSlotPosition(int slot) const { return this->currentSlotConfig[slot].position.getRelCoor(); }; void setSlotCapability(int slot, long slotCapability); /** @param slot the slot to get the capabilities from @returns the capabilies */ long getSlotCapability(int slot) const { return this->currentSlotConfig[slot].capability; }; void setParent(PNode* parent); /** @returns the Parent (carrier) of this WeaponManager */ PNode* getParent() const { return this->parent; }; void addWeapon(Weapon* weapon, int configID = -1, int slotID = -1); void removeWeapon(Weapon* weapon, int configID = -1); // FIXME :: // bool hasFreeSlot(int configID, long capability = WTYPE_ALL) { return ( getNextFreeSlot(configID, capability ) != -1)? true : false; }; void nextWeaponConfig(); void previousWeaponConfig(); void changeWeaponConfig(int weaponConfig); /** @returns a fixed target namely the Crosshair's 3D position */ inline PNode* getFixedTarget() const { return this->crosshair; }; PNode* getSomeTarget(); PNode* getDistanceTarget(const PNode* carrier, float distance); void fire(); //! @TODO: implement this function (maybe also in Weapon itself) void releaseFire(); void tick(float dt); void draw() const; void debug() const; // private: int getNextFreeSlot(int configID, long capability = WTYPE_ALL); private: PNode* parent; //!< The parent, this WeaponManager is connected to. int slotCount; //!< number of weapon slots the ship has. int currentConfigID; //!< the currently selected config. Weapon* configs[WM_MAX_CONFIGS][WM_MAX_SLOTS]; //!< An array of predefined configurations and assigned weapon. WM_Slot currentSlotConfig[WM_MAX_SLOTS]; //!< The currentConfigureation. Weapon* availiableWeapons[WM_MAX_LOADED_WEAPONS]; //!< The availiable Weapons of this WeaponManager bool weaponChange; Crosshair* crosshair; //!< an aim. tAnimation* crossHairSizeAnim; //!< An animation for the crosshair (scaling) std::list::iterator targetIterator; //!< An iterator for traversion lists of enemies. };