diff --git a/base/src/shared/weapons.qc b/base/src/shared/weapons.qc deleted file mode 100644 index bdadb62f..00000000 --- a/base/src/shared/weapons.qc +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2023 Vera Visions LLC. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -weapon_t w_null = {}; -weapon_t g_weapons[] = { - w_null -}; diff --git a/src/client/entry.qc b/src/client/entry.qc index cf2a30b0..9f12e1b8 100644 --- a/src/client/entry.qc +++ b/src/client/entry.qc @@ -622,4 +622,7 @@ CSQC_Shutdown(void) Sound_Shutdown(); PropData_Shutdown(); NSLog("Client game shutdown."); + + /* ENGINE, PLS FIX */ + input_cursor_entitynumber = 0; } diff --git a/src/shared/NSClientPlayer.qc b/src/shared/NSClientPlayer.qc index 0bc9d0cb..69d749a8 100644 --- a/src/shared/NSClientPlayer.qc +++ b/src/shared/NSClientPlayer.qc @@ -249,14 +249,18 @@ NSClientPlayer::ProcessInput(void) } /* weapon system */ - if (input_buttons & INPUT_SECONDARY) + if (input_buttons & INPUT_SECONDARY) { + m_activeWeapon._WeaponStartedFiring(); m_activeWeapon.SecondaryAttack(); - else if (input_buttons & INPUT_PRIMARY) + } else if (input_buttons & INPUT_PRIMARY) { + m_activeWeapon._WeaponStartedFiring(); m_activeWeapon.PrimaryAttack(); - else if (input_buttons & INPUT_RELOAD) + } else if (input_buttons & INPUT_RELOAD) { m_activeWeapon.Reload(); - else + } else { + m_activeWeapon._WeaponStoppedFiring(); m_activeWeapon.Release(); + } } /* this is where it gets mod specific really fast, diff --git a/src/shared/NSDict.h b/src/shared/NSDict.h index 574a5667..edb634e9 100644 --- a/src/shared/NSDict.h +++ b/src/shared/NSDict.h @@ -14,6 +14,15 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +/** This class is responsible for handling groups of key/value pairs. + +It handles entity spawns, respawns, +save/load as well as key/value pair loading, as well as inputs/outputs +which is our basic entity model. + +This is a very low-level class. You're never meant to use this. +Use NSEntity as a basis for your classes. +*/ class NSDict { @@ -31,6 +40,8 @@ public: nonvirtual void AddKey(string, string); nonvirtual void RemoveKey(string); + nonvirtual NSDict InitWithSpawnData(string); + private: nonvirtual void _AddRemoveKey(string, string, bool); string m_strBody; diff --git a/src/shared/NSDict.qc b/src/shared/NSDict.qc index b02283b1..9bae91b4 100644 --- a/src/shared/NSDict.qc +++ b/src/shared/NSDict.qc @@ -96,3 +96,11 @@ NSDict::RemoveKey(string keyName) { _AddRemoveKey(keyName, "", true); } + +NSDict +NSDict::InitWithSpawnData(string spawnData) +{ + NSDict newDict = spawn(NSDict); + newDict.SetDeclBody(spawnData); + return (newDict); +} diff --git a/src/shared/NSSurfacePropEntity.qc b/src/shared/NSSurfacePropEntity.qc index 8c4aed1a..489834ac 100644 --- a/src/shared/NSSurfacePropEntity.qc +++ b/src/shared/NSSurfacePropEntity.qc @@ -830,8 +830,7 @@ entityDamage(entity targetEnt, entity inflictingEnt, entity attackingEnt, string return; } - NSDict damageDecl = spawn(NSDict); - damageDecl.SetDeclBody(damageDef); + NSDict damageDecl = NSDict::InitWithSpawnData(damageDef); theTarget.Damage(inflictingEnt, attackingEnt, damageDecl, 1.0, damageDir, hitLocation); remove(damageDecl); #endif diff --git a/src/shared/NSWeapon.h b/src/shared/NSWeapon.h index 7fed6a4a..94abfe7f 100644 --- a/src/shared/NSWeapon.h +++ b/src/shared/NSWeapon.h @@ -137,10 +137,15 @@ public: virtual bool CanIdle(void); virtual bool UseAmmo(string); - /** Overridable: Called when the weapon has been fired. */ - virtual void FiredWeapon(string); - /** Overridable: Called when the weapon has been released. */ - virtual void ReleasedWeapon(string); + /** Overridable: Called once when the weapon started firing. */ + virtual void WeaponStartedFiring(void); + /** Overridable: Called once when the weapon stopped firing. */ + virtual void WeaponStoppedFiring(void); + + /** Overridable: Controls def_onFire event. */ + virtual void FiredWeaponAttack(string); + /** Overridable: Controls def_onRelease event. */ + virtual void ReleasedWeaponAttack(string); /** Overridable: Called when we've switched to this weapon successfully. */ virtual void SwitchedToWeapon(void); diff --git a/src/shared/NSWeapon.qc b/src/shared/NSWeapon.qc index afdbe0e7..2cce97c0 100644 --- a/src/shared/NSWeapon.qc +++ b/src/shared/NSWeapon.qc @@ -124,8 +124,6 @@ NSWeapon::Spawned(void) SetViewModel(m_strWeaponViewModel); SetWorldModel(model); SetPlayerModel(m_strWeaponPlayerModel); - - printf("%S\n", classname); } void @@ -614,6 +612,7 @@ void NSWeapon::_SwitchedToCallback(void) { _CacheWeaponDefVariables(); + SwitchFireInfo(m_primaryFireInfo); SetAttackNext(0.0f); SetIdleNext(0.0f); @@ -736,14 +735,14 @@ NSWeapon::DetonateDef(string defName) } void -NSWeapon::FiredWeapon(string fireInfo) +NSWeapon::FiredWeaponAttack(string fireInfo) { NSClientPlayer ourOwner = (NSClientPlayer)GetOwner(); ourOwner.AttackByDef(fireInfo, false); } void -NSWeapon::ReleasedWeapon(string fireInfo) +NSWeapon::ReleasedWeaponAttack(string fireInfo) { NSClientPlayer ourOwner = (NSClientPlayer)GetOwner(); ourOwner.AttackByDef(fireInfo, true); @@ -879,7 +878,7 @@ NSWeapon::Attack(string fireInfo) ourOwner.StartSoundDef(m_fiSndFire, CHAN_WEAPON, true); #endif - FiredWeapon(fireInfo); + FiredWeaponAttack(fireInfo); if (m_iClipSize > 0 && m_iClip == 0) shotAnim = GetSubDefAct(fireInfo, "actFireLast"); @@ -995,8 +994,6 @@ NSWeapon::Reload(void) } reloadStartAct = GetDefAct("actReloadStart"); - //printf("m_iClip:%i m_iClipSize: %i\n", m_iClip, m_iClipSize); - /* we cannot reload this weapon by principle. */ if (!m_iClipSize) { return; @@ -1020,8 +1017,9 @@ NSWeapon::Reload(void) } /* no leftover ammo at all. */ - if (ourOwner.HasAmmo(ammoTypeID, 1) == false) + if (ourOwner.HasAmmo(ammoTypeID, 1) == false) { return; + } /* we have a start-reload, so this is a shotgun styled weapon reload */ if (reloadStartAct) { @@ -1031,17 +1029,21 @@ NSWeapon::Reload(void) } if (!m_iMode) { - if (m_iClipSize > 0 && m_iClip == 0) + if (m_iClipSize > 0 && m_iClip == 0) { reloadAnimation = GetDefAct("actReloadEmpty"); + } - if (!reloadAnimation) + if (!reloadAnimation) { reloadAnimation = GetDefAct("actReload"); + } } else { - if (m_iClipSize > 0 && m_iClip == 0) + if (m_iClipSize > 0 && m_iClip == 0) { reloadAnimation = GetDefAct("actAltReloadEmpty"); + } - if (!reloadAnimation) + if (!reloadAnimation) { reloadAnimation = GetDefAct("actAltReload"); + } } reloadTime = frameduration(m_viewModel, reloadAnimation); @@ -1082,6 +1084,46 @@ NSWeapon::HasReserveAmmo(void) return (false); } +void +NSWeapon::_WeaponStartedFiring(void) +{ + if (CanFire() == false) { + return; + } + + /* hasn't been fired yet. */ + if (!(vv_flags & VFL_FIRING)) { + WeaponStartedFiring(); + } + + vv_flags |= VFL_FIRING; +} + +void +NSWeapon::_WeaponStoppedFiring(void) +{ + if (CanFire() == false) { + return; + } + + /* was still registed as firing */ + if (vv_flags & VFL_FIRING) { + WeaponStoppedFiring(); + } + + vv_flags &= ~VFL_FIRING; +} + +void +NSWeapon::WeaponStartedFiring(void) +{ +} + +void +NSWeapon::WeaponStoppedFiring(void) +{ +} + void NSWeapon::Release(void) { @@ -1110,7 +1152,7 @@ NSWeapon::Release(void) } } - ReleasedWeapon(m_strLastFireInfo); + ReleasedWeaponAttack(m_strLastFireInfo); m_fiWillRelease = false; SetWeaponFrame(idleAnim); SetAttackNext(1.0f); @@ -1479,6 +1521,7 @@ NSWeapon_SelectWeapon(NSWeapon nextWeapon) return; } + /* this gets passed in NSClientPlayer::ClientInputFrame() to the server */ pSeat->m_iHUDWeaponSelected = nextWeapon.GetSharedID(); } #endif diff --git a/src/shared/flags.h b/src/shared/flags.h index 9abf97cc..940e6c9c 100644 --- a/src/shared/flags.h +++ b/src/shared/flags.h @@ -46,3 +46,4 @@ #define VFL_NOATTACK (1<<10) /**< Entity is not allowed to fire. */ #define VFL_PRIMEDFUSE (1<<11) /**< Entity is not allowed to fire. */ #define VFL_REDRAW (1<<12) /**< Entity is not allowed to fire. */ +#define VFL_FIRING (1<<13) /**< Entity is firing. */