More work on stackables.

This commit is contained in:
Martin Haye 2017-08-30 08:50:28 -07:00
parent dbc94d707c
commit ddbeebd9b0
3 changed files with 48 additions and 23 deletions

View File

@ -2767,12 +2767,23 @@ end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Add to a list if named obj not already in it; returns TRUE if really added.
// Also handles incrementing stackable items.
export def addUnique(pList, p_thing)#1
if !scanForNamedObj(*pList, p_thing=>s_name)
addToList(pList, p_thing)
return TRUE
word p_existing
// If it's stackable and player already has some, just increase the stack
p_existing = scanForNamedObj(*pList, p_thing=>s_name)
if p_existing
if p_existing->t_type == TYPE_FANCY_ITEM and p_existing=>w_count > 0
p_existing=>w_count++
return TRUE
fin
return FALSE // already have one, and it's not stackable
fin
return FALSE
// Otherwise, add a new item
addToList(pList, p_thing)
return TRUE
end
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -2886,7 +2897,12 @@ export def removeNamed(name, pList)#0
word p_thing
p_thing = scanForNamedObj(*pList, name)
if p_thing
removeFromList(pList, p_thing)
// If it's stackable and there's more than one, just reduce the count. Otherwise take it all.
if p_thing->t_type == TYPE_FANCY_ITEM and p_thing=>w_count > 1
p_thing=>w_count--
else
removeFromList(pList, p_thing)
fin
else
printf1("Warning: couldn't find '%s' to remove.\n", name)
fin

View File

@ -406,21 +406,32 @@ end
// Select an item and use it. Returns item if it needs to be processed by outer loop, else NULL
def doUse(player, item)#1
if item=>p_modifiers
if streqi(item=>p_modifiers=>s_name, @S_HEALTH)
clearMenuRect()
clearMainRect()
rawDisplayStr("^V000\n^J^J^J")
if player=>w_health < player=>w_maxHealth
player=>w_health = min(player=>w_health + item=>p_modifiers=>w_modValue, player=>w_maxHealth)
removeFromList(@player=>p_items, item)
rawDisplayf2("Healed to %d/%d", player=>w_health, player=>w_maxHealth)
word pMod, oldVal, newVal
if item->t_type == TYPE_FANCY_ITEM and item=>p_modifiers
clearMenuRect()
clearMainRect()
rawDisplayStr("^V000\n^J^J^J")
pMod = item=>p_modifiers
while pMod
oldVal = getStat(player, pMod=>s_name)
setStat(player, pMod=>s_name, oldVal + pMod=>w_modValue)
newVal = getStat(player, pMod=>s_name)
rawDisplayStr(pMod=>s_name)
if newVal <> oldVal
takeItemFromPlayer(player, item=>s_name) // also handles reducing count of stackables
if newVal > oldVal
rawDisplayStr(" increased")
else
rawDisplayStr(" decreased")
fin
rawDisplayf2(" from %d to %d.", oldVal, newVal)
else
rawDisplayStr("No healing needed.")
rawDisplayStr(" already at the limit.")
fin
pause(800)
return NULL
fin
pMod = pMod=>p_nextObj
loop
return NULL
fin
return item // general 'use' handled by outer engine, because it might involve graphics
end
@ -878,11 +889,9 @@ end
// For countable "stuff" (e.g. ammo), display the count and appropriate singular or plural name.
def _displayItemName(pItem)#1
isPlural = FALSE
if pItem->t_type == TYPE_FANCY_ITEM
if pItem=>w_count > 0
isPlural = pItem=>w_count > 1
rawDisplayf1("%d ", pItem=>w_count)
fin
if pItem->t_type == TYPE_FANCY_ITEM and pItem=>w_count > 0
isPlural = pItem=>w_count > 1
rawDisplayf1("%d ", pItem=>w_count)
fin
buildString(@addToString)
printf1("%s", pItem=>s_name) // need proper plural processing

View File

@ -185,7 +185,7 @@ def browseItem(num)#0
matchEquipped(pItem, compSkip) // to set pMatchPlayer
pComp = scanForNamedObj(pMatchPlayer=>p_items, pItem=>s_name)
if pComp
if pItem->t_type == TYPE_FANCY_ITEM
if pItem->t_type == TYPE_FANCY_ITEM and pItem=>w_count > 0
pComp=>w_count = min(30000, pComp=>w_count + pItem=>w_count)
else
rawDisplayStr("\nDuplicate item.")