NSWeapon: rename some methods to be more verbose, add WeaponStartedFiring(), WeaponStoppedFiring()

NSDict: add InitWithSpawnData(string)
This commit is contained in:
Marco Cawthorne 2024-07-30 20:15:43 -07:00
parent 4315e92ef5
commit 37f5c907b4
Signed by: eukara
GPG key ID: CE2032F0A2882A22
9 changed files with 97 additions and 43 deletions

View file

@ -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
};

View file

@ -622,4 +622,7 @@ CSQC_Shutdown(void)
Sound_Shutdown();
PropData_Shutdown();
NSLog("Client game shutdown.");
/* ENGINE, PLS FIX */
input_cursor_entitynumber = 0;
}

View file

@ -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,

View file

@ -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;

View file

@ -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);
}

View file

@ -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

View file

@ -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);

View file

@ -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

View file

@ -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. */