/*! \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" // FORWARD DECLARATION 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 //! this is an identifier for the weapon config typedef enum { WM_CONFIG0 = 0, WM_CONFIG1 = 1, WM_CONFIG2 = 2, WM_CONFIG3 = 3, WM_CONFIGCOUNT = 4 } WM_CONFIG; //! this is an identifier for the slot. there are up to 8 weapon slots -> this means there can't be more than 8 weapons at the same time typedef enum { WM_SLOT0 = 0, WM_SLOT1 = 1, WM_SLOT2 = 2, WM_SLOT3 = 3, WM_SLOT4 = 4, WM_SLOT5 = 5, WM_SLOT6 = 6, WM_SLOT7 = 7, WM_SLOT_COUNT = 8, WM_FREE_SLOT = -1 } WM_SLOT; typedef enum { WM_SLOTC_DIRECTIONAL = 1, WM_SLOTC_TURRET = 2, WM_SLOTC_ALLKINDS = 3, WM_SLOTC_FORWARD = 4, WM_SLOTC_BACKWARD = 8, WM_SLOTC_LEFT = 16, WM_SLOTC_RIGHT = 32, WM_SLOTC_ALLDIRS = 60, WM_SLOTC_ALL = 63, } WM_SlotCapability; typedef struct WM_Slot { int number; long capability; Weapon* currentWeapon; Weapon* nextWeapon; }; //! this is a weapon Configuration: it has up to 8 slots typedef struct { bool bUsed; //!< is set to true, if this configuration is Weapon* slots[WM_MAX_SLOTS]; } weaponConfig; class WeaponManager : public BaseObject { public: WeaponManager(int slotCount); WeaponManager(const TiXmlElement* root); ~WeaponManager(); void init(); void loadParams(const TiXmlElement* root); void loadWeapons(const TiXmlElement* root); void setSlotCount(int slotCount); void addWeapon(Weapon* weapon, int configID = WM_CONFIG0, int slotID = WM_FREE_SLOT); void removeWeapon(Weapon* weapon, int configID = WM_CONFIG0); void nextWeaponConf(); void fire(); void tick(float dt); void draw(); private: int getNextFreeSlot(int configID); private: Crosshair* crosshair; //!< an aim. tAnimation* crossHairSizeAnim; //!< An animation for the crosshair (scaling) int slotCount; //!< number of weapon slots a ship has int currConfID; //!< the currently selected config weaponConfig configs[4]; //!< a list of four configurations Weapon* availiableWeapons[WM_MAX_LOADED_WEAPONS]; };