From c920dc2df083fa2a75a995966174ff8d97b26c58 Mon Sep 17 00:00:00 2001 From: Marco Cawthorne Date: Mon, 18 Sep 2023 17:57:47 -0700 Subject: [PATCH] NSMonster: add spawn key 'reserve_ammo', which should be self explanatory. See docs otherwise. --- src/shared/NSMonster.h | 2 ++ src/shared/NSMonster.qc | 32 +++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/shared/NSMonster.h b/src/shared/NSMonster.h index 57dd5f9a..9f401fb5 100644 --- a/src/shared/NSMonster.h +++ b/src/shared/NSMonster.h @@ -268,6 +268,7 @@ capable of fighting if prompted to. - "reload_count" : how many ranged attacks until reload. Only affects primary ranged attacks. - "reload_delay" : Time between reloads in seconds. Requires `reload_count` to be set > 0. - "snd_reload" : SoundDef to play when reloading. +- "reserve_ammo" : The amount of reserve ammo. -1 is infinite (default) - "attack_cone" : Cone in which to attack. - "attack_accuracy" : Accuracy (or rather, lack of) multiplier. @@ -552,6 +553,7 @@ private: float m_flReloadCount; float m_flReloadDelay; string m_sndReload; + float m_flReserveAmmo; string m_sndRangedAttack2; diff --git a/src/shared/NSMonster.qc b/src/shared/NSMonster.qc index b2bc4f33..95b17fe2 100644 --- a/src/shared/NSMonster.qc +++ b/src/shared/NSMonster.qc @@ -88,6 +88,8 @@ NSMonster::NSMonster(void) m_flSpecial1Range = m_flSpecial2Range = -1.0f; + m_flReserveAmmo = -1; /* unlimited */ + m_bWeaponStartsDrawn = true; m_flWalkSpeed = autocvar_ai_walkSpeed; @@ -193,6 +195,7 @@ NSMonster::Save(float handle) SaveFloat(handle, "m_flReloadCount", m_flReloadCount); SaveFloat(handle, "m_flReloadDelay", m_flReloadDelay); SaveString(handle, "m_sndReload", m_sndReload); + SaveFloat(handle, "m_flReserveAmmo", m_flReserveAmmo); SaveString(handle, "m_sndRangedAttack2", m_sndRangedAttack2); SaveBool(handle, "m_bWeaponStartsDrawn", m_bWeaponStartsDrawn); SaveString(handle, "m_strBodyOnDraw", m_strBodyOnDraw); @@ -426,6 +429,9 @@ NSMonster::Restore(string strKey, string strValue) case "m_sndReload": m_sndReload = ReadString(strValue); break; + case "m_flReserveAmmo": + m_flReserveAmmo = ReadFloat(strValue); + break; case "m_sndRangedAttack2": m_sndRangedAttack2 = ReadString(strValue); break; @@ -991,8 +997,29 @@ NSMonster::AttackRanged(void) /* can't shoot anything ranged anymore, need to reload. */ if (m_flReloadCount) if (_m_flReloadTracker > m_flReloadCount) { + float startAmmo = 0; float actReload = FramegroupForAct(ACT_RELOAD); - _m_flReloadTracker = 0; + + /* out of ammo, cannot reload */ + if (m_flReserveAmmo == 0) { + //NSMonster_Log("Out of ammo!"); + return 0; + } + + /* do we not have unlimited ammo? */ + if (m_flReserveAmmo != -1) { + m_flReserveAmmo -= m_flReloadCount; + NSMonster_Log("Reserve ammo: %d", m_flReserveAmmo); + + /* oh no, we're below 0 in terms of ammo. */ + if (m_flReserveAmmo < 0) { + startAmmo = -m_flReserveAmmo; + m_flReserveAmmo = 0; /* we're fully emptied now */ + } + } + + NSMonster_Log("Starting at %d bullets", startAmmo); + _m_flReloadTracker = startAmmo; AnimPlay(actReload); StartSoundDef(m_sndReload, CHAN_WEAPON, true); _m_bShouldThrow = false; @@ -1769,6 +1796,9 @@ NSMonster::SpawnKey(string strKey, string strValue) case "snd_reload": m_sndReload = ReadString(strValue); break; + case "reserve_ammo": + m_flReserveAmmo = ReadFloat(strValue); + break; case "def_attack_special": case "def_attack_special_1": m_defSpecial1 = ReadString(strValue);