1 | /*! |
---|
2 | \file weapon.h |
---|
3 | * a weapon that a can use |
---|
4 | |
---|
5 | |
---|
6 | A weapon is characterized by: |
---|
7 | o firing-rate: the initial firing rate of a weapon (1/s = Herz) |
---|
8 | 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! |
---|
9 | o energy-consumption: this determines the energy that has to be used to produce this projectile = costs per projectile |
---|
10 | |
---|
11 | Furthermore there are some other attributes, that will help to represent a firing |
---|
12 | weapon in this world: |
---|
13 | o sound file/ressource: this is a pointer to the sound-file/ressource. however it may be represented |
---|
14 | o shooting animation |
---|
15 | */ |
---|
16 | |
---|
17 | |
---|
18 | #ifndef _WEAPON_H |
---|
19 | #define _WEAPON_H |
---|
20 | |
---|
21 | #include "base_object.h" |
---|
22 | #include "world_entity.h" |
---|
23 | |
---|
24 | // FORWARD DECLARATION |
---|
25 | class Projectile; |
---|
26 | class Weapon; |
---|
27 | class Animation3D; |
---|
28 | class TiXmlElement; |
---|
29 | |
---|
30 | //! An enumerator defining actions a Weapon can take |
---|
31 | typedef enum { |
---|
32 | WA_NONE = 0, //!< No Action taken |
---|
33 | WA_SHOOT = 1, //!< emitting Shot |
---|
34 | WA_CHARGE = 2, //!< charge action (one click before the shot) |
---|
35 | WA_RELOAD = 3, //!< reload right after shoot is finished |
---|
36 | WA_ACTIVATE = 4, //!< activate the GUN |
---|
37 | WA_DEACTIVATE = 5, //!< deactivate the GUN |
---|
38 | WA_SPECIAL1 = 6, //!< Special Action taken |
---|
39 | |
---|
40 | WA_ACTION_COUNT = 7 //!< This must match the count of enumerations-members. |
---|
41 | } WeaponAction; |
---|
42 | |
---|
43 | //! An enumerator defining the States of a Weapon |
---|
44 | typedef enum { |
---|
45 | WS_NONE = 0, //!< No State at all (if set, there is something wrong, or the weapon is not yet availiable) |
---|
46 | WS_SHOOTING = 1, //!< The State of the Shooting |
---|
47 | WS_RELOADING = 3, //!< The State of the Reloading |
---|
48 | WS_ACTIVATING = 4, //!< The State in which the weapon gets activated |
---|
49 | WS_DEACTIVATING = 5, //!< The State in which the weapon gets deactivated |
---|
50 | WS_INACTIVE = 6, //!< The State where the weapon is inactive (unable to shoot) |
---|
51 | WS_IDLE = 7, //!< The State where the weapon is idle |
---|
52 | |
---|
53 | WS_STATE_COUNT = 8 //!< This must match the count of enumerations-members. |
---|
54 | } WeaponState; |
---|
55 | |
---|
56 | |
---|
57 | //! a weapon can be left or right sided |
---|
58 | /** |
---|
59 | * @todo this will be reset with mirror X/Y/Z |
---|
60 | */ |
---|
61 | #define W_LEFT 0 |
---|
62 | #define W_RIGHT 1 |
---|
63 | |
---|
64 | //! An abstract class, that describes weapons |
---|
65 | /** |
---|
66 | * This is used as a container for all the different kinds of weapons that may exist |
---|
67 | */ |
---|
68 | class Weapon : public WorldEntity |
---|
69 | { |
---|
70 | friend class World; |
---|
71 | |
---|
72 | public: |
---|
73 | Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction); |
---|
74 | Weapon(const TiXmlElement* root); |
---|
75 | virtual ~Weapon (); |
---|
76 | |
---|
77 | void init(); |
---|
78 | void loadParams(const TiXmlElement* root); |
---|
79 | |
---|
80 | void setProjectile(Projectile* projectile); |
---|
81 | Projectile* getProjectile(); |
---|
82 | |
---|
83 | virtual void activate(); |
---|
84 | virtual void deactivate(); |
---|
85 | virtual void fire() = 0; |
---|
86 | //virtual void reload(); |
---|
87 | //virtual void charge(); |
---|
88 | bool isActive() const { return this->active; }; |
---|
89 | |
---|
90 | // FUNCTIONS TO SET THE WEAPONS PROPERTIES. |
---|
91 | void setStateDuration(const char* state, float duration); |
---|
92 | void setStateDuration(WeaponState state, float duration); |
---|
93 | float getStateDuration(WeaponState state) { return (state < WS_STATE_COUNT)?this->times[state]:0.0; }; |
---|
94 | /** @return true if idletime is elapsed, false otherwise */ |
---|
95 | inline bool stateTimeElapsed() const { return (this->stateTime > this->times[currentState])?true:false; }; |
---|
96 | |
---|
97 | /** fires the weapon */ |
---|
98 | virtual void hit (WorldEntity* weapon, const Vector& loc); |
---|
99 | virtual void destroy(); |
---|
100 | |
---|
101 | virtual void tick(float time); |
---|
102 | virtual void draw(); |
---|
103 | |
---|
104 | private: |
---|
105 | static WeaponAction charToAction(const char* action); |
---|
106 | static WeaponState charToState(const char* state); |
---|
107 | |
---|
108 | |
---|
109 | protected: |
---|
110 | //////////// |
---|
111 | // PHASES // |
---|
112 | //////////// |
---|
113 | WeaponState currentState; //!< The State the weapon is in. |
---|
114 | WeaponAction requestAction; //!< An action to try to Engage after the currentState ends. |
---|
115 | float stateTime; //!< how long the state has taken until now. |
---|
116 | float times[WS_STATE_COUNT]; //!< Times to stay in the different States @see WeaponState. |
---|
117 | SoundBuffer* soundBuffers[WA_ACTION_COUNT]; //!< SoundBuffers for all actions @see WeaponAction. |
---|
118 | Animation3D* animation[WS_STATE_COUNT]; //!< Animations for all the States (you can say yourself on what part of the gun this animation acts). |
---|
119 | |
---|
120 | SoundBuffer* fireSound; |
---|
121 | SoundSource* weaponSource; |
---|
122 | |
---|
123 | float minCharge; |
---|
124 | float maxCharge; |
---|
125 | |
---|
126 | private: |
---|
127 | bool active; //!< states wheter the weapon is enabled or not |
---|
128 | Projectile* projectile; //!< the projectile used for this weapon |
---|
129 | }; |
---|
130 | |
---|
131 | #endif /* _WEAPON_H */ |
---|