Nuclide
Software Development Kit for id Tech
NSWeapon.h
Go to the documentation of this file.
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_X,
23 WEAPONFL_CHANGED_VELOCITY_Y,
24 WEAPONFL_CHANGED_VELOCITY_Z,
25 WEAPONFL_CHANGED_ANGULARVELOCITY,
26 WEAPONFL_CHANGED_SIZE,
27 WEAPONFL_CHANGED_FLAGS,
28 WEAPONFL_CHANGED_SOLID,
29 WEAPONFL_CHANGED_FRAME,
30 WEAPONFL_CHANGED_SKIN,
31 WEAPONFL_CHANGED_MOVETYPE,
32 WEAPONFL_CHANGED_EFFECTS,
33 WEAPONFL_CHANGED_BODY,
34 WEAPONFL_CHANGED_SCALE,
35 WEAPONFL_CHANGED_ENTITYDEF,
36 WEAPONFL_CHANGED_CLIP,
37 WEAPONFL_CHANGED_CHAIN,
38 WEAPONFL_CHANGED_STATE
39} nsweapon_changed_t;
40
41typedef enum
42{
48
49typedef enum
50{
54
84class
86{
87public:
88 void NSWeapon(void);
89
90 virtual void AddedToInventory(void);
91 virtual void RemovedFromInventory(void);
92
93 /* overrides */
94#ifdef SERVER
95 virtual void Spawned(void);
96 virtual void SpawnKey(string, string);
97 virtual void Save(float);
98 virtual void Restore(string, string);
99 virtual void EvaluateEntity(void);
100 virtual float SendEntity(entity,float);
101#endif
102
103#ifdef CLIENT
104 virtual void ClientFX(bool);
105 virtual void PredictPreFrame(void);
106 virtual void PredictPostFrame(void);
107 virtual void ReceiveEntity(float,float);
108 virtual void ReceiveEvent(float);
109#endif
110
111 virtual bool IsWeapon(void);
112 virtual bool HasReserveAmmo(void);
113
115 virtual void Draw(void);
117 virtual void Holster(void);
119 virtual void PrimaryAttack(void);
121 virtual void SecondaryAttack(void);
123 virtual void Reload(void);
125 virtual void Release(void);
127 virtual void UpdateGUI(void);
128
129 nonvirtual void SetViewModel(string);
130 nonvirtual void SetWorldModel(string);
131 nonvirtual void SetPlayerModel(string);
132 nonvirtual void SetWeaponFrame(float);
133
134 virtual void SetAttackNext(float);
135 virtual void SetIdleNext(float);
136 virtual bool CanFire(void);
137 virtual bool CanIdle(void);
138 virtual bool UseAmmo(string);
139
141 virtual void FiredWeapon(string);
143 virtual void ReleasedWeapon(string);
144
146 virtual void SwitchedToWeapon(void);
148 virtual void SwitchedFromWeapon(void);
149
151 virtual void UpdateFireInfoCache(void);
152
154 nonvirtual void SwitchFireInfo(string);
155 nonvirtual bool DetonateDef(string);
156 nonvirtual void Attack(string);
157
158private:
160 nonvirtual void _SwitchedToCallback(void);
162 nonvirtual void _SwitchedFromCallback(void);
164 nonvirtual void _CacheWeaponDefVariables(void);
165
166#ifdef SERVER
167 nonvirtual void _ReloadFinished(void);
168#endif
169
170 /* weapon related spawn keys */
171 string m_strWeaponViewModel;
172 string m_strWeaponPlayerModel;
173 string m_strWeaponScript;
174 string m_strAmmoType;
175 bool m_bAmmoRequired;
176 int m_iClipStartSize;
177 string m_strFlashShader;
178 string m_strFlashModel;
179 vector m_vecFlashColor;
180 float m_flFlashRadius;
181 string m_strDropItemDef;
182 string m_strSmokeParticle;
183 bool m_bSmokeContinous;
184 float m_fxTrail;
185
186 /* extra networking */
187 bool m_bFiring;
188
189 /* cached variables. don't save - recalculate! */
190 string m_primaryFireInfo;
191 string m_secondaryFireInfo;
192 int m_primaryAmmoType;
193 int m_secondaryAmmoType;
194 float m_muzzleModelIndex;
195 float m_altMuzzleModelIndex;
196 string m_meleeDef;
197 float m_flPrimedFuse;
198 float m_flTriggerDelay;
199 float m_flZoomFOV;
200 bool m_bPowerAmmo;
201 bool m_bRemoveOnEmpty;
202 string m_strLastFireInfo;
203 float m_jointTrailWorld;
204 float m_jointTrailView;
205 float m_flSpeedMod;
206
207 /* cached fireInfo */
208 string m_fiDetonateOnFire;
209 float m_fiMeleeRange;
210 vector m_fiPunchAngle;
211 string m_fiSndFire;
212 string m_fiSndEmpty;
213 int m_fiAmmoType;
214 int m_fiAmmoPerShot;
215 bool m_fiAmmoRequired;
216 float m_fiFireRate;
217 string m_fiOnFire;
218 string m_fiOnRelease;
219 bool m_fiWillRelease;
220 bool m_fiSemiAuto;
221 string m_fiSndFireLoop;
222
223 NETWORKED_INT(m_iClip)
224 NETWORKED_INT(m_iClipSize)
225 NETWORKED_FLOAT(m_iMode)
226 NETWORKED_MODELINDEX(m_viewModel)
227 NETWORKED_MODELINDEX(m_worldModel)
228 NETWORKED_MODELINDEX(m_playerModel)
229 NETWORKED_FLOAT(m_flFireRate)
230 NETWORKED_FLOAT(m_dState)
231 NETWORKED_BOOL(m_bFiring)
232};
233
234/* Helper functions for plugins, the rest of the codebase etc.
235
236These are, according to IW, common operations. Makes sense to
237handle the implementation ourselves as it'll prevent
238entityDefs changing from breaking plugins as a result.
239Some of these don't just do direct look-ups of keys. */
240
244string weaponType(string weaponDef);
245
248int weaponStartAmmo(string weaponDef);
249
252int weaponMaxAmmo(string weaponDef);
253
256bool weaponIsSemiAuto(string weaponDef);
257
260string weaponInventoryType(string weaponDef);
261
264float weaponFireTime(string weaponDef);
265
269int weaponClipSize(string weaponDef);
270
274string weaponClass(string weaponDef);
275
279bool isWeaponClipOnly(string weaponDef);
280
284bool isWeaponDetonationTimed(string weaponDef);
285
nsweapon_event_t
Definition: NSWeapon.h:50
@ WEPEVENT_RELOADED
Definition: NSWeapon.h:52
@ WEPEVENT_FIRED
Definition: NSWeapon.h:51
nsweapon_state_t
Definition: NSWeapon.h:42
@ WEAPONSTATE_RELOAD_START
Definition: NSWeapon.h:44
@ WEAPONSTATE_IDLE
Definition: NSWeapon.h:43
@ WEAPONSTATE_RELOAD
Definition: NSWeapon.h:45
@ WEAPONSTATE_RELOAD_END
Definition: NSWeapon.h:46
typedef enumflags
Definition: NSWeapon.h:18
This entity class represents inventory items, weapons.
Definition: NSItem.h:68
This entity class represents weapon based items.
Definition: NSWeapon.h:86
bool isWeaponClipOnly(string weaponDef)
Definition: mapC_weapons.h:81
float weaponFireTime(string weaponDef)
Definition: mapC_weapons.h:60
bool weaponIsSemiAuto(string weaponDef)
Definition: mapC_weapons.h:46
string weaponType(string weaponDef)
Definition: mapC_weapons.h:25
bool isWeaponDetonationTimed(string weaponDef)
Definition: mapC_weapons.h:88
string weaponClass(string weaponDef)
Definition: mapC_weapons.h:74
int weaponClipSize(string weaponDef)
Definition: mapC_weapons.h:67
int weaponMaxAmmo(string weaponDef)
Definition: mapC_weapons.h:39
string weaponInventoryType(string weaponDef)
Definition: mapC_weapons.h:53
int weaponStartAmmo(string weaponDef)
Definition: mapC_weapons.h:32
#define NETWORKED_MODELINDEX(x)
Definition: defs.h:26
#define NETWORKED_INT(x)
Definition: defs.h:20
#define NETWORKED_FLOAT(x)
Definition: defs.h:21
#define NETWORKED_BOOL(x)
Definition: defs.h:25