diff --git a/src/shared/NSMonster.qc b/src/shared/NSMonster.qc index 1827a392..70d172a1 100644 --- a/src/shared/NSMonster.qc +++ b/src/shared/NSMonster.qc @@ -1441,6 +1441,8 @@ NSMonster::Physics(void) if (!IsAlive) return; + /* editors like Hammer like putting 'sequence' into spawndata + of monsters. so only ever force the animation when flagged as dead */ if (_m_bStartDead && m_flForceSequence) { if (m_iSequenceState != SEQUENCESTATE_IDLE) { SetFrame(m_flForceSequence); diff --git a/src/shared/NSNavAI.h b/src/shared/NSNavAI.h index 5bc80dc0..6f376f07 100644 --- a/src/shared/NSNavAI.h +++ b/src/shared/NSNavAI.h @@ -101,6 +101,12 @@ public: nonvirtual bool RemoveAllItems(bool); /** Removes all weapons from the inventory. Returns `false` when already clear. */ nonvirtual bool RemoveAllWeapons(void); + /** Returns the name of the current weapon. E.g. "weapon_foobar" */ + nonvirtual string GetCurrentWeapon(void); + /** Switches the entity to use the desired weapon. */ + nonvirtual void SwitchToWeapon(string); + /** Switches the entity to use the desired weapon. */ + nonvirtual void SwitchToExactWeapon(NSWeapon); nonvirtual void LaunchProjectile(string, bool, float); nonvirtual bool PlantCharge(string); diff --git a/src/shared/NSNavAI.qc b/src/shared/NSNavAI.qc index e3a65363..50607ec8 100644 --- a/src/shared/NSNavAI.qc +++ b/src/shared/NSNavAI.qc @@ -700,10 +700,8 @@ NSNavAI::GiveItem(string itemName) /* TODO: Replace this with a 'SwitchBest' type function? */ /* we have no active weapon, and this is our pick */ - if (!m_activeWeapon && m_itemList.IsWeapon() == true) { - m_activeWeapon = (NSWeapon)m_itemList; - m_activeWeapon._SwitchedToCallback(); - //m_activeWeapon.PrintDebugInfo(); + if (!m_activeWeapon) { + SwitchToExactWeapon((NSWeapon)m_itemList); } return (true); @@ -741,10 +739,8 @@ NSNavAI::GiveItem(string itemName) /* TODO: Replace this with a 'SwitchBest' type function? */ /* we have no active weapon, and this is our pick */ - if (!m_activeWeapon && linkedList.IsWeapon() == true) { - m_activeWeapon = (NSWeapon)linkedList; - m_activeWeapon._SwitchedToCallback(); - //m_activeWeapon.PrintDebugInfo(); + if (!m_activeWeapon) { + SwitchToExactWeapon((NSWeapon)linkedList); } return (true); @@ -883,6 +879,52 @@ NSNavAI::RemoveAllWeapons(void) return (true); } +string +NSNavAI::GetCurrentWeapon(void) +{ + if (m_activeWeapon) { + return (m_activeWeapon.classname); + } else { + return ""; + } +} + +void +NSNavAI::SwitchToWeapon(string weaponName) +{ + NSItem linkedList = __NULL__; + + /* we do not have an item. */ + if (!m_itemList) { + return; + } + + /* since we have something in the inventory, start there */ + linkedList = m_itemList; + + /* iterate through the inventory, then figure out if we already have it*/ + while (linkedList) { + /* we already have the item. */ + if (linkedList.classname == weaponName) { + SwitchToExactWeapon((NSWeapon)linkedList); + } + + linkedList = (NSItem)linkedList.chain; + } +} + +void +NSNavAI::SwitchToExactWeapon(NSWeapon item) +{ + if (item.IsWeapon() == false) { + return; + } + + m_activeWeapon = item; + m_activeWeapon._SwitchedToCallback(); + //m_activeWeapon.PrintDebugInfo(); +} + bool NSNavAI::AddItem(NSItem theItem) {