/*! \file weapon.h * a weapon that a player can use A Player has a list of weapons, that can be choosen to shoot projectiles (projectiles.{cc,h}) at ennemies. These weapons can be shooted sequentially or (if able) combined. Therefore you can choose the weapon mode = choose a weapon. A weapon is characterized by: o firing-rate: the initial firing rate of a weapon (1/s = Herz) o slowdown-factor: this is a factor d: exp(-d*x), d is element of all positive R. it determines how fast the firing-rate will slow down. if no slowdown: d=0, the bigger d is, the faster the weapon will slow down! o energy-consumption: this determines the energy that has to be used to produce this projectile = costs per projectile Furthermore there are some other attributes, that will help to represent a firing weapon in this world: o sound file/ressource: this is a pointer to the sound-file/ressource. however it may be represented o shooting animation a player defines one or more weapon configurations. a player has got one to eight weapon slots: places where weapons can be attached to. a weapon configuration is a matching between weapons and slots. Since its clear how many weapons a player will have, there is no list of weapons: its hard coded and limited to 8 slots and 4 configs. More would be a waste of memory and time you need to customize and change to a weapon config... */ #include "base_object.h" #include "p_node.h" // FORWARD DECLARATION class PNode; class Weapon; class Crosshair; template class tAnimation; #define WM_MAX_SLOTS 8 //!< 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 capabilities of a WeaponSlot typedef enum { WM_SLOTC_DIRECTIONAL = 0x00000001, //!< if the Slot is able to carry directional weapons WM_SLOTC_TURRET = 0x00000002, //!< if the Slot is able to carry turrets WM_SLOTC_ALLKINDS = 0x0000000f, //!< if the Slot is able to carry all kinds of weapons WM_SLOTC_FORWARD = 0x00000010, //!< if the Slot is able to carry weapons firing forward WM_SLOTC_BACKWARD = 0x00000020, //!< if the Slot is able to carry weapons firing backwards WM_SLOTC_LEFT = 0x00000040, //!< if the Slot is able to carry weapons firing to the left WM_SLOTC_RIGHT = 0x00000080, //!< if the Slot is able to carry weapons firing to the right WM_SLOTC_ALLDIRS = 0x000000f0, //!< this slot can fire into all directions WM_SLOTC_ALL = 0x000000ff, //!< everything allowed in this slot } WM_SlotCapability; //! 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 * 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); // setting up the WeaponManager with the following functions void setSlotPosition(int slot, const Vector& position); void setSlotCapability(long slotCapability); void setParent(PNode* parent); void addWeapon(Weapon* weapon, int configID = -1, int slotID = -1); void removeWeapon(Weapon* weapon, int configID = -1); void nextWeaponConf(); void previousWeaponConfig(); void changeWeaponConfig(int weaponConfig); void fire(); void tick(float dt); void draw() const; void debug() const; private: void setSlotCount(unsigned int slotCount); int getNextFreeSlot(int configID); 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]; bool weaponChange; Crosshair* crosshair; //!< an aim. tAnimation* crossHairSizeAnim; //!< An animation for the crosshair (scaling) };