[3573] | 1 | /*! |
---|
| 2 | \file weapon.h |
---|
| 3 | \brief a weapon that a player can use |
---|
| 4 | |
---|
| 5 | A Player has a list of weapons, that can be choosen to shoot projectiles |
---|
| 6 | (projectiles.{cc,h}) at ennemies. These weapons can be shooted sequentially |
---|
| 7 | or (if able) combined. Therefore you can choose the weapon mode = choose |
---|
| 8 | a weapon. |
---|
| 9 | |
---|
| 10 | A weapon is characterized by: |
---|
| 11 | o firing-rate: the initial firing rate of a weapon (1/s = Herz) |
---|
| 12 | 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! |
---|
| 13 | o energy-consumption: this determines the energy that has to be used to produce this projectile = costs per projectile |
---|
| 14 | |
---|
| 15 | Furthermore there are some other attributes, that will help to represent a firing |
---|
| 16 | weapon in this world: |
---|
| 17 | o sound file/ressource: this is a pointer to the sound-file/ressource. however it may be represented |
---|
[3575] | 18 | o shooting animation |
---|
[3573] | 19 | |
---|
[3862] | 20 | |
---|
| 21 | a player defines one or more weapon configurations. a player has got one to eight |
---|
| 22 | weapon slots: places where weapons can be attached to. a weapon configuration |
---|
| 23 | is a matching between weapons and slots. |
---|
| 24 | Since its clear how many weapons a player will have, there is no list of weapons: |
---|
| 25 | its hard coded and limited to 8 slots and 4 configs. More would be a waste of |
---|
| 26 | memory and time you need to customize and change to a weapon config... |
---|
[3573] | 27 | */ |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | #ifndef _WEAPON_H |
---|
| 31 | #define _WEAPON_H |
---|
| 32 | |
---|
| 33 | #include "world_entity.h" |
---|
| 34 | |
---|
[3862] | 35 | #define W_MAX_SLOTS 8 |
---|
| 36 | #define W_MAX_CONFS 4 |
---|
| 37 | |
---|
[3575] | 38 | class Projectile; |
---|
[3862] | 39 | class Weapon; |
---|
[3573] | 40 | |
---|
[3583] | 41 | typedef enum { |
---|
| 42 | SHOOT, |
---|
| 43 | EMPTY, |
---|
| 44 | RELOAD, |
---|
| 45 | SPECIAL1, |
---|
| 46 | SPECIAL2, |
---|
| 47 | SPECIAL3 |
---|
| 48 | } weaponSoundType; |
---|
| 49 | |
---|
[3862] | 50 | //! 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 |
---|
| 51 | typedef enum slotID {W_SLOT0=0, W_SLOT1, W_SLOT2, W_SLOT3, |
---|
| 52 | W_SLOT4, W_SLOT5, W_SLOT6, W_SLOT7}; |
---|
[3583] | 53 | |
---|
[3862] | 54 | //! this is an identifier for the weapon config |
---|
| 55 | typedef enum configID {W_CONFIG0=0, W_CONFIG1, |
---|
| 56 | W_CONFIG2, W_CONFIG3}; |
---|
| 57 | |
---|
| 58 | //! this is a weapon Configuration: it has up to 8 slots |
---|
| 59 | typedef struct weaponConfig { |
---|
| 60 | Weapon* slot1; //<! standard right side weapon |
---|
| 61 | Weapon* slot2; //<! standard left side weapon |
---|
| 62 | Weapon* slot3; //<! custom |
---|
| 63 | Weapon* slot4; //<! custom |
---|
| 64 | Weapon* slot5; //<! custom |
---|
| 65 | Weapon* slot6; //<! custom |
---|
| 66 | Weapon* slot7; //<! custom |
---|
| 67 | Weapon* slot8; //<! custom |
---|
| 68 | }; |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | class WeaponManager { |
---|
| 72 | public: |
---|
| 73 | WeaponManager(int nrOfSlots = 2); |
---|
| 74 | ~WeaponManager(); |
---|
| 75 | |
---|
| 76 | void addWeapon(Weapon* weapon, slotID slot, configID config = W_CONFIG0); |
---|
| 77 | void addWeaponConfig(weaponConfig* config); |
---|
| 78 | |
---|
| 79 | void nextWeaponConf(); |
---|
| 80 | void prevWeaponConf(); |
---|
| 81 | void selectConfig(configID config); |
---|
| 82 | |
---|
| 83 | private: |
---|
| 84 | int nrOfConfigs; //<! number of configurations defined |
---|
| 85 | int nrOfSlots; //<! number of weapon slots a ship has |
---|
| 86 | weaponConfig* currentConfig; //<! the currently selected config |
---|
| 87 | weaponConfig* configs[4]; //<! a list of four configurations |
---|
| 88 | }; |
---|
| 89 | |
---|
[3573] | 90 | class Weapon : public WorldEntity |
---|
| 91 | { |
---|
| 92 | friend class World; |
---|
| 93 | |
---|
| 94 | public: |
---|
[3631] | 95 | Weapon (PNode* parent, Vector* coordinate, Quaternion* direction); |
---|
[3573] | 96 | virtual ~Weapon (); |
---|
| 97 | |
---|
[3583] | 98 | void enable(void); |
---|
| 99 | void disable(void); |
---|
| 100 | bool isEnabled(void); |
---|
[3577] | 101 | |
---|
[3575] | 102 | void setProjectile(Projectile* projectile); |
---|
[3583] | 103 | Projectile* getProjectile(void); |
---|
[3575] | 104 | |
---|
[3583] | 105 | virtual void activate(void); |
---|
| 106 | virtual void deactivate(void); |
---|
| 107 | bool isActive(void); |
---|
[3575] | 108 | |
---|
[3618] | 109 | void setWeaponIdleTime(float time); |
---|
| 110 | float getWeaponIdleTime(void); |
---|
| 111 | bool hasWeaponIdleTimeElapsed(void); |
---|
[3575] | 112 | |
---|
[3646] | 113 | virtual void fire(void) = 0; |
---|
[3578] | 114 | virtual void hit (WorldEntity* weapon, Vector* loc); |
---|
[3583] | 115 | virtual void destroy(void); |
---|
[3575] | 116 | |
---|
[3583] | 117 | virtual void tick(float time); |
---|
| 118 | virtual void weaponIdle(void); |
---|
| 119 | virtual void draw(void); |
---|
[3573] | 120 | |
---|
[3629] | 121 | protected: |
---|
| 122 | tList<WorldEntity>* worldEntities; |
---|
[3685] | 123 | float localTime; |
---|
| 124 | float idleTime; |
---|
| 125 | float slowDownFactor; |
---|
[3575] | 126 | |
---|
[3573] | 127 | private: |
---|
[3577] | 128 | bool enabled; |
---|
[3575] | 129 | Projectile* projectile; |
---|
[3583] | 130 | //WeaponSound sound; |
---|
[3573] | 131 | }; |
---|
| 132 | |
---|
| 133 | #endif /* _WEAPON_H */ |
---|