Fixes for ammo on buy/sell/loot pages. Also, halved store profit so total for buy+sell is 100%.

This commit is contained in:
Martin Haye 2017-07-16 12:34:24 -07:00
parent 729758ab0f
commit 1ecddcf190
6 changed files with 77 additions and 36 deletions

View File

@ -2614,8 +2614,8 @@ end
"${escapeString(parseStringAttr(row, "ammo-kind"))}, " +
"${parseWordAttr(row, "price")}, " +
"${parseWordAttr(row, "max")}, " +
"${parseDiceAttr(row, "loot-amount")}, " +
"${parseDiceAttr(row, "store-amount")})")
"${parseWordAttr(row, "store-amount")}, " +
"${parseDiceAttr(row, "loot-amount")})")
}
def genItem(func, row, out)
@ -2826,14 +2826,14 @@ def makeWeapon_pt2(p, attack0, attack1, attack2, weaponRange, combatText, single
return p
end
def makeStuff(name, kind, price, count, lootAmount, storeAmount)
def makeStuff(name, kind, price, count, storeAmount, lootAmount)
word p; p = mmgr(HEAP_ALLOC, TYPE_STUFF)
p=>s_name = mmgr(HEAP_INTERN, name)
p=>s_itemKind = mmgr(HEAP_INTERN, kind)
p=>w_price = price
p=>w_count = count
p=>w_storeAmount = storeAmount
p=>r_lootAmount = lootAmount
p=>r_storeAmount = storeAmount
return p
end

View File

@ -26,8 +26,9 @@ byte nEnemiesFighting
byte isFleeing
byte combatDebug
byte[] S_AN = "an"
byte[] S_A = "a"
byte[] S_AN = "an "
byte[] S_A = "a "
byte[] S_EMPTY = ""
///////////////////////////////////////////////////////////////////////////////////////////////////
def combatPause()#0
@ -817,15 +818,39 @@ def makeRandomGroup(mapCode)#0
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Determines if string should be prefixed by "an ", "a ", or "". Examples:
// an apple
// a gun
// boots
def anOrA(str)
byte ch
ch = charToUpper(^str)
ch = charToUpper(^(str + ^str))
if ch == 'S'
return @S_EMPTY // assume plural
fin
ch = charToUpper(^(str+1))
if ch == 'A' or ch == 'E' or ch == 'I' or ch == 'O' or ch == 'U'
return @S_AN
fin
return @S_A
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def addItem(pl, pItem)#1
word pComp
pComp = scanForNamedObj(pl=>p_items, pItem=>s_name)
if pComp
if pItem->t_type == TYPE_STUFF
pComp=>w_count = min(30000, pComp=>w_count + pItem=>w_count)
return TRUE
else
return FALSE // duplicate item
fin
fin
addToList(@pl=>p_items, pItem)
return TRUE
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def collectLootAndXP()#2
word group, enemy, gold, xp, pItemsModule, itemFunc, pItem
@ -849,12 +874,14 @@ def collectLootAndXP()#2
if pItem->t_type == TYPE_STUFF
pItem=>w_count = rollDiceWithLuck(pItem=>r_lootAmount, global=>p_players->b_luck)
fin
if pItem->t_type == TYPE_STUFF and pItem=>w_count > 1
setPlural(TRUE)
displayf2("You find %d %s! ", pItem=>w_count, pItem=>s_name)
else
setPlural(FALSE)
displayf2("You find %s %s! ", anOrA(pItem=>s_name), pItem=>s_name)
if addItem(global=>p_players, pItem)
if pItem->t_type == TYPE_STUFF and pItem=>w_count > 1
setPlural(TRUE)
displayf2("You find %d %s! ", pItem=>w_count, pItem=>s_name)
else
setPlural(FALSE)
displayf2("You find %s%s! ", anOrA(pItem=>s_name), pItem=>s_name)
fin
fin
lootedItem = TRUE
fin

View File

@ -634,6 +634,7 @@ export asm puts(str)#0
ldy #0
lda (pTmp),y
tax
beq ++ ; handle empty string
iny
- lda (pTmp),y
+ ora #$80
@ -641,7 +642,7 @@ export asm puts(str)#0
iny
dex
bne -
rts
++ rts
end
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -2279,7 +2280,7 @@ def returnFromEngine(render)#0
curEngine = NULL
loadMainFrameImg()
clearPortrait()
if renderLoaded; texControl(1); fin
if renderLoaded; texControl(1); texturesLoaded = TRUE; fin
mapNameHash = 0; showMapName(global=>s_mapName)
setWindow2(); clearWindow()
if render; doRender(); fin

View File

@ -592,6 +592,7 @@ def _showPlayerSheet(player_num)#1 // funcTbl functions always have to return a
is '$' // add gold cheat
if global->b_godmode
addGold(500)
redisplay = 2
fin
break
is '%' // add item cheat
@ -858,9 +859,12 @@ def _displayItemStats(pItem1, pItem2)#1
wend
// If either item has modifiers, show them
pMod1 = pItem1=>p_modifiers
pMod1 = NULL
if pItem1->t_type <> TYPE_STUFF; pMod1 = pItem1=>p_modifiers; fin
pMod2 = NULL
if pItem2; pMod2 = pItem2=>p_modifiers; fin
if pItem2
if pItem2->t_type <> TYPE_STUFF; pMod2 = pItem2=>p_modifiers; fin
fin
if pMod1 or pMod2
rawDisplayStr("\nSpecial")
while pMod1 or pMod2

View File

@ -177,7 +177,7 @@ struc Stuff
word w_price
// Stuff properties
word w_count
word r_storeAmount
word w_storeAmount
word r_lootAmount
end

View File

@ -89,13 +89,18 @@ def displayBuyPage(pItemTbl, markupRatio, pageNum, nPages)#1
for itemNum = 0 to PAGE_SIZE-1
if !(*pFunc); break; fin
pItem = (*pFunc)()
if pItem->t_type == TYPE_STUFF
pItem=>w_count = pItem=>w_storeAmount
fin
pageItems[itemNum] = pItem
pagePrices[itemNum] = max(1, pItem=>w_price + addRatio(pItem=>w_price, markupRatio))
displayItemLine(itemNum)
pFunc = pFunc + 2
next
rawDisplayf2("\n^V166Gold: %d. Browse [A-%c], ", global=>w_gold, itemNum-1+'A')
rawDisplayf1("\n^V166Gold: %d. Browse [A", global=>w_gold)
if itemNum > 1; rawDisplayf1("-%c", itemNum-1+'A'); fin
rawDisplayStr("], ")
if nPages > 1
rawDisplayf1("p. [1-%d], ", nPages)
fin
@ -177,9 +182,6 @@ def browseItem(num)#0
sel = getUpperKey()
rawDisplayf1(" %c\n", sel)
if sel == 'B' and price <= global=>w_gold
if pItem->t_type == TYPE_STUFF
pItem=>w_count = rollDice(pItem=>r_storeAmount)
fin
matchEquipped(pItem, compSkip) // to set pMatchPlayer
pComp = scanForNamedObj(pMatchPlayer=>p_items, pItem=>s_name)
if pComp
@ -211,7 +213,7 @@ end
///////////////////////////////////////////////////////////////////////////////////////////////////
def _buyFromStore(storeCode, profitPercent)#1
word pItemTbl, choice
word pItemTbl, choice, ratio
byte nItemsOnPage, pageNum, nPages, redisplay
loadExtraModules()
@ -222,10 +224,12 @@ def _buyFromStore(storeCode, profitPercent)#1
nPages = (countArray(pItemTbl) + PAGE_SIZE - 1) / PAGE_SIZE
pageNum = 0
ratio = percentToRatio(profitPercent) / 2 // half of profit on buying, half on selling
redisplay = TRUE
while TRUE
if redisplay
nItemsOnPage = displayBuyPage(pItemTbl, percentToRatio(profitPercent), pageNum, nPages)
nItemsOnPage = displayBuyPage(pItemTbl, ratio, pageNum, nPages)
fin
choice = getUpperKey()
redisplay = TRUE
@ -258,7 +262,7 @@ end
///////////////////////////////////////////////////////////////////////////////////////////////////
def iterateSellables(skipItems, markdownRatio)#1
word pPlayer, pItem, itemsOnPage, totalItems
word pPlayer, pItem, itemsOnPage, totalItems, price
byte ok
itemsOnPage = 0
totalItems = 0
@ -272,10 +276,14 @@ def iterateSellables(skipItems, markdownRatio)#1
elsif pItem->t_type == TYPE_WEAPON or pItem->t_type == TYPE_ARMOR
if pItem->b_flags & ITEM_FLAG_EQUIP; ok = FALSE; fin
fin
if ok
price = max(0, pItem=>w_price - addRatio(pItem=>w_price, markdownRatio))
if !price; ok = FALSE; fin
fin
if ok
if totalItems >= skipItems and itemsOnPage < PAGE_SIZE
pageItems[itemsOnPage] = pItem
pagePrices[itemsOnPage] = max(0, pItem=>w_price - addRatio(pItem=>w_price, markdownRatio))
pagePrices[itemsOnPage] = price
pagePlayers[itemsOnPage] = pPlayer
displayItemLine(itemsOnPage)
itemsOnPage++
@ -295,7 +303,12 @@ def displaySellPage(markdownRatio, pageNum, nPages)#1
word nItems
displaySellTitle(pageNum, nPages)
nItems = iterateSellables(pageNum * PAGE_SIZE, markdownRatio)
rawDisplayf2("\n^V166Gold: %d. Sell [A-%c], ", global=>w_gold, nItems-1+'A')
if !nItems
rawDisplayStr("\n\nNothing to sell here.")
fin
rawDisplayf1("\n^V166Gold: %d. Sell [A", global=>w_gold)
if nItems > 1; rawDisplayf1("-%c", nItems-1+'A'); fin
rawDisplayStr("], ")
if nPages > 1
rawDisplayf1("p. [1-%d], ", nPages)
fin
@ -321,27 +334,22 @@ end
///////////////////////////////////////////////////////////////////////////////////////////////////
def _sellToStore(profitPercent)#1
word pItemTbl, choice
word pItemTbl, choice, ratio
byte nItemsOnPage, pageNum, totalItems, nPages, redisplay
loadExtraModules()
totalItems = iterateSellables(9999, 0)
if totalItems == 0
scriptDisplayStr("\nNothing to sell.\n")
pause(800)
return 0
fin
setBigWindow()
pageNum = 0
ratio = percentToRatio(profitPercent) / 2 // half profit on buying, half on selling
redisplay = TRUE
while totalItems > 0
nPages = (totalItems + PAGE_SIZE - 1) / PAGE_SIZE // recalc each time since totalItems changes
pageNum = min(nPages-1, pageNum)
if redisplay
nItemsOnPage = displaySellPage(percentToRatio(profitPercent), pageNum, nPages)
nItemsOnPage = displaySellPage(ratio, pageNum, nPages)
fin
choice = getUpperKey()
redisplay = TRUE
@ -358,6 +366,7 @@ def _sellToStore(profitPercent)#1
fin
loop
unloadExtraModules()
return mmgr(HEAP_COLLECT, 0)
end