-
Notifications
You must be signed in to change notification settings - Fork 0
/
cWeapon.h
316 lines (240 loc) · 9.62 KB
/
cWeapon.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
///////////////////////////////////////////////////////
//*-------------------------------------------------*//
//| Part of Project One (https://www.maus-games.at) |//
//*-------------------------------------------------*//
//| Copyright (c) 2010 Martin Mauersics |//
//| Released under the zlib License |//
//*-------------------------------------------------*//
///////////////////////////////////////////////////////
#pragma once
#ifndef _P1_GUARD_WEAPON_H_
#define _P1_GUARD_WEAPON_H_
// TODO 3: weapons may have to share their cooldown (not relevant on single-weapon setup)
// TODO 1: sound and visual effect for charging pulse
// ****************************************************************
// weapon definitions
#define WEAPON_MODES (1u) //
#define WEAPON_PULSE_CHARGE (4.0f) //
#define WEAPON_TESLA_TARGETS (1u) //
// ****************************************************************
// weapon interface
class INTERFACE cWeapon
{
protected:
coreTimer m_CooldownTimer; // controls the cooldown between two successive primary shots
coreUint8 m_iLastStatus; // last shoot status (to determine trigger and release)
coreUint8 m_iBurst; //
cPlayer* m_pOwner; // associated owner of the weapon (and bullets)
public:
constexpr cWeapon()noexcept;
virtual ~cWeapon() = default;
DISABLE_COPY(cWeapon)
ENABLE_ID
// update the weapon
coreBool Update(const coreUint8 iShootStatus, const coreFloat fShootSpeed);
//
void Render();
void RenderAfter();
void Move();
//
void Prefetch();
// set object properties
inline void SetCooldownTime(const coreFloat fTime) {m_CooldownTimer.SetValue(fTime);}
inline void SetOwner (cPlayer* pOwner) {m_pOwner = pOwner;}
// get object properties
inline coreBool GetCooldown ()const {return m_CooldownTimer.GetStatus();}
inline coreFloat GetCooldownTime ()const {return m_CooldownTimer.GetValue(CORE_TIMER_GET_NORMAL);}
inline coreFloat GetCooldownSpeed()const {return m_CooldownTimer.GetSpeed();}
inline const coreUint8& GetLastStatus ()const {return m_iLastStatus;}
inline const coreUint8& GetBurst ()const {return m_iBurst;}
inline cPlayer* GetOwner ()const {return m_pOwner;}
virtual coreVector3 GetColorEnergy ()const {return coreVector3(0.5f,0.5f,0.5f);}
virtual coreVector3 GetColorShip ()const {return coreVector3(0.5f,0.5f,0.5f);}
virtual coreUint8 GetElement ()const {return ELEMENT_NEUTRAL;}
protected:
//
coreBool _IsOwnerDarkShading()const;
coreBool _IsOwnerRainbow ()const;
coreVector3 _GetEnergyColor ()const;
template <typename T> FORCE_INLINE T* _MakeWhite(T* OUTPUT ptBullet) {this->_TrackBullet(); if(this->_IsOwnerRainbow()) ptBullet->SetColor3(this->_GetEnergyColor()); else ptBullet->MakeWhite(); return ptBullet;}
//
void _TrackBullet();
private:
// own routines for derived classes
virtual void __UpdateOwn (const coreUint8 iShootStatus, const coreFloat fShootSpeed) {}
virtual void __TriggerOwn (const coreUint8 iMode) {}
virtual void __ReleaseOwn (const coreUint8 iMode) {}
virtual void __ShootOwn () {}
virtual void __RenderOwn () {}
virtual void __RenderAfterOwn() {}
virtual void __MoveOwn () {}
virtual void __PrefetchOwn () {}
};
// ****************************************************************
// empty weapon class
class cNoWeapon final : public cWeapon
{
public:
cNoWeapon() = default;
DISABLE_COPY(cNoWeapon)
ASSIGN_ID(0, "Nothing")
};
// ****************************************************************
// ray weapon class
class cRayWeapon final : public cWeapon
{
private:
coreObject3D m_aMuzzle[2]; //
coreFlow m_fMuzzleTime; //
coreFlow m_fMuzzleAnim; //
coreFlow m_fMuzzleScale; //
public:
cRayWeapon()noexcept;
~cRayWeapon()final;
DISABLE_COPY(cRayWeapon)
ASSIGN_ID(1, "Laser Gun")
// get object properties
inline coreVector3 GetColorEnergy()const final {return COLOR_ENERGY_YELLOW;}
inline coreVector3 GetColorShip ()const final {return COLOR_SHIP_YELLOW;}
inline coreUint8 GetElement ()const final {return ELEMENT_YELLOW;}
private:
// execute own routines
void __UpdateOwn (const coreUint8 iShootStatus, const coreFloat fShootSpeed)final;
void __TriggerOwn (const coreUint8 iMode)final;
void __ReleaseOwn (const coreUint8 iMode)final;
void __ShootOwn ()final;
void __RenderOwn ()final;
void __MoveOwn ()final;
void __PrefetchOwn()final;
};
// ****************************************************************
// pulse weapon class
class cPulseWeapon final : public cWeapon
{
private:
coreFlow m_fCharge; //
coreUint8 m_iShotType; //
coreObject3D m_Charge; //
coreObject3D m_ChargeWave; //
coreObject3D m_Muzzle; //
coreFlow m_fMuzzleTime; //
coreFlow m_fMuzzleAnim; //
coreFlow m_fMuzzleScale; //
coreFlow m_fWave; //
coreFlow m_fAnimation; //
public:
cPulseWeapon()noexcept;
~cPulseWeapon()final;
DISABLE_COPY(cPulseWeapon)
ASSIGN_ID(2, "Pulse Cannon")
// get object properties
inline coreVector3 GetColorEnergy()const final {return COLOR_ENERGY_PURPLE;}
inline coreVector3 GetColorShip ()const final {return COLOR_SHIP_PURPLE;}
inline coreUint8 GetElement ()const final {return ELEMENT_PURPLE;}
private:
// execute own routines
void __UpdateOwn (const coreUint8 iShootStatus, const coreFloat fShootSpeed)final;
void __ReleaseOwn (const coreUint8 iMode)final;
void __ShootOwn ()final;
void __RenderOwn ()final;
void __RenderAfterOwn()final;
void __MoveOwn ()final;
void __PrefetchOwn ()final;
};
// ****************************************************************
// wave weapon class
class cWaveWeapon final : public cWeapon
{
public:
cWaveWeapon()noexcept;
DISABLE_COPY(cWaveWeapon)
ASSIGN_ID(3, "Wave Mortar")
// get object properties
inline coreVector3 GetColorEnergy()const final {return COLOR_ENERGY_GREEN;}
inline coreVector3 GetColorShip ()const final {return COLOR_SHIP_GREEN;}
inline coreUint8 GetElement ()const final {return ELEMENT_GREEN;}
private:
// execute own routines
void __ReleaseOwn (const coreUint8 iMode)final;
void __ShootOwn ()final;
void __PrefetchOwn()final;
};
// ****************************************************************
// tesla weapon class
class cTeslaWeapon final : public cWeapon
{
private:
coreUint8 m_iStrikeType; //
coreFloat m_fStrikeOffset; //
public:
cTeslaWeapon()noexcept;
DISABLE_COPY(cTeslaWeapon)
ASSIGN_ID(4, "Tesla Rifle")
// get object properties
inline coreVector3 GetColorEnergy()const final {return COLOR_ENERGY_BLUE;}
inline coreVector3 GetColorShip ()const final {return COLOR_SHIP_BLUE;}
inline coreUint8 GetElement ()const final {return ELEMENT_BLUE;}
private:
// execute own routines
void __TriggerOwn (const coreUint8 iMode)final;
void __ReleaseOwn (const coreUint8 iMode)final;
void __ShootOwn ()final;
void __PrefetchOwn()final;
};
// ****************************************************************
// antimatter weapon class
class cAntiWeapon final : public cWeapon
{
public:
cAntiWeapon() = default;
DISABLE_COPY(cAntiWeapon)
ASSIGN_ID(5, "Antimatter")
// get object properties
inline coreVector3 GetColorEnergy()const final {return COLOR_ENERGY_RED;}
inline coreVector3 GetColorShip ()const final {return COLOR_SHIP_RED;}
inline coreUint8 GetElement ()const final {return ELEMENT_RED;}
};
// ****************************************************************
// enemy weapon class
class cEnemyWeapon final : public cWeapon
{
public:
cEnemyWeapon()noexcept;
DISABLE_COPY(cEnemyWeapon)
ASSIGN_ID(10, "Enemy Weapon")
// get object properties
inline coreVector3 GetColorEnergy()const final {return COLOR_ENERGY_MAGENTA;}
inline coreVector3 GetColorShip ()const final {return COLOR_SHIP_MAGENTA;}
inline coreUint8 GetElement ()const final {return ELEMENT_MAGENTA;}
private:
// execute own routines
void __ShootOwn ()final;
void __PrefetchOwn()final;
};
// ****************************************************************
// final weapon class
class cFinalWeapon final : public cWeapon
{
public:
cFinalWeapon()noexcept;
DISABLE_COPY(cFinalWeapon)
ASSIGN_ID(11, "Final Weapon")
// get object properties
inline coreVector3 GetColorEnergy()const final {return COLOR_ENERGY_WHITE;}
inline coreVector3 GetColorShip ()const final {return COLOR_SHIP_WHITE;}
inline coreUint8 GetElement ()const final {return ELEMENT_WHITE;}
private:
// execute own routines
void __ShootOwn ()final;
void __PrefetchOwn()final;
};
// ****************************************************************
// constructor
constexpr cWeapon::cWeapon()noexcept
: m_CooldownTimer (coreTimer(1.0f, 1.0f, 0u))
, m_iLastStatus (0u)
, m_iBurst (0u)
, m_pOwner (NULL)
{
}
#endif // _P1_GUARD_WEAPON_H_