NSNavAI: Inventory management functions.
This commit is contained in:
parent
822a7221b2
commit
bd7e78ab94
3 changed files with 114 additions and 1 deletions
|
@ -78,6 +78,10 @@ public:
|
||||||
nonvirtual bool GiveItem(string);
|
nonvirtual bool GiveItem(string);
|
||||||
/** Removes a named NSItem from the inventory Returns `false` when impossible. */
|
/** Removes a named NSItem from the inventory Returns `false` when impossible. */
|
||||||
nonvirtual bool RemoveItem(string);
|
nonvirtual bool RemoveItem(string);
|
||||||
|
/** Adds the specified NSItem to the inventory. Returns `false` when impossible. */
|
||||||
|
nonvirtual bool AddItem(NSItem);
|
||||||
|
/** Returns `true` or `false` depending on if the entity has the named item. */
|
||||||
|
nonvirtual bool HasItem(string);
|
||||||
|
|
||||||
#ifdef SERVER
|
#ifdef SERVER
|
||||||
/* overrides */
|
/* overrides */
|
||||||
|
@ -135,4 +139,5 @@ private:
|
||||||
|
|
||||||
/* These are defined in side defs\*.def, ammo_types and ammo_names */
|
/* These are defined in side defs\*.def, ammo_types and ammo_names */
|
||||||
int m_iAmmoTypes[MAX_AMMO_TYPES];
|
int m_iAmmoTypes[MAX_AMMO_TYPES];
|
||||||
|
NSItem m_itemList;
|
||||||
};
|
};
|
||||||
|
|
|
@ -526,14 +526,122 @@ NSNavAI::UseAmmo(int ammoType, int ammoAmount)
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
NSNavAI::HasItem(string itemName)
|
||||||
|
{
|
||||||
|
NSItem linkedList = __NULL__;
|
||||||
|
|
||||||
|
/* we do not have an item. */
|
||||||
|
if (!m_itemList) {
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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 == itemName) {
|
||||||
|
return (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
linkedList = linkedList.chain;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
NSNavAI::GiveItem(string itemName)
|
NSNavAI::GiveItem(string itemName)
|
||||||
{
|
{
|
||||||
|
#ifdef SERVER
|
||||||
|
NSItem linkedList = __NULL__;
|
||||||
|
NSItem lastItem = __NULL__;
|
||||||
|
|
||||||
|
/* we do not have an item yet. */
|
||||||
|
if (!m_itemList) {
|
||||||
|
m_itemList = (NSItem)Entity_CreateClass(itemName);
|
||||||
|
return (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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 == itemName) {
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
|
|
||||||
|
lastItem = linkedList;
|
||||||
|
linkedList = linkedList.chain;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* add it to the back of the chain, so it's part of our inventory. */
|
||||||
|
if (lastItem && linkedList == __NULL__) {
|
||||||
|
NSItem newItem = (NSItem)Entity_CreateClass(itemName);
|
||||||
|
lastItem.chain = newItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (true);
|
||||||
|
#else
|
||||||
return (false);
|
return (false);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
NSNavAI::RemoveItem(string itemName)
|
NSNavAI::RemoveItem(string itemName)
|
||||||
|
{
|
||||||
|
#ifdef SERVER
|
||||||
|
NSItem linkedList = __NULL__;
|
||||||
|
NSItem frontItem = __NULL__;
|
||||||
|
NSItem lastItem = __NULL__;
|
||||||
|
NSItem itemToRemove = __NULL__;
|
||||||
|
bool removeItem = false;
|
||||||
|
|
||||||
|
/* we posess nothing. auto return false. */
|
||||||
|
if (!m_itemList) {
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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) {
|
||||||
|
/* found the item, mark as needing to be removed */
|
||||||
|
if (linkedList.classname == itemName) {
|
||||||
|
removeItem = true;
|
||||||
|
frontItem = lastItem; /* the one before the current one */
|
||||||
|
itemToRemove = linkedList; /* the item to destroy */
|
||||||
|
}
|
||||||
|
|
||||||
|
lastItem = linkedList;
|
||||||
|
linkedList = linkedList.chain;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* successfully remove the last item */
|
||||||
|
if (removeItem == true) {
|
||||||
|
/* we had an item in front, bridge across the removed item. */
|
||||||
|
if (frontItem) {
|
||||||
|
frontItem.chain = itemToRemove.chain;
|
||||||
|
} else {
|
||||||
|
/* this was the first item. set to chain (can be NULL) */
|
||||||
|
m_itemList = itemToRemove.chain;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemToRemove.Destroy();
|
||||||
|
return (true);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
NSNavAI::AddItem(NSItem theItem)
|
||||||
{
|
{
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,13 +94,13 @@ string __fullspawndata;
|
||||||
#include "NSPhysicsEntity.h"
|
#include "NSPhysicsEntity.h"
|
||||||
#include "NSBrushTrigger.h"
|
#include "NSBrushTrigger.h"
|
||||||
#include "NSPointTrigger.h"
|
#include "NSPointTrigger.h"
|
||||||
|
#include "NSItem.h"
|
||||||
#include "NSNavAI.h"
|
#include "NSNavAI.h"
|
||||||
#include "NSMonster.h"
|
#include "NSMonster.h"
|
||||||
#include "NSSquadMonster.h"
|
#include "NSSquadMonster.h"
|
||||||
#include "NSTalkMonster.h"
|
#include "NSTalkMonster.h"
|
||||||
#include "NSSpawnPoint.h"
|
#include "NSSpawnPoint.h"
|
||||||
#include "NSProjectile.h"
|
#include "NSProjectile.h"
|
||||||
#include "NSItem.h"
|
|
||||||
#include "NSSpraylogo.h"
|
#include "NSSpraylogo.h"
|
||||||
#include "NSPortal.h"
|
#include "NSPortal.h"
|
||||||
#include "NSDebris.h"
|
#include "NSDebris.h"
|
||||||
|
|
Loading…
Reference in a new issue