mirror of
https://github.com/badvision/lawless-legends.git
synced 2025-02-20 21:29:13 +00:00
More progress on store buying.
This commit is contained in:
parent
121753c45d
commit
35c5ee97ef
@ -30,7 +30,8 @@ import gamelib
|
||||
predef addPlayerToParty, removePlayerFromParty, partyHasPlayer, loadFrameImg, loadMainFrameImg
|
||||
predef scriptSwapTile, setIntimateMode, fontCmd, setIntimateMode
|
||||
predef callGlobalFunc, getCharResponse, memcpy, checkEncounter, finalWin, addUnique
|
||||
predef benchPlayer, unbenchPlayer, buyFromStore, sellToStore, setOversizeWindow, convertDec
|
||||
predef benchPlayer, unbenchPlayer, buyFromStore, sellToStore, setOversizeWindow
|
||||
predef rawDisplayf1, rawDisplayf2, rawDisplayf3
|
||||
|
||||
// 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.
|
||||
|
@ -1010,7 +1010,7 @@ end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Convert signed decimal to string in decimalBuf (@decimalBuf returned)
|
||||
export def convertDec(n)
|
||||
def convertDec(n)
|
||||
word n0
|
||||
word p
|
||||
p = @decimalBuf + 1
|
||||
@ -1071,6 +1071,16 @@ end
|
||||
export def displayf1(str, arg1); displayf3(str, arg1, 0, 0); end
|
||||
export def displayf2(str, arg1, arg2); displayf3(str, arg1, arg2, 0); end
|
||||
|
||||
// Like printf, but displays text using font engine
|
||||
export def rawDisplayf3(str, arg1, arg2, arg3)
|
||||
buildString(@addToString)
|
||||
printf3(str, arg1, arg2, arg3)
|
||||
rawDisplayStr(finishString(isPlural))
|
||||
end
|
||||
|
||||
export def rawDisplayf1(str, arg1); rawDisplayf3(str, arg1, 0, 0); end
|
||||
export def rawDisplayf2(str, arg1, arg2); rawDisplayf3(str, arg1, arg2, 0); end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
def parseDec(str)
|
||||
word n
|
||||
|
@ -14,7 +14,7 @@ include "globalDefs.plh"
|
||||
include "gen_modules.plh"
|
||||
include "gen_items.plh"
|
||||
|
||||
const PAGE_SIZE = 19
|
||||
const PAGE_SIZE = 13
|
||||
|
||||
// Exported functions go here. First a predef for each one, then a table with function pointers
|
||||
// in the same order as the constants are defined in the header.
|
||||
@ -26,8 +26,6 @@ const MAX_PAGE_ITEMS = 20 // should be plenty
|
||||
word pageItems[MAX_PAGE_ITEMS]
|
||||
word pagePrices[MAX_PAGE_ITEMS]
|
||||
|
||||
byte selStrBuf[2]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Definitions used by assembly code
|
||||
asm _defs
|
||||
@ -113,63 +111,94 @@ def unloadItems()
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
def displayBuyTitle()
|
||||
rawDisplayStr("^T108Buying\n\n")
|
||||
rawDisplayStr("^LSel^T025Price^T060Item^L")
|
||||
def displayBuyTitle(pageNum, nPages)
|
||||
clearWindow()
|
||||
// Can't use centering mode on oversize window - font engine can't handle width > 255
|
||||
if (nPages > 0)
|
||||
rawDisplayf2("^T073Buying (page %d of %d)", pageNum+1, nPages)
|
||||
else
|
||||
rawDisplayStr("^T108Buying")
|
||||
fin
|
||||
rawDisplayStr("\n\n^LSel^T025Price^T060Item^L")
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
def displayBuyLine(num, name, price)
|
||||
word buf
|
||||
rawDisplayStr("\n")
|
||||
^(@buf) = 1
|
||||
^(@buf + 1) = num + 'A'
|
||||
rawDisplayStr(@buf)
|
||||
rawDisplayStr(".^T025")
|
||||
rawDisplayStr(convertDec(price))
|
||||
rawDisplayStr("^T060")
|
||||
rawDisplayStr(name)
|
||||
def displayBuyLine(num, price, name)
|
||||
rawDisplayf3("\n%c.^T025%d^T060%s", num + 'A', price, name)
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
def displayBuyPage(pItemFunc, markupRatio)
|
||||
def displayBuyPage(pItemTbl, markupRatio, pageNum, nPages)
|
||||
byte itemNum
|
||||
itemNum = 0
|
||||
displayBuyTitle()
|
||||
word pFunc, pItem
|
||||
|
||||
displayBuyTitle(pageNum, nPages)
|
||||
mmgr(HEAP_COLLECT, 0)
|
||||
while itemNum < PAGE_SIZE-5
|
||||
pageItems[itemNum] = (*pItemFunc)()
|
||||
pagePrices[itemNum] = max(1, pageItems[itemNum]=>w_price + calcMarkup(pageItems[itemNum]=>w_price, markupRatio))
|
||||
if pageItems[itemNum]->t_type == TYPE_STUFF // show plural for countable stuff like ammo, pelts
|
||||
setPlural(TRUE)
|
||||
else
|
||||
setPlural(FALSE)
|
||||
fin
|
||||
displayBuyLine(itemNum, pageItems[itemNum]=>s_name, pagePrices[itemNum])
|
||||
itemNum++
|
||||
pItemFunc = pItemFunc + 2
|
||||
if !*pItemFunc; break; fin
|
||||
loop
|
||||
|
||||
pFunc = pItemTbl + ((pageNum*PAGE_SIZE) << 1)
|
||||
for itemNum = 0 to PAGE_SIZE-1
|
||||
if !(*pFunc); break; fin
|
||||
pItem = (*pFunc)()
|
||||
pageItems[itemNum] = pItem
|
||||
pagePrices[itemNum] = max(1, pItem=>w_price + calcMarkup(pItem=>w_price, markupRatio))
|
||||
setPlural(FALSE)
|
||||
if pItem->t_type == TYPE_STUFF; setPlural(TRUE); fin
|
||||
displayBuyLine(itemNum, pagePrices[itemNum], pItem=>s_name)
|
||||
pFunc = pFunc + 2
|
||||
next
|
||||
|
||||
rawDisplayf1("\n\nBrowse item [A-%c], ", itemNum-1+'A')
|
||||
if nPages > 0
|
||||
rawDisplayf1("page [1-%d], ", nPages)
|
||||
fin
|
||||
rawDisplayStr("or [Esc].")
|
||||
return itemNum
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
def countArray(arr)
|
||||
byte count
|
||||
for count = 0 to 127
|
||||
if !*arr; return count; fin
|
||||
arr = arr + 2
|
||||
next
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
def _buyFromStore(storeCode, markupRatio)
|
||||
word pItemTbl, topItem, choice
|
||||
word pItemTbl, choice
|
||||
byte nItemsOnPage, pageNum, nPages, redisplay
|
||||
|
||||
setOversizeWindow()
|
||||
clearWindow()
|
||||
|
||||
loadItems()
|
||||
pItemTbl = pItemsModule()=>items_forStoreCode(storeCode)
|
||||
topItem = pItemTbl
|
||||
|
||||
nPages = (countArray(pItemTbl) + PAGE_SIZE) / PAGE_SIZE
|
||||
pageNum = 0
|
||||
|
||||
redisplay = TRUE
|
||||
while TRUE
|
||||
displayBuyPage(topItem, markupRatio)
|
||||
rawDisplayStr("\n\nSelect item, Return for next pg, Esc to leave")
|
||||
choice = readStr()
|
||||
break
|
||||
if redisplay
|
||||
nItemsOnPage = displayBuyPage(pItemTbl + ((pageNum*PAGE_SIZE)<<1), markupRatio, pageNum, nPages)
|
||||
fin
|
||||
choice = getUpperKey()
|
||||
redisplay = TRUE
|
||||
if choice >= '1' and (choice-'1') < nPages
|
||||
pageNum = choice - '1'
|
||||
elsif choice >= 'A' and (choice-'A' < nItemsOnPage)
|
||||
rawDisplayf1("\nTODO: browse it, maybe buy\n")
|
||||
getUpperKey()
|
||||
elsif choice == $1B // Esc
|
||||
break
|
||||
else
|
||||
beep()
|
||||
redisplay = FALSE
|
||||
fin
|
||||
loop
|
||||
|
||||
unloadItems()
|
||||
mmgr(HEAP_COLLECT, 0)
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
x
Reference in New Issue
Block a user