Nuclide
Software Development Kit for id Technology
NSWeapon.h
1/*
2 * Copyright (c) 2022 Vera Visions LLC.
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
14 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*/
16
17typedef enumflags
18{
19 WEAPONFL_CHANGED_MODELINDEX,
20 WEAPONFL_CHANGED_ORIGIN,
21 WEAPONFL_CHANGED_ANGLES,
22 WEAPONFL_CHANGED_VELOCITY,
23 WEAPONFL_CHANGED_ANGULARVELOCITY,
24 WEAPONFL_CHANGED_SIZE,
25 WEAPONFL_CHANGED_FLAGS,
26 WEAPONFL_CHANGED_SOLID,
27 WEAPONFL_CHANGED_FRAME,
28 WEAPONFL_CHANGED_SKIN,
29 WEAPONFL_CHANGED_MOVETYPE,
30 WEAPONFL_CHANGED_EFFECTS,
31 WEAPONFL_CHANGED_BODY,
32 WEAPONFL_CHANGED_SCALE,
33 WEAPONFL_CHANGED_ENTITYDEF,
34 WEAPONFL_CHANGED_CLIP,
35 WEAPONFL_CHANGED_CHAIN,
36 WEAPONFL_CHANGED_STATE,
37 WEAPONFL_CHANGED_NEXTWEAPON,
38 WEAPONFL_CHANGED_PREVWEAPON,
39} nsweapon_changed_t;
40
41typedef enum
42{
43 WEAPONSTATE_IDLE,
44 WEAPONSTATE_COCK,
45 WEAPONSTATE_CHARGING,
46 WEAPONSTATE_FIRELOOP,
47 WEAPONSTATE_RELEASED,
48 WEAPONSTATE_OVERHEATED,
49 WEAPONSTATE_DRAW,
50 WEAPONSTATE_RELOAD_START,
51 WEAPONSTATE_RELOAD,
52 WEAPONSTATE_RELOAD_END
53} nsweapon_state_t;
54
55string nsweapon_state_s[] =
56{
57 "WEAPONSTATE_IDLE",
58 "WEAPONSTATE_RELOAD_START",
59 "WEAPONSTATE_RELOAD",
60 "WEAPONSTATE_RELOAD_END",
61 "WEAPONSTATE_CHARGING",
62 "WEAPONSTATE_FIRELOOP",
63 "WEAPONSTATE_RELEASED",
64 "WEAPONSTATE_OVERHEATED"
65};
66
67typedef enum
68{
69 WEPEVENT_FIRED,
70 WEPEVENT_RELOADED
71} nsweapon_event_t;
72
73#define CHAN_LOOP 5
74
168class
170{
171public:
172 void NSWeapon(void);
173
174 virtual void InputFrame(void);
175 virtual void AddedToInventory(void);
176 virtual void RemovedFromInventory(void);
177
178 /* overrides */
179#ifdef SERVER
180 virtual void Spawned(void);
181 virtual void SpawnKey(string, string);
182 virtual void Save(float);
183 virtual void Restore(string, string);
184 virtual void EvaluateEntity(void);
185 virtual float SendEntity(entity,float);
186#endif
187
188 virtual bool TestFireAbility(string);
189
190#ifdef CLIENT
191 virtual void UpdateViewmodel(void);
192 virtual void ClientFX(bool);
193 virtual void PredictPreFrame(void);
194 virtual void PredictPostFrame(void);
195 virtual void ReceiveEntity(float,float);
196 virtual void ReceiveEvent(float);
197#endif
198
199 virtual bool UsesSecondaryAmmo(void);
200 virtual bool IsEmpty(void);
201 virtual bool IsWeapon(void);
202 virtual bool HasReserveAmmo(void);
203
205 virtual void Draw(void);
207 virtual void Holster(void);
209 virtual void PrimaryAttack(void);
211 virtual void SecondaryAttack(void);
213 virtual void Reload(void);
215 virtual void Release(void);
217 virtual void Idle(void);
219 virtual void UpdateGUI(void);
220
221 nonvirtual void SetViewModel(string);
222 nonvirtual void SetWorldModel(string);
223 nonvirtual void SetPlayerModel(string);
224 nonvirtual void SetWeaponFrame(float);
225 nonvirtual void PlaySound(string, float, bool);
226
227 /* state */
228 nonvirtual nsweapon_state_t GetWeaponState(void);
229
230 virtual void SetAttackNext(float);
231 virtual void SetReloadNext(float);
232 virtual void SetIdleNext(float);
233 virtual bool CanFire(void);
234 virtual bool CanIdle(void);
235 virtual bool CanReload(void);
236 virtual bool UseAmmo(string);
237
239 virtual void WeaponStartedFiring(void);
241 virtual void WeaponStoppedFiring(void);
242
244 nonvirtual bool WeaponIsFiring(void);
245
247 virtual void FiredWeaponAttack(string);
249 virtual void ReleasedWeaponAttack(string);
250
252 virtual void SwitchedToWeapon(void);
254 virtual void SwitchedFromWeapon(void);
255
257 virtual void UpdateFireInfoCache(void);
258
260 nonvirtual void SwitchFireInfo(string);
261 nonvirtual bool DetonateDef(string);
262 nonvirtual void Attack(string);
263
264private:
266 nonvirtual void _SetWeaponState(nsweapon_state_t);
268 nonvirtual void _SwitchedToCallback(void);
270 nonvirtual void _SwitchedFromCallback(void);
272 nonvirtual void _CacheWeaponDefVariables(void);
273 nonvirtual void _WeaponStartedFiring(void);
274 nonvirtual void _WeaponStoppedFiring(void);
275 nonvirtual void _PrimaryAttack(void);
276 nonvirtual void _SecondaryAttack(void);
277 nonvirtual void _SwitchedWeaponMode(void);
278 virtual void _AddedCallback(void);
279 virtual void _RemovedCallback(void);
280
282 nonvirtual NSWeapon GetNextWeapon(void);
284 nonvirtual NSWeapon GetPreviousWeapon(void);
285
286#ifdef CLIENT
287 virtual void HandleAnimEvent(float, int, string);
288#endif
289
290#ifdef SERVER
291 nonvirtual void _ReloadFinished(void);
292#endif
293
294 /* weapon related spawn keys */
295 string m_strWeaponTitle;
296 int m_iHudSlot;
297 int m_iHudSlotPos;
298 string m_icon;
299 string m_iconSel;
300
301 string m_strWeaponViewModel;
302 string m_strWeaponPlayerModel;
303 string m_strWeaponScript;
304 string m_strAmmoType;
305 bool m_bAmmoRequired;
306 int m_iClipStartSize;
307 string m_strFlashShader;
308 string m_strFlashModel;
309 vector m_vecFlashColor;
310 float m_flFlashRadius;
311 string m_strDropItemDef;
312 string m_strSmokeParticle;
313 bool m_bSmokeContinous;
314 float m_fxTrail;
315
316 /* extra networking */
317 bool m_bFiring;
318
319 /* cached variables. don't save - recalculate! */
320 string m_primaryFireInfo;
321 string m_secondaryFireInfo;
322 int m_primaryAmmoType;
323 int m_secondaryAmmoType;
324 float m_muzzleModelIndex;
325 float m_altMuzzleModelIndex;
326 float m_flPrimedFuse;
327 float m_flTriggerDelay;
328 float m_flZoomFOV;
329 bool m_bPowerAmmo;
330 bool m_bRemoveOnEmpty;
331 string m_strLastFireInfo;
332 float m_jointTrailWorld;
333 float m_jointTrailView;
334 float m_flSpeedMod;
335 bool m_bAltModeSwitch;
336 bool m_bBuggyIdleAnim;
337
338 float m_nextWeapon_entnum;
339 float m_prevWeapon_entnum;
340 NSWeapon m_nextWeapon_net;
341 NSWeapon m_prevWeapon_net;
342
343 /* cached fireInfo */
344 string m_fiDetonateOnFire;
345 float m_fiMeleeRange;
346 vector m_fiPunchAngle;
347 vector m_fiPunchSpring;
348 string m_fiSndFire;
349 string m_fiSndFailed;
350 string m_fiSndFireLast;
351 string m_fiSndRelease;
352 string m_fiSndEmpty;
353 int m_fiAmmoType;
354 int m_fiAmmoPerShot;
355 bool m_fiAmmoRequired;
356 float m_fiFireRate;
357 string m_fiOnFire;
358 string m_fiOnRelease;
359 bool m_fiWillRelease;
360 bool m_fiSemiAuto;
361 string m_fiSndFireLoop;
362 float m_flReloadSpeed;
363 float m_fiChargeTime;
364 bool m_bHasLoop;
365 string m_fiSndFireStart;
366 string m_fiSndFireStop;
367 string m_fiSndFireLoop;
368 bool m_fiDrawAfterRelease;
369
370 bool m_fiCocks;
371 string m_fiSndCock;
372
373 float m_fiJointMuzzle; /* World Model only */
374 float m_fiJointBarrel; /* View Model only */
375 string m_fiBrassDef;
376 float m_fiBrassDelay;
377
378 /* overheating */
379 float m_fiOverheatLength;
380 float m_fiOverheatPoints;
381
382 NETWORKED_INT(m_iClip)
383 NETWORKED_INT(m_iClipSize)
384 NETWORKED_FLOAT(m_iMode)
385 NETWORKED_MODELINDEX(m_viewModel)
386 NETWORKED_MODELINDEX(m_worldModel)
387 NETWORKED_MODELINDEX(m_playerModel)
388 NETWORKED_FLOAT(m_flFireRate)
389 NETWORKED_FLOAT(m_dState)
390 NETWORKED_BOOL(m_bFiring)
391 NETWORKED_BOOL(m_flOverheating)
392};
393
394.NSWeapon m_nextWeapon;
395.NSWeapon m_prevWeapon;
396
This entity class represents inventory items, weapons.
Definition: NSItem.h:67
This entity class represents weapon based items.
Definition: NSWeapon.h:170
void NSWeapon(void)
Definition: NSWeapon.qc:18
typedef enumflags
Defines the valid alignment flags for text fields.
Definition: font.h:37