[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 |
---|
[3870] | 36 | #define W_MAX_CONFIGS 4 |
---|
[3862] | 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 | |
---|
[3870] | 50 | |
---|
[3862] | 51 | //! 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 |
---|
[3870] | 52 | #define W_SLOT0 0 |
---|
| 53 | #define W_SLOT1 1 |
---|
| 54 | #define W_SLOT2 2 |
---|
| 55 | #define W_SLOT3 3 |
---|
| 56 | #define W_SLOT4 4 |
---|
| 57 | #define W_SLOT5 5 |
---|
| 58 | #define W_SLOT6 6 |
---|
| 59 | #define W_SLOT7 7 |
---|
| 60 | #define W_FREE_SLOT 99 |
---|
[3583] | 61 | |
---|
[3870] | 62 | |
---|
[3862] | 63 | //! this is an identifier for the weapon config |
---|
[3870] | 64 | #define W_CONFIG0 0 |
---|
| 65 | #define W_CONFIG1 1 |
---|
| 66 | #define W_CONFIG2 2 |
---|
| 67 | #define W_CONFIG3 3 |
---|
[3862] | 68 | |
---|
| 69 | //! this is a weapon Configuration: it has up to 8 slots |
---|
| 70 | typedef struct weaponConfig { |
---|
[3870] | 71 | bool bUsed; //<! is set to true, if this configuration is |
---|
| 72 | Weapon* slots[8]; |
---|
[3862] | 73 | }; |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | class WeaponManager { |
---|
| 77 | public: |
---|
| 78 | WeaponManager(int nrOfSlots = 2); |
---|
| 79 | ~WeaponManager(); |
---|
| 80 | |
---|
[3878] | 81 | void addWeapon(Weapon* weapon, int configID = W_CONFIG0, int slotID = W_FREE_SLOT); |
---|
| 82 | void removeWeapon(Weapon* weapon, int configID = W_CONFIG0); |
---|
[3862] | 83 | void nextWeaponConf(); |
---|
| 84 | |
---|
[3875] | 85 | void fire(); |
---|
[3877] | 86 | void tick(float sec); |
---|
| 87 | void draw(); |
---|
[3873] | 88 | |
---|
[3862] | 89 | private: |
---|
| 90 | int nrOfSlots; //<! number of weapon slots a ship has |
---|
[3875] | 91 | int currConfID; //<! the currently selected config |
---|
[3870] | 92 | weaponConfig configs[4]; //<! a list of four configurations |
---|
| 93 | |
---|
[3878] | 94 | int getNextFreeSlot(int configID); |
---|
[3862] | 95 | }; |
---|
| 96 | |
---|
[3573] | 97 | class Weapon : public WorldEntity |
---|
| 98 | { |
---|
| 99 | friend class World; |
---|
| 100 | |
---|
| 101 | public: |
---|
[3881] | 102 | Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction); |
---|
[3573] | 103 | virtual ~Weapon (); |
---|
| 104 | |
---|
[3583] | 105 | void enable(void); |
---|
| 106 | void disable(void); |
---|
| 107 | bool isEnabled(void); |
---|
[3577] | 108 | |
---|
[3575] | 109 | void setProjectile(Projectile* projectile); |
---|
[3583] | 110 | Projectile* getProjectile(void); |
---|
[3575] | 111 | |
---|
[3583] | 112 | virtual void activate(void); |
---|
| 113 | virtual void deactivate(void); |
---|
| 114 | bool isActive(void); |
---|
[3575] | 115 | |
---|
| 116 | |
---|
[3881] | 117 | /** |
---|
| 118 | \brief sets a weapon idle time |
---|
| 119 | \param idle time in ms |
---|
| 120 | |
---|
| 121 | a weapon idle time is the time spend after a shoot until the weapon can |
---|
| 122 | shoot again |
---|
| 123 | */ |
---|
| 124 | inline void setWeaponIdleTime(float time) { this->idleTime = time; } |
---|
| 125 | /** |
---|
| 126 | \brief gets the weapon idle time |
---|
| 127 | \returns idle time in ms |
---|
| 128 | |
---|
| 129 | a weapon idle time is the time spend after a shoot until the weapon can |
---|
| 130 | shoot again |
---|
| 131 | */ |
---|
| 132 | inline float getWeaponIdleTime(void) const { return this->idleTime;} |
---|
| 133 | /** |
---|
| 134 | \brief checks if the idle time is elapsed |
---|
| 135 | \return true if time is elapsed |
---|
| 136 | |
---|
| 137 | a weapon idle time is the time spend after a shoot until the weapon can |
---|
| 138 | shoot again |
---|
| 139 | */ |
---|
| 140 | inline bool hasWeaponIdleTimeElapsed(void) const { return (this->localTime>this->idleTime)?true:false; } |
---|
| 141 | |
---|
| 142 | /** |
---|
| 143 | \brief fires the weapon |
---|
| 144 | |
---|
| 145 | this is called from the player.cc, when fire-button is been pushed |
---|
| 146 | */ |
---|
[3646] | 147 | virtual void fire(void) = 0; |
---|
[3578] | 148 | virtual void hit (WorldEntity* weapon, Vector* loc); |
---|
[3583] | 149 | virtual void destroy(void); |
---|
[3575] | 150 | |
---|
[3583] | 151 | virtual void tick(float time); |
---|
| 152 | virtual void weaponIdle(void); |
---|
| 153 | virtual void draw(void); |
---|
[3573] | 154 | |
---|
[3629] | 155 | protected: |
---|
| 156 | tList<WorldEntity>* worldEntities; |
---|
[3685] | 157 | float localTime; |
---|
| 158 | float idleTime; |
---|
| 159 | float slowDownFactor; |
---|
[3575] | 160 | |
---|
[3573] | 161 | private: |
---|
[3577] | 162 | bool enabled; |
---|
[3575] | 163 | Projectile* projectile; |
---|
[3583] | 164 | //WeaponSound sound; |
---|
[3573] | 165 | }; |
---|
| 166 | |
---|
| 167 | #endif /* _WEAPON_H */ |
---|