Add gold to global state and collect loot after combat.

This commit is contained in:
David Schmenk 2016-07-04 09:31:33 -07:00
parent 9dd02c2236
commit 287ecc6702
5 changed files with 55 additions and 2 deletions

View File

@ -426,6 +426,23 @@ def makeRandomGroup(mapCode)
mmgr(FREE_MEMORY, enemiesModule)
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def collectLoot()
word group, enemies, gold
gold = 0
group = global=>p_enemyGroups
while group
enemies = group=>p_enemies
while enemies
gold = gold + rollDice(enemies=>r_goldLoot)
enemies = enemies=>p_nextObj
loop
group = group=>p_nextObj
loop
return gold
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def startCombat(mapCode)
word p, p2, n, s
@ -507,7 +524,7 @@ end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Returns: zero if fled, non-zero if won
def _combat_zoneEncounter(s_encZone)
word p
word p, l
byte answer
// Show portrait and threat details, find out if player wants to fight (vs. run)
@ -556,6 +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()))
getUpperKey()
// Note: no need to clear heap -- the caller does that.
return 1

View File

@ -22,5 +22,6 @@ import gamelib
predef encodeDice, rollDice, setPlural, getStringResponse
predef streqi, fatal, pause, tossStrings
predef addEncounterZone, showMapName, setMapWindow, makeModifier
predef addGold, countGold, payGold
predef calcPlayerArmor, diskActivity, rdkey, initHeap, scriptCombat
end

View File

@ -26,6 +26,9 @@ const ANIM_FLAG_RANDOM = $80
const ANIM_PAUSE_MAX = 300
// Max gold
const GOLD_MAX = 20000
include "globalDefs.plh"
include "playtype.plh"
include "gen_images.plh"
@ -2168,6 +2171,31 @@ export def calcPlayerArmor(player)
loop
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Add gold
export def addGold(amount)
if global=>w_gold + amount > GOLD_MAX
amount = GOLD_MAX - global=>w_gold
fin
if amount
global=>w_gold = global=>w_gold + amount
fin
return amount
end
// How much gold?
export def countGold()
return global=>w_gold
end
// Pay out gold
export def payGold(amount)
if amount > global=>w_gold
return -1
fin
global=>w_gold = global=>w_gold - amount
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def startGame()
word p_module

View File

@ -49,6 +49,7 @@ def showPlayerSheet(num)
setMapWindow()
clearWindow()
rawDisplayStr("^Y^LInventory^L^N")
displayf1("\nGold: %d", countGold())
item = player=>p_items
while item
displayStr("\n")
@ -94,6 +95,7 @@ def _party_doPlayerSheet(num)
is '2'; num = 1; break
is '3'; num = 2; break
// Other operations...
is '!'; player=>w_health++; break
// All done
otherwise return
wend

View File

@ -26,6 +26,9 @@ struc Global
word w_mapY
byte b_mapDir
// Shared player gold amount
word w_gold
// Heap size for restoring saved game
word w_heapSize
end
@ -40,7 +43,7 @@ struc Player
byte b_combatOrder
word p_combatNext
word w_health
// Innate attributes
byte b_intelligence
byte b_strength