Nuclide
Software Development Kit for id Technology (BETA)
Weapon.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 WEAPONSTATE_BURSTFIRING
54} nsweapon_state_t;
55
56string nsweapon_state_s[] =
57{
58 "WEAPONSTATE_IDLE",
59 "WEAPONSTATE_RELOAD_START",
60 "WEAPONSTATE_RELOAD",
61 "WEAPONSTATE_RELOAD_END",
62 "WEAPONSTATE_CHARGING",
63 "WEAPONSTATE_FIRELOOP",
64 "WEAPONSTATE_RELEASED",
65 "WEAPONSTATE_OVERHEATED"
66};
67
68typedef enum
69{
70 WEPEVENT_FIRED,
71 WEPEVENT_RELEASED,
72 WEPEVENT_RELOADED
73} nsweapon_event_t;
74
75#define CHAN_LOOP 5
76
303class
305{
306public:
307 void ncWeapon(void);
308
309 virtual void InputFrame(void);
310 virtual void AddedToInventory(void);
311 virtual void RemovedFromInventory(void);
312
313 /* overrides */
314#ifdef SERVER
315 virtual void Spawned(void);
316 virtual void SpawnKey(string, string);
317 virtual void Save(float);
318 virtual void Restore(string, string);
319 virtual void EvaluateEntity(void);
320 virtual float SendEntity(entity,float);
321 virtual void RestoreComplete(void);
322 virtual void GiveBonusItems(entity, bool);
323 virtual bool ItemBonusCheck(entity);
324
325 virtual void EjectBrass(void);
326 virtual void EjectCartridge(void);
327#endif
328
329 virtual bool TestFireAbility(string);
330
331#ifdef CLIENT
332 virtual void ClientFX(bool);
333 virtual void PredictPreFrame(void);
334 virtual void PredictPostFrame(void);
335 virtual void ReceiveEntity(float,float);
336 virtual void ReceiveEvent(float);
337#endif
338
339 virtual bool UsesSecondaryAmmo(void);
340 virtual bool IsEmpty(void);
341 virtual bool IsWeapon(void);
342 virtual bool HasReserveAmmo(void);
343
345 virtual void Draw(void);
347 virtual void Holster(void);
349 virtual void PrimaryAttack(void);
351 virtual void SecondaryAttack(void);
353 virtual void Reload(void);
355 virtual void Release(void);
357 virtual void Idle(void);
359 virtual void UpdateGUI(void);
360
361 nonvirtual void SetViewModel(string);
362 nonvirtual void SetWorldModel(string);
363 nonvirtual void SetPlayerModel(string);
364 nonvirtual void SetWeaponFrame(float);
365 nonvirtual void PlaySound(string, float, bool);
366
367 /* state */
368 nonvirtual nsweapon_state_t GetWeaponState(void);
369
370 virtual void SetAttackNext(float);
371 virtual void SetReloadNext(float);
372 virtual void SetIdleNext(float);
373 virtual bool CanFire(void);
374 virtual bool CanIdle(void);
375 virtual bool CanReload(void);
376 virtual bool UseAmmo(string);
377
379 virtual void WeaponStartedFiring(void);
381 virtual void WeaponStoppedFiring(void);
383 virtual void WeaponStartedReloading(void);
385 virtual void WeaponStoppedReloading(void);
386
388 virtual void FiredWeaponAttack(string);
390 virtual void ReleasedWeaponAttack(string);
391
393 virtual void SwitchedToWeapon(void);
395 virtual void SwitchedFromWeapon(void);
396
398 virtual void UpdateFireInfoCache(void);
400 virtual void FireInfoChanged(void);
401
403 nonvirtual bool WeaponIsFiring(void);
404
406 nonvirtual void SwitchFireInfo(string);
407 nonvirtual bool DetonateDef(string);
408 nonvirtual void Attack(string);
409
410 nonvirtual int GetClip(void);
411 nonvirtual int GetClipSize(void);
412 nonvirtual bool RequiresAmmo(void);
413 nonvirtual int FireInfoSelected(void);
414 nonvirtual float OverheatingProgress(void);
415 nonvirtual float PlayerSpeedMod(void);
416
418 virtual void ReloadCachedAttributes(void);
419
420private:
422 nonvirtual void _SetWeaponState(nsweapon_state_t);
424 nonvirtual void _SwitchedToCallback(void);
426 nonvirtual void _SwitchedFromCallback(void);
427 nonvirtual void _WeaponStartedFiring(void);
428 nonvirtual void _WeaponStoppedFiring(void);
429 nonvirtual void _PrimaryAttack(void);
430 nonvirtual void _SecondaryAttack(void);
431 nonvirtual void _SwitchedWeaponMode(void);
432 virtual void _AddedCallback(void);
433 virtual void _RemovedCallback(void);
434
436 nonvirtual ncWeapon GetNextWeapon(void);
438 nonvirtual ncWeapon GetPreviousWeapon(void);
440 nonvirtual void EmptySound(void);
442 nonvirtual void SetViewZoom(float);
443
444#ifdef CLIENT
445 virtual void HandleAnimEvent(float, int, string);
446#endif
447
448#ifdef SERVER
449 nonvirtual void _ReloadFinished(void);
450#endif
451
452 /* weapon related spawn keys */
453 string m_weaponTitle;
454 int m_weaponHUDSlot;
455 int m_weaponHUDSlotPos;
456 string m_weaponHUDIcon;
457 string m_weaponHUDIconSel;
458 string m_weaponViewModelPath;
459 string m_weaponPlayerModelPath;
460 string m_weaponScript;
461 string m_weaponAmmoType;
462 bool m_weaponRequiresAmmo;
463 int m_weaponClipStartSize;
464 string m_weaponDropsItem;
465
466 NETWORKED_INT(m_weaponClip)
467 NETWORKED_INT(m_weaponClipSize)
468 NETWORKED_FLOAT(m_weaponFireInfoValue)
469 NETWORKED_MODELINDEX(m_viewModel)
470 NETWORKED_MODELINDEX(m_worldModel)
471 NETWORKED_MODELINDEX(m_playerModel)
472 NETWORKED_FLOAT(m_weaponFireRate)
473 NETWORKED_FLOAT(m_weaponState)
474 NETWORKED_BOOL(m_weaponIsFiring)
475 NETWORKED_BOOL(m_weaponOverheating)
476 NETWORKED_FLOAT(m_burstCount)
477
478 /* cached variables. don't save - recalculate! */
479 string m_weaponLastFireInfo;
480 string m_primaryFireInfo;
481 string m_secondaryFireInfo;
482 int m_primaryAmmoType;
483 int m_secondaryAmmoType;
484 float m_jointTrailWorld;
485 float m_jointTrailView;
486 float m_weaponAmmoRegenTime;
487 float m_weaponAmmoDepleteTime;
488 string m_animPrefix;
489 bool m_altAlternates;
490
491 /* extra networking */
492 float m_nextWeapon_entnum;
493 float m_prevWeapon_entnum;
494 ncWeapon m_nextWeapon_net;
495 ncWeapon m_prevWeapon_net;
496
497 /* cached fireInfo */
498 string m_fiMuzzleFlashMaterial;
499 string m_fiMuzzleFlashModelPath;
500 vector m_fiMuzzleFlashColor;
501 float m_fiMuzzleFlashRadius;
502 string m_fiFXSmokeParticle;
503 bool m_fiFXSmokeContinous;
504 float m_fiFXTrail;
505 bool m_fiAmmoRequired;
506 bool m_fiCocks;
507 bool m_fiDrawAfterRelease;
508 bool m_fiFireUnderwater;
509 bool m_fiLoopingFire;
510 bool m_fiSemiAuto;
511 bool m_fiWillRelease;
512 float m_fiBrassDelay;
513 float m_fiCartridgeDelay;
514 float m_fiChargeTime;
515 float m_fiFireRate;
516 float m_fiOverheatLength;
517 float m_fiOverheatPoints;
518 float m_fiReloadTime;
519 int m_fiAmmoPerShot;
520 int m_fiAmmoType;
521 float m_fiPrimedFuse;
522 float m_fiZoomFOV;
523 bool m_fiPowerAmmo;
524 bool m_fiRemoveOnEmpty;
525 bool m_switchOnEmpty;
526 string m_fiBrassDef;
527 string m_fiCartridgeDef;
528 string m_fiDetonateOnFire;
529 string m_fiOnFire;
530 string m_fiOnRelease;
531
532 ncSoundDict m_fiSndDraw;
533 ncSoundDict m_fiSndDelay;
534 ncSoundDict m_fiSndHolster;
535 ncSoundDict m_fiSndReload;
536 ncSoundDict m_fiSndReloadStart;
537 ncSoundDict m_fiSndReloadEnd;
538 ncSoundDict m_fiSndCock;
539 ncSoundDict m_fiSndEmpty;
540 ncSoundDict m_fiSndFailed;
541 ncSoundDict m_fiSndFire;
542 ncSoundDict m_fiSndFireLast;
543 ncSoundDict m_fiSndFireLoop;
544 ncSoundDict m_fiSndFireLoop;
545 ncSoundDict m_fiSndFireStart;
546 ncSoundDict m_fiSndFireStop;
547 ncSoundDict m_fiSndRelease;
548 ncSoundDict m_fiSndEjectBrass;
549 ncSoundDict m_fiSndEjectCartridge;
550 ncSoundDict m_sndRaiseScope;
551 ncSoundDict m_sndLowerScope;
552 ncSoundDict m_sndModeOn;
553 ncSoundDict m_sndModeOff;
554
555 vector m_fiPunchAngle;
556 vector m_fiPunchSpring;
557 float m_fiSpeedMod;
558 bool m_fiAltModeSwitch;
559 bool m_fiBuggyIdleAnim;
560 int m_fiRegenAmmo;
561 float m_fiRegenRate;
562 int m_fiDepleteAmmo;
563 float m_fiDepleteRate;
564 float m_fiMaxBurst;
565 float m_fiBurstTime;
566 float m_fiKnockBack;
567 float m_fiKnockBackRelease;
568 float m_fiTestDistance;
569};
570
571.ncWeapon m_nextWeapon;
572.ncWeapon m_prevWeapon;
573
This entity class represents inventory items, weapons.
Definition: Item.h:138
Dictionary for sound effect definition.
Definition: SoundDict.h:39
This entity class represents weapon based items.
Definition: Weapon.h:305
void ncWeapon(void)
Definition: Weapon.qc:18
typedef enumflags
Defines the valid alignment flags for text fields.
Definition: font.h:37