Fleshed out ability to use an item on a map space. In addition, add item god-mode cheat moved to player info screen and made fancier.

This commit is contained in:
Martin Haye 2016-09-24 11:10:17 -07:00
parent 83a26c901b
commit 49d025a44c
5 changed files with 94 additions and 38 deletions

View File

@ -2218,6 +2218,7 @@ end
funcs.each { typeName, func, index, row -> funcs.each { typeName, func, index, row ->
out.println("const ${func} = ${(index+2)*2}") out.println("const ${func} = ${(index+2)*2}")
} }
out.println("const NUM_ITEMS = ${funcs.size()}")
} }
replaceIfDiff("build/src/plasma/gen_items.plh") replaceIfDiff("build/src/plasma/gen_items.plh")
@ -3107,6 +3108,25 @@ end
} }
} }
def packLogicOperation(blk)
{
def op = getSingle(blk.field, "OP").text()
assert blk.value[0].@name == 'A'
assert blk.value[1].@name == 'B'
def val1 = getSingle(blk.value[0].block)
def val2 = getSingle(blk.value[1].block)
switch (op) {
case 'AND':
packExpr(val1); out << " and "; packExpr(val2)
break
case 'OR':
packExpr(val1); out << " or "; packExpr(val2)
break
default:
assert false : "Logic op '$op' not yet implemented."
}
}
def packVarGet(blk) def packVarGet(blk)
{ {
def name = "v_" + humanNameToSymbol(getSingle(blk.field, "VAR").text(), false) def name = "v_" + humanNameToSymbol(getSingle(blk.field, "VAR").text(), false)
@ -3143,6 +3163,9 @@ end
case 'logic_compare': case 'logic_compare':
packLogicCompare(blk) packLogicCompare(blk)
break break
case 'logic_operation':
packLogicOperation(blk)
break
case 'variables_get': case 'variables_get':
packVarGet(blk) packVarGet(blk)
break break

View File

@ -142,15 +142,6 @@ asm mliStub
rts rts
end end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Clear the text-mode screen, and put the cursor there.
// Params: None
asm home
+asmPlasm 0
+safeHome
rts
end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
def callMLI(cmd, p_params) def callMLI(cmd, p_params)
byte err byte err
@ -286,7 +277,7 @@ def _newOrLoadGame(ask)
return 0 return 0
fin fin
home() textHome()
^$c053 ^$c053
^$25 = 20 ^$25 = 20
puts("\n N)ew game, or L)oad last game? ") puts("\n N)ew game, or L)oad last game? ")

View File

@ -13,6 +13,7 @@ import gamelib
//////////// Shared library routines //////////// //////////// Shared library routines ////////////
predef setScriptInfo, scriptDisplayStr, scriptDisplayStrNL, getYN, queue_setMap predef setScriptInfo, scriptDisplayStr, scriptDisplayStrNL, getYN, queue_setMap
predef setSky, setGround, queue_teleport, setPortrait, clearPortrait, moveWayBackward predef setSky, setGround, queue_teleport, setPortrait, clearPortrait, moveWayBackward
predef flipToPage1, textHome
predef getUpperKey, clearWindow, getGlobals, rand16, printf1, printf2, printf3 predef getUpperKey, clearWindow, getGlobals, rand16, printf1, printf2, printf3
predef displayf1, displayf2, displayf3, buildString, addToString, finishString, printHex predef displayf1, displayf2, displayf3, buildString, addToString, finishString, printHex
predef displayChar, rawDisplayStr, displayStr, rightJustifyStr, rightJustifyNum, puts predef displayChar, rawDisplayStr, displayStr, rightJustifyStr, rightJustifyNum, puts
@ -22,10 +23,10 @@ import gamelib
predef encodeDice, rollDice, setPlural, getStringResponse predef encodeDice, rollDice, setPlural, getStringResponse
predef streqi, strncpy, fatal, pause, tossStrings, charToUpper predef streqi, strncpy, fatal, pause, tossStrings, charToUpper
predef addEncounterZone, clearEncounterZones, showMapName, setMapWindow, getMapWindow predef addEncounterZone, clearEncounterZones, showMapName, setMapWindow, getMapWindow
predef addGold, countGold, payGold predef addGold, countGold, payGold, scriptEvent
predef calcPlayerArmor, rdkey, initHeap, scriptCombat, makeModifier predef calcPlayerArmor, rdkey, initHeap, scriptCombat, makeModifier
predef giveItemToPlayer, takeItemFromPlayer, playerHasItem, getStat, setStat predef giveItemToPlayer, takeItemFromPlayer, playerHasItem, getStat, setStat
predef setGameFlag, getGameFlag, scriptSetAvatar predef setGameFlag, getGameFlag, scriptSetAvatar, parseDecWithDefault, readStr
predef addPlayerToParty, removePlayerFromParty, partyHasPlayer predef addPlayerToParty, removePlayerFromParty, partyHasPlayer
/////////// Shared string constants ////////////// /////////// Shared string constants //////////////

View File

@ -37,6 +37,7 @@ include "gen_modules.plh"
include "gen_enemies.plh" include "gen_enemies.plh"
include "gen_players.plh" include "gen_players.plh"
include "gen_globalScripts.plh" include "gen_globalScripts.plh"
include "gen_items.plh"
include "combat.plh" include "combat.plh"
include "party.plh" include "party.plh"
include "diskops.plh" include "diskops.plh"
@ -176,7 +177,7 @@ asm initDisplay // params: mapNum, pMapData, x, y, dir
+asmPlasm 5 +asmPlasm 5
jmp $6000 jmp $6000
end end
asm flipToPage1 // no params export asm flipToPage1 // no params
+asmPlasm 0 +asmPlasm 0
jmp $6003 jmp $6003
end end
@ -591,7 +592,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Read a string from the keyboard, turn it into a PLASMA string and return a pointer to the string. // Read a string from the keyboard, turn it into a PLASMA string and return a pointer to the string.
asm readStr export asm readStr
+asmPlasm 0 +asmPlasm 0
bit setROM bit setROM
jsr ROM_getln1 jsr ROM_getln1
@ -807,6 +808,15 @@ export asm rand16
end end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Clear the text-mode screen, and put the text cursor at the top of it.
// Params: None
export asm textHome
+asmPlasm 0
+safeHome
rts
end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// General methods // General methods
@ -966,7 +976,7 @@ def parseDec(str)
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
def parseDecWithDefault(str, default) export def parseDecWithDefault(str, default)
if ^str == 0 if ^str == 0
return default return default
fin fin
@ -1194,7 +1204,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Send an event to the scripts on the current map square // Send an event to the scripts on the current map square
def scriptEvent(event, param) export def scriptEvent(event, param)
byte i, argCount byte i, argCount
word script word script
if !nMapScripts; return; fin if !nMapScripts; return; fin
@ -2081,25 +2091,6 @@ def testCombat
getPos(@x, @y) getPos(@x, @y)
checkEncounter(x, y, TRUE) checkEncounter(x, y, TRUE)
end end
def addItem()
word funcTbl, func, p_item, n_item
flipToPage1()
^$c053
if ^$25 < 23; ^$25 = 23; fin
puts("\nAdd item #: ")
n_item = parseDecWithDefault(readStr(), 0)
^$c052
if n_item >= 2
funcTbl = loadEngine(MODULE_GEN_ITEMS)
func = *(funcTbl + n_item * 2)
p_item = func()
addToList(@global=>p_players=>p_items, p_item)
returnFromEngine()
fin
end
def printMem def printMem
flipToPage1 flipToPage1
^$c051 ^$c051
@ -2113,7 +2104,6 @@ def setCheatCmds
// install cheat commands // install cheat commands
cmdTbl['T'] = @kbdTeleport cmdTbl['T'] = @kbdTeleport
cmdTbl['P'] = @showPos cmdTbl['P'] = @showPos
cmdTbl['%'] = @addItem
cmdTbl['>'] = @nextPortrait cmdTbl['>'] = @nextPortrait
cmdTbl['<'] = @prevPortrait cmdTbl['<'] = @prevPortrait
cmdTbl['!'] = @testCombat cmdTbl['!'] = @testCombat

View File

@ -17,6 +17,8 @@ include "playtype.plh"
// Global definitions // Global definitions
include "globalDefs.plh" include "globalDefs.plh"
include "gen_modules.plh"
include "gen_items.plh"
// Definition of constants for functions exported by this module // Definition of constants for functions exported by this module
include "party.plh" include "party.plh"
@ -55,7 +57,7 @@ def itemMatch(item, group)
is TYPE_EQUIP is TYPE_EQUIP
return type == TYPE_ARMOR or type == TYPE_WEAPON return type == TYPE_ARMOR or type == TYPE_WEAPON
is TYPE_USE is TYPE_USE
return type == TYPE_ITEM and item=>p_modifiers return type == TYPE_ITEM
break break
is TYPE_DROP is TYPE_DROP
return type == TYPE_WEAPON or type == TYPE_ARMOR return type == TYPE_WEAPON or type == TYPE_ARMOR
@ -234,6 +236,47 @@ def showPlayerSheet(num, i_page, i_rows)
return player return player
end end
// Add an item cheat
def addItem(player)
word pModule, funcTbl, func, p_item, n_item, n2, pstr, pstr2
pstr = "%d: %s\n"
pstr2 = "Add item #: "
flipToPage1()
textHome()
^$c051
mmgr(START_LOAD, 1) // code is in partition 1
pModule = mmgr(QUEUE_LOAD, MODULE_GEN_ITEMS<<8 | RES_TYPE_MODULE)
mmgr(FINISH_LOAD, 0)
funcTbl = pModule()
for n_item = 1 to NUM_ITEMS
func = *(funcTbl + (n_item+1) * 2)
p_item = func()
printf2(pstr, n_item, p_item=>s_name)
if (n_item % 22) == 0 or n_item == NUM_ITEMS
mmgr(HEAP_COLLECT, 0)
puts(pstr2)
n2 = parseDecWithDefault(readStr(), 0)
if n2 >= 1 and n2 <= NUM_ITEMS
func = *(funcTbl + (n2+1) * 2)
p_item = func()
printf1("Adding '%s'\n", p_item=>s_name)
addToList(@player=>p_items, p_item)
rdkey()
break
else
textHome()
fin
fin
next
mmgr(FREE_MEMORY, pModule)
^$c050
return
end
// Show player sheet and accept command // Show player sheet and accept command
def _party_doPlayerSheet(num) def _party_doPlayerSheet(num)
word player, item word player, item
@ -274,7 +317,9 @@ def _party_doPlayerSheet(num)
rawDisplayStr("\n^T032Which item?") rawDisplayStr("\n^T032Which item?")
item = itemNum(player, i_rows * i_page, getUpperKey() - 'A', TYPE_USE) item = itemNum(player, i_rows * i_page, getUpperKey() - 'A', TYPE_USE)
if item if item
if streqi(item=>p_modifiers=>s_name, "health") setWindow2()
clearWindow()
if item=>p_modifiers and streqi(item=>p_modifiers=>s_name, "health")
if player=>w_health < player=>w_maxHealth if player=>w_health < player=>w_maxHealth
player=>w_health = min(player=>w_health + item=>p_modifiers=>w_modValue, player=>w_maxHealth) player=>w_health = min(player=>w_health + item=>p_modifiers=>w_modValue, player=>w_maxHealth)
item->b_curUses++ item->b_curUses++
@ -283,6 +328,7 @@ def _party_doPlayerSheet(num)
fin fin
fin fin
fin fin
scriptEvent(@S_USE, item=>s_name)
fin fin
else else
beep beep
@ -343,6 +389,11 @@ def _party_doPlayerSheet(num)
addGold(500) addGold(500)
fin fin
break break
is '%' // item cheat
if global->b_godmode
addItem(player)
fin
break
// All done // All done
otherwise return otherwise return
wend wend