Inventory equip/use/drop

This commit is contained in:
David Schmenk 2016-07-12 08:09:55 -07:00
parent d7e4c85e10
commit 71b4900375
5 changed files with 171 additions and 64 deletions

View File

@ -1,10 +1,10 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 The 8-Bit Bunch. Licensed under the Apache License, Version 1.1
// Copyright (C) 2015 The 8-Bit Bunch. Licensed under the Apache License, Version 1.1
// (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at <http://www.apache.org/licenses/LICENSE-1.1>.
// Unless required by applicable law or agreed to in writing, software distributed under
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
// ANY KIND, either express or implied. See the License for the specific language
// Unless required by applicable law or agreed to in writing, software distributed under
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
// ANY KIND, either express or implied. See the License for the specific language
// governing permissions and limitations under the License.
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -34,7 +34,7 @@ end
def chooseEnemy(maxDist)
word p
byte n
// TODO: Consider distance of enemies
n = rand16() % nEnemiesFighting
p = global=>p_combatFirst
@ -399,7 +399,7 @@ def makeEnemyGroup(enemyFunc)
p->b_enemyGroupRange = max(1, rand16() % (enem->b_enemyAttackRange))
if enem=>r_groupSize == 0 // handle unique enemies
groupSize = 1
else
else
groupSize = rollDice(enem=>r_groupSize)
fin
addToList(p + p_enemies, enem)
@ -429,7 +429,7 @@ end
///////////////////////////////////////////////////////////////////////////////////////////////////
def collectLoot()
word group, enemies, gold
gold = 0
group = global=>p_enemyGroups
while group
@ -573,8 +573,8 @@ def _combat_zoneEncounter(s_encZone)
otherwise
displayStr("\nLooks like you live to fight another day!\n"); break
wend
// Grab the loot
displayf1("And find %d gold pieces!", addGold(collectLoot()))
// Grab the loot
displayf1("And find %d gold pieces!", addGold(collectLoot()))
getUpperKey()
// Note: no need to clear heap -- the caller does that.
return 1
@ -608,4 +608,4 @@ end
global = getGlobals()
return @funcTbl
done
done

View File

@ -1,10 +1,10 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2016 The 8-Bit Bunch. Licensed under the Apache License, Version 1.1
// Copyright (C) 2016 The 8-Bit Bunch. Licensed under the Apache License, Version 1.1
// (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at <http://www.apache.org/licenses/LICENSE-1.1>.
// Unless required by applicable law or agreed to in writing, software distributed under
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
// ANY KIND, either express or implied. See the License for the specific language
// Unless required by applicable law or agreed to in writing, software distributed under
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
// ANY KIND, either express or implied. See the License for the specific language
// governing permissions and limitations under the License.
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -15,8 +15,9 @@ import gamelib
predef setSky, setGround, queue_teleport, setPortrait, clearPortrait, moveWayBackward
predef getUpperKey, clearWindow, getGlobals, rand16, printf1, printf2, printf3
predef displayf1, displayf2, displayf3, buildString, addToString, finishString
predef rawDisplayStr, displayStr, puts
predef min, max, countList, countListFiltered, randomFromListFiltered, randomFromArray, addToList
predef displayChar, rawDisplayStr, displayStr, rightJustifyStr, rightJustifyNum, puts
predef min, max, randomFromListFiltered, randomFromArray
predef countList, countListFiltered, addToList, removeFromList
predef beep, showParty, mmgr, setWindow1, setWindow2, setWindow3, reboot, brk
predef encodeDice, rollDice, setPlural, getStringResponse
predef streqi, fatal, pause, tossStrings

View File

@ -1,10 +1,10 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 The 8-Bit Bunch. Licensed under the Apache License, Version 1.1
// Copyright (C) 2015 The 8-Bit Bunch. Licensed under the Apache License, Version 1.1
// (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at <http://www.apache.org/licenses/LICENSE-1.1>.
// Unless required by applicable law or agreed to in writing, software distributed under
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
// ANY KIND, either express or implied. See the License for the specific language
// Unless required by applicable law or agreed to in writing, software distributed under
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
// ANY KIND, either express or implied. See the License for the specific language
// governing permissions and limitations under the License.
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -243,7 +243,7 @@ asm readAuxByte // params: ptr; ret: char
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// String building for display with the font engine. Includes plurality processing to handily
// String building for display with the font engine. Includes plurality processing to handily
// handle things like "Dirt bag(s)" and "his/their"
export asm buildString
+asmPlasm 1
@ -744,7 +744,7 @@ end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Display a character using the font engine.
// Params: ch
asm displayChar
export asm displayChar
+asmPlasm_bank2 1
jmp DisplayChar
end
@ -801,13 +801,13 @@ export asm rand16
lda seed
beq .lowZero ; $0000 and $8000 are special values to test for
; Do a normal shift
asl seed
lda seed+1
rol
bcc .noEor
.doEor:
; high byte is in A
eor #>magic
@ -817,18 +817,18 @@ export asm rand16
eor #<magic
sta seed
rts
.lowZero:
lda seed+1
beq .doEor ; High byte is also zero, so apply the EOR
; For speed, you could store 'magic' into 'seed' directly
; instead of running the EORs
; wasn't zero, check for $8000
asl
beq .noEor ; if $00 is left after the shift, then it was $80
bcs .doEor ; else, do the EOR based on the carry bit as usual
.noEor:
sta seed+1
tay ; for asmPlasm, return hi byte in Y, lo byte in A
@ -1129,7 +1129,7 @@ export def setMapWindow()
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def rightJustifyStr(str, rightX)
export def rightJustifyStr(str, rightX)
word x
x = rightX - calcWidth(str)
tabBuf[0] = 4 // length
@ -1142,7 +1142,7 @@ def rightJustifyStr(str, rightX)
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def rightJustifyNum(num, rightX)
export def rightJustifyNum(num, rightX)
rightJustifyStr(convertDec(num), rightX)
end
@ -1162,7 +1162,7 @@ def displayPlayerData(player)
fin
rightJustifyNum(player=>w_health, CHAR_WND_LIFE_X)
// All done.
rawDisplayStr("\n")
end
@ -1485,14 +1485,14 @@ def setMap(is3D, num, x, y, dir)
flipToPage1()
mmgr(FINISH_LOAD, WITH_CLOSE)
showMapName("Traveling...")
setMapWindow(); clearWindow()
setMapWindow(); clearWindow()
setWindow2(); clearWindow()
mapIs3D = is3D
mapNum = num
initMap(x, y, dir)
fin
// Don't check scripts, because we often land on an "Exit to wilderness?" script
//NO:checkScripts()
//NO:checkScripts()
end
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -1500,7 +1500,7 @@ def kbdTeleport()
byte d3, num
word x, y
byte dir
flipToPage1()
^$c053
if ^$25 < 23; ^$25 = 23; fin
@ -1529,7 +1529,7 @@ end
def showPos()
word x, y
byte dir
flipToPage1()
^$c053
if ^$25 < 23; ^$25 = 23; fin
@ -1877,7 +1877,7 @@ end
def restoreMapPos()
mapIs3D = global->b_mapIs3D
mapNum = global->b_mapNum
initMap(global=>w_mapX, global=>w_mapY, global->b_mapDir)
initMap(global=>w_mapX, global=>w_mapY, global->b_mapDir)
end
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -2209,7 +2209,7 @@ export def calcPlayerArmor(player)
player->b_armor = 0
pItem = player=>p_items
while pItem
if pItem->t_type == TYPE_ARMOR
if pItem->t_type == TYPE_ARMOR and pItem->b_flags & ITEM_FLAG_EQUIP
player->b_armor = player->b_armor + pItem->b_armorValue
fin
pItem = pItem=>p_nextObj
@ -2252,7 +2252,7 @@ end
///////////////////////////////////////////////////////////////////////////////////////////////////
export def giveItemToPlayer(itemFunc)
word p_module, funcTbl, func, p_item
// Load the module that is capable of creating items
mmgr(START_LOAD, 1) // code is in partition 1
p_module = mmgr(QUEUE_LOAD, MODULE_GEN_ITEMS<<8 | RES_TYPE_MODULE)
@ -2394,4 +2394,4 @@ loadTitle()
startGame()
kbdLoop()
done
done

View File

@ -18,6 +18,9 @@ include "playtype.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 = 13
// This pointer is the root of all heap-tracked (and garbage collected) objects.
// See playtype.plh for definitions of all the datastructures and how they interconnect.
word global
@ -30,9 +33,76 @@ word[] funcTbl = @_party_doPlayerSheet
// Other global variables here
///////////////////////////////////////////////////////////////////////////////////////////////////
// Search item num
def itemNum(player, num)
word item
item = player=>p_items
while item and num
item = item=>p_nextObj
num--
loop
return item
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Unequip item kind
def unequip(player, type, kind)
word item
item = player=>p_items
while item
if item->t_type == type and item=>s_itemKind == kind
item->b_flags = item->b_flags & ~ITEM_FLAG_EQUIP
return
fin
item = item=>p_nextObj
loop
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Display inventory pane
def showInventory(player, page)
word item
byte n_item, n_page
setMapWindow()
clearWindow()
rawDisplayStr("^Y^LInventory^L^N")
displayf1("\nGroup Gold: %d", countGold())
item = player=>p_items
n_item = 0
n_page = page * INV_PAGE_NUM
if page
while item and n_item < n_page
item = item=>p_nextObj
n_item++
loop
fin
while item and n_item < (n_page + INV_PAGE_NUM)
displayf2("\n%c) %s", 'A' + n_item, item=>s_name)
when item->t_type
is TYPE_WEAPON
if item->b_flags & ITEM_FLAG_EQUIP
displayChar('+')
fin
break
is TYPE_ARMOR
if item->b_flags & ITEM_FLAG_EQUIP
displayChar('+')
fin
break
wend
item = item=>p_nextObj
n_item++
loop
while n_item < (n_page + INV_PAGE_NUM)
displayChar('\n')
n_item++
loop
end
// Show player data
def showPlayerSheet(num)
word player, item
word player
// Count the number of players
player = global=>p_players
@ -45,18 +115,6 @@ def showPlayerSheet(num)
// First, display the player's name in the title bar
showMapName(player=>s_name)
// Next, show inventory in the main panel
setMapWindow()
clearWindow()
rawDisplayStr("^Y^LInventory^L^N")
displayf1("\nGroup Gold: %d", countGold())
item = player=>p_items
while item
displayStr("\n")
displayStr(item=>s_name)
item = item=>p_nextObj
loop
// Show stats in the right panel
setWindow2()
clearWindow()
@ -70,7 +128,7 @@ def showPlayerSheet(num)
displayf1("%d", player->b_spirit); rawDisplayStr("^T024Spirit\n")
displayf1("%d", player->b_luck); rawDisplayStr("^T024Luck\n")
displayf1("%d", player->b_armor); rawDisplayStr("^T024Armor\n")
// Show aquired skills in lower right panel
setWindow3()
clearWindow()
@ -78,22 +136,67 @@ def showPlayerSheet(num)
if player->b_aiming; displayStr("\nAiming"); fin
if player->b_handToHand; displayStr("\nHand-to-Hand"); fin
if player->b_dodging; displayStr("\nDodging"); fin
// Next, show inventory in the main panel
showInventory(player, 0)
rawDisplayStr("\n^YE)quip, U)se, D)rop^Y")
return player
end
// Show player sheet and accept command
def _party_doPlayerSheet(num)
word player
word player, item
byte n_item, n_page
n_page = 0
repeat
player = showPlayerSheet(num)
if !player; return; fin // Invalid player
// Get a key, do something
when getUpperKey()
// Select another player to show
is '1'; num = 0; break
is '2'; num = 1; break
is '3'; num = 2; break
is '1'; num = 0; n_page = 0; break
is '2'; num = 1; n_page = 0; break
is '3'; num = 2; n_page = 0; break
// Equip player with weapon/armor
is 'E'
showInventory(player, n_page)
rawDisplayStr("\n^YWhich item?^Y")
item = itemNum(player, getUpperKey() - 'A')
if item
if 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)
fin
fin
break
// Use an item
is 'U'
break
// Drop an item
is 'D'
showInventory(player, n_page)
rawDisplayStr("\n^YWhich item?^Y")
item = itemNum(player, getUpperKey() - 'A')
if item
removeFromList(@player=>p_items, item)
calcPlayerArmor(player)
fin
break
// Next inventory page
is '>'
if itemNum(player, n_page * INV_PAGE_NUM + INV_PAGE_NUM)
n_page++
fin
break
// Previous inventory page
is '<'
if n_page
n_page--
fin
break
// Other operations...
is '!'; player=>w_health = player=>w_health + 10; break
is '$'; addGold(10); break

View File

@ -1,10 +1,10 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 The 8-Bit Bunch. Licensed under the Apache License, Version 1.1
// Copyright (C) 2015 The 8-Bit Bunch. Licensed under the Apache License, Version 1.1
// (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at <http://www.apache.org/licenses/LICENSE-1.1>.
// Unless required by applicable law or agreed to in writing, software distributed under
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
// ANY KIND, either express or implied. See the License for the specific language
// Unless required by applicable law or agreed to in writing, software distributed under
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
// ANY KIND, either express or implied. See the License for the specific language
// governing permissions and limitations under the License.
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -26,7 +26,7 @@ struc Global
word w_mapY
byte b_mapDir
word w_mapScript
// Shared player gold amount
word w_gold
@ -47,7 +47,7 @@ struc Player
byte b_combatOrder
word p_combatNext
word w_health
// Innate attributes
byte b_intelligence
byte b_strength
@ -108,6 +108,8 @@ struc Item
byte b_curUses
end
const ITEM_FLAG_EQUIP = $80 // only one weapon/armor equipped (in use) at a time
const WEAPON_FLAG_SINGLE_USE = $01
const WEAPON_FLAG_WHOLE_GROUP = $02
@ -124,7 +126,7 @@ struc Weapon
byte b_maxUses
byte b_curUses
// Weapon properties
byte b_weaponFlags // WEAPON_FLAG_* above
byte b_flags // WEAPON_FLAG_* above
word s_ammoKind
byte b_clipSize
byte b_clipCurrent
@ -148,6 +150,7 @@ struc Armor
byte b_maxUses
byte b_curUses
// Armor properties
byte b_flags // ARMOR_FLAG_* above
byte b_armorValue
end