Filter selection based on command

This commit is contained in:
David Schmenk 2016-07-14 22:24:09 -07:00
parent 3ec8b61811
commit 9f3e880c37
3 changed files with 89 additions and 58 deletions

View File

@ -192,7 +192,7 @@ def playerCombatChoose(pl)
pWeapon = NULL
p = pl=>p_items
while p
if p->t_type == TYPE_WEAPON
if p->t_type == TYPE_WEAPON and p->b_flags & ITEM_FLAG_EQUIP
if !pWeapon; pWeapon = p; fin
nWeapons = nWeapons + 1
fin

View File

@ -1182,7 +1182,7 @@ def displayPlayerData(player)
fin
pi = pi=>p_nextObj
loop
if pi
if pi and pi->b_clipSize
rightJustifyNum(pi->b_clipCurrent, CHAR_WND_AMMO_X)
else
rightJustifyStr("---", CHAR_WND_AMMO_X)
@ -1287,7 +1287,7 @@ def initMap(x, y, dir)
if global->b_curAvatar <> 0 and !mapIs3D
setAvatar(global->b_curAvatar)
doRender()
fin
fin
// Display the party characters
showParty()

View File

@ -21,9 +21,13 @@ include "globalDefs.plh"
// Definition of constants for functions exported by this module
include "party.plh"
// Number of items that fit in inventory pane
const INV_PAGE_NUM = 11
// Type groups
const TYPE_ALL = $0100
const TYPE_EQUIP = $0101
const TYPE_USE = $0102
const TYPE_DROP = $0103
// Tab positions
const CHAR_WND_STAT_X = 20
const CHAR_WND_INV_X = 16
@ -41,16 +45,39 @@ byte[] strYouSure = "\n^YAre you sure (Y/N)?^Y"
// Other global variables here
///////////////////////////////////////////////////////////////////////////////////////////////////
// Match item type to group type
def itemMatch(item, group)
byte type
type = item->t_type
when group
is TYPE_ALL
return TRUE
break
is TYPE_EQUIP
return type == TYPE_ARMOR or type == TYPE_WEAPON
is TYPE_USE
return type == TYPE_ITEM and item=>p_modifiers
break
is TYPE_DROP
return type == TYPE_WEAPON or type == TYPE_ARMOR
break
otherwise
return group == type
wend
end
// Search item num
def itemNum(player, num)
def itemNum(player, num, select)
word item
item = player=>p_items
while item and num
while item
if itemMatch(item, select)
if not num; return item; fin
num--
fin
item = item=>p_nextObj
num--
loop
return item
end
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -62,9 +89,9 @@ def unequip(player, type, kind)
item = player=>p_items
while item
if item->t_type == type
if streqi(item=>s_itemKind, kind)
if streqi(item=>s_itemKind, kind) and item->b_flags & ITEM_FLAG_EQUIP
item->b_flags = item->b_flags & ~ITEM_FLAG_EQUIP
return
return item
fin
fin
item = item=>p_nextObj
@ -74,14 +101,15 @@ end
// Display inventory pane
def showInventory(player, page, height, select)
word item
byte n_item, n_page
byte s_item, n_item, n_page
setMapWindow()
clearWindow()
rawDisplayStr("^Y^LInventory^L^N")
rawDisplayStr("^Y^LInventory^L^Y")
rawDisplayStr("\n^T018")
displayf1("Group Gold: %d", countGold())
item = player=>p_items
s_item = 0
n_item = 0
n_page = page * height
if page
@ -91,15 +119,13 @@ def showInventory(player, page, height, select)
loop
fin
while item and n_item < (n_page + height)
if select
displayf2("\n%c) %s", 'A' + n_item, item=>s_name)
else
rawDisplayStr("\n^T018")
displayf1("%s", item=>s_name)
displayChar('\n')
if itemMatch(item, select)
displayf1("%c)", 'A' + s_item)
s_item++
fin
//if item=>s_itemKind
// displayf1(" (%s)", item=>s_itemKind)
//fin
rawDisplayStr("^T018")
displayStr(item=>s_name)
when item->t_type
is TYPE_WEAPON
if item->b_flags & ITEM_FLAG_EQUIP
@ -112,13 +138,14 @@ def showInventory(player, page, height, select)
fin
break
wend
item = item=>p_nextObj
n_item++
item = item=>p_nextObj
loop
while n_item < (n_page + height)
displayChar('\n')
n_item++
loop
return s_item
end
// Display skill value
def displaySkill(str, val, col)
@ -178,7 +205,7 @@ def showPlayerSheet(num, mapHeight)
col++
loop
// Next, show inventory in the main panel
showInventory(player, 0, mapHeight, FALSE)
showInventory(player, 0, mapHeight, 0)
rawDisplayStr("\n^YE)quip, U)se, D)rop^Y")
return player
end
@ -205,26 +232,25 @@ def _party_doPlayerSheet(num)
is '3'; num = 2; n_page = 0; break
// Equip player with weapon/armor
is 'E'
showInventory(player, n_page, vInv, TRUE)
rawDisplayStr(@strWhichItem)
item = itemNum(player, getUpperKey() - 'A')
if item
if item->t_type == TYPE_WEAPON and item->b_flags & ITEM_FLAG_EQUIP
item->b_flags = item->b_flags & ~ITEM_FLAG_EQUIP
elsif item->t_type == TYPE_WEAPON or item->t_type == TYPE_ARMOR
unequip(player, item->t_type, item=>s_itemKind)
item->b_flags = item->b_flags | ITEM_FLAG_EQUIP
calcPlayerArmor(player)
if showInventory(player, n_page, vInv, TYPE_EQUIP)
rawDisplayStr(@strWhichItem)
item = itemNum(player, getUpperKey() - 'A', TYPE_EQUIP)
if item
if unequip(player, item->t_type, item=>s_itemKind) <> item
item->b_flags = item->b_flags | ITEM_FLAG_EQUIP
calcPlayerArmor(player)
fin
fin
else
beep
fin
break
// Use an item
is 'U'
showInventory(player, n_page, vInv, TRUE)
rawDisplayStr(@strWhichItem)
item = itemNum(player, getUpperKey() - 'A')
if item
if item->t_type == TYPE_ITEM and item=>p_modifiers
if showInventory(player, n_page, vInv, TYPE_USE)
rawDisplayStr(@strWhichItem)
item = itemNum(player, getUpperKey() - 'A', TYPE_USE)
if item
if streqi(item=>p_modifiers=>s_name, "health")
if player=>w_health < player=>w_maxHealth
player=>w_health = min(player=>w_health + item=>p_modifiers=>w_modValue, player=>w_maxHealth)
@ -235,35 +261,40 @@ def _party_doPlayerSheet(num)
fin
fin
fin
else
beep
fin
break
// Drop an item
is 'D'
showInventory(player, n_page, vInv, TRUE)
rawDisplayStr(@strWhichItem)
n_item = getUpperKey() - 'A'
item = itemNum(player, n_item)
if item
clearWindow()
rawDisplayStr("^Y^LDrop^L^Y")
for i = 0 to n_item
rawDisplayStr("\n")
next
rawDisplayStr("\n^T018")
displayf1("%s", item=>s_name)
for i = n_item + 2 to vInv
rawDisplayStr("\n")
next
rawDisplayStr(@strYouSure)
if getYN()
removeFromList(@player=>p_items, item)
calcPlayerArmor(player)
if showInventory(player, n_page, vInv, TYPE_DROP)
rawDisplayStr(@strWhichItem)
n_item = getUpperKey() - 'A'
item = itemNum(player, n_item, TYPE_DROP)
if item
clearWindow()
rawDisplayStr("^Y^LDrop^L^Y")
for i = 0 to n_item
displayChar('\n')
next
rawDisplayStr("\n^T018")
displayStr(item=>s_name)
for i = n_item + 2 to vInv
displayChar('\n')
next
rawDisplayStr(@strYouSure)
if getYN()
removeFromList(@player=>p_items, item)
calcPlayerArmor(player)
fin
fin
else
beep
fin
break
// Next inventory page
is '>'
if itemNum(player, n_page * INV_PAGE_NUM + INV_PAGE_NUM)
if itemNum(player, n_page * vInv + vInv, TYPE_ALL)
n_page++
fin
break