NSNavAI: add methods GetCurrentWeapon(), SwitchToWeapon(string), SwitchToExactWeapon(NSWeapon)

This commit is contained in:
Marco Cawthorne 2024-07-24 14:26:20 -07:00
parent 24a9ef71ac
commit 1282bc42dd
Signed by: eukara
GPG key ID: CE2032F0A2882A22
3 changed files with 58 additions and 8 deletions

View file

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

View file

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

View file

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