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} 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 ncWeapon(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 ncWeapon GetNextWeapon(void);
284 nonvirtual ncWeapon GetPreviousWeapon(void);
286 nonvirtual void EmptySound(void);
287
288#ifdef CLIENT
289 virtual void HandleAnimEvent(float, int, string);
290#endif
291
292#ifdef SERVER
293 nonvirtual void _ReloadFinished(void);
294#endif
295
296 /* weapon related spawn keys */
297 string m_strWeaponTitle;
298 int m_iHudSlot;
299 int m_iHudSlotPos;
300 string m_icon;
301 string m_iconSel;
302
303 string m_strWeaponViewModel;
304 string m_strWeaponPlayerModel;
305 string m_strWeaponScript;
306 string m_strAmmoType;
307 bool m_bAmmoRequired;
308 int m_iClipStartSize;
309 string m_strFlashShader;
310 string m_strFlashModel;
311 vector m_vecFlashColor;
312 float m_flFlashRadius;
313 string m_strDropItemDef;
314 string m_strSmokeParticle;
315 bool m_bSmokeContinous;
316 float m_fxTrail;
317
318 /* extra networking */
319 bool m_bFiring;
320
321 /* cached variables. don't save - recalculate! */
322 string m_primaryFireInfo;
323 string m_secondaryFireInfo;
324 int m_primaryAmmoType;
325 int m_secondaryAmmoType;
326 float m_muzzleModelIndex;
327 float m_altMuzzleModelIndex;
328 float m_flPrimedFuse;
329 float m_flTriggerDelay;
330 float m_flZoomFOV;
331 bool m_bPowerAmmo;
332 bool m_bRemoveOnEmpty;
333 string m_strLastFireInfo;
334 float m_jointTrailWorld;
335 float m_jointTrailView;
336 float m_flSpeedMod;
337 bool m_bAltModeSwitch;
338 bool m_bBuggyIdleAnim;
339
340 float m_nextWeapon_entnum;
341 float m_prevWeapon_entnum;
342 ncWeapon m_nextWeapon_net;
343 ncWeapon m_prevWeapon_net;
344
345 /* cached fireInfo */
346 string m_fiDetonateOnFire;
347 vector m_fiPunchAngle;
348 vector m_fiPunchSpring;
349 string m_fiSndFire;
350 string m_fiSndFailed;
351 string m_fiSndFireLast;
352 string m_fiSndRelease;
353 string m_fiSndEmpty;
354 int m_fiAmmoType;
355 int m_fiAmmoPerShot;
356 bool m_fiAmmoRequired;
357 float m_fiFireRate;
358 string m_fiOnFire;
359 string m_fiOnRelease;
360 bool m_fiWillRelease;
361 bool m_fiSemiAuto;
362 string m_fiSndFireLoop;
363 float m_flReloadSpeed;
364 float m_fiChargeTime;
365 bool m_bHasLoop;
366 string m_fiSndFireStart;
367 string m_fiSndFireStop;
368 string m_fiSndFireLoop;
369 bool m_fiDrawAfterRelease;
370 bool m_fireUnderwater;
371
372 bool m_fiCocks;
373 string m_fiSndCock;
374
375 float m_fiJointMuzzle; /* World Model only */
376 float m_fiJointBarrel; /* View Model only */
377 string m_fiBrassDef;
378 float m_fiBrassDelay;
379
380 /* overheating */
381 float m_fiOverheatLength;
382 float m_fiOverheatPoints;
383
384 NETWORKED_INT(m_iClip)
385 NETWORKED_INT(m_iClipSize)
386 NETWORKED_FLOAT(m_iMode)
387 NETWORKED_MODELINDEX(m_viewModel)
388 NETWORKED_MODELINDEX(m_worldModel)
389 NETWORKED_MODELINDEX(m_playerModel)
390 NETWORKED_FLOAT(m_flFireRate)
391 NETWORKED_FLOAT(m_dState)
392 NETWORKED_BOOL(m_bFiring)
393 NETWORKED_BOOL(m_flOverheating)
394};
395
396.ncWeapon m_nextWeapon;
397.ncWeapon m_prevWeapon;
398
This entity class represents inventory items, weapons.
Definition: Item.h:67
This entity class represents weapon based items.
Definition: Weapon.h:170
void ncWeapon(void)
Definition: Weapon.qc:18
typedef enumflags
Defines the valid alignment flags for text fields.
Definition: font.h:37