Now handles scripted combat on 2D maps as well, and handles fleeing correctly.

This commit is contained in:
Martin Haye 2016-06-30 09:31:29 -07:00
parent 02bbbf5ac7
commit 437471451b
3 changed files with 23 additions and 8 deletions

View File

@ -2508,7 +2508,8 @@ end
out << "include \"../plasma/gamelib.plh\"\n" out << "include \"../plasma/gamelib.plh\"\n"
out << "include \"../plasma/playtype.plh\"\n" out << "include \"../plasma/playtype.plh\"\n"
out << "include \"../plasma/gen_images.plh\"\n\n" out << "include \"../plasma/gen_images.plh\"\n\n"
out << "word global\n\n" out << "word global\n"
out << "word tmp\n\n"
} }
/** /**
@ -2905,7 +2906,7 @@ end
{ {
assert blk.field.size() == 1 assert blk.field.size() == 1
def code = getSingle(blk.field, 'CODE') def code = getSingle(blk.field, 'CODE')
outIndented("scriptCombat(${escapeString(code)})\n") outIndented("tmp = scriptCombat(${escapeString(code)})); if (!tmp); return; fin\n")
} }
def packTeleport(blk) def packTeleport(blk)

View File

@ -78,7 +78,6 @@ byte q_mapNum = 1
word q_x = 0 word q_x = 0
word q_y = 0 word q_y = 0
byte q_dir = 0 byte q_dir = 0
word q_encounter = NULL
// For decimal conversion and display tabbing // For decimal conversion and display tabbing
byte decimalBuf[7] byte decimalBuf[7]
@ -1370,7 +1369,7 @@ def adjustDir(n)
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Move backward one step (3D mode) // Move backward one step (3D mode). Also actually works in 2D mode.
def _moveBackward() def _moveBackward()
adjustDir(8) adjustDir(8)
moveForward() moveForward()
@ -1556,9 +1555,6 @@ def kbdLoop()
if q_mapNum if q_mapNum
setMap(q_mapIs3D, q_mapNum, q_x, q_y, q_dir) setMap(q_mapIs3D, q_mapNum, q_x, q_y, q_dir)
q_mapNum = 0 q_mapNum = 0
elsif q_encounter
doCombat(q_encounter)
q_encounter = NULL
fin fin
if needRender if needRender
doRender() doRender()
@ -1920,6 +1916,7 @@ end
// Called by user-defined map scripts to initiate a combat encounter. // Called by user-defined map scripts to initiate a combat encounter.
def _scriptCombat(mapCode) def _scriptCombat(mapCode)
word pScripts word pScripts
word result
// Lock the currently running script in memory so combat engine doesn't destroy our calling // Lock the currently running script in memory so combat engine doesn't destroy our calling
// context. // context.
@ -1935,12 +1932,15 @@ def _scriptCombat(mapCode)
skipScripts = TRUE skipScripts = TRUE
// Now run the combat // Now run the combat
doCombat(mapCode) result = doCombat(mapCode)
// Unlock the script module so it can get freed a the natural time (when it's done) // Unlock the script module so it can get freed a the natural time (when it's done)
if pScripts if pScripts
mmgr(UNLOCK_MEMORY, pScripts) mmgr(UNLOCK_MEMORY, pScripts)
fin fin
// Let the caller know what happened (1=won, 0=fled)
return result
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
@ -1951,6 +1951,11 @@ def doCombat(mapCode)
global=>p_enemyGroups = NULL global=>p_enemyGroups = NULL
mmgr(HEAP_COLLECT, 0) mmgr(HEAP_COLLECT, 0)
restoreMapPos() restoreMapPos()
// If the party fled the combat instead of winning, back up to previous square.
if (!result)
moveBackward()
fin
return result return result
end end

View File

@ -114,6 +114,7 @@ next_zp = $AB
JMP pl_setColor ; params: slot (0=sky/1=ground), color (0-15); return: nothing JMP pl_setColor ; params: slot (0=sky/1=ground), color (0-15); return: nothing
JMP pl_render ; params: none JMP pl_render ; params: none
JMP pl_texControl ; params: 1=load, 0=unload JMP pl_texControl ; params: 1=load, 0=unload
JMP pl_getScripts ; params: none
;---------------------------------------------------------------------- ;----------------------------------------------------------------------
; >> START LOADING MAP SECTIONS ; >> START LOADING MAP SECTIONS
@ -1232,6 +1233,14 @@ pl_setDir:
pl_texControl: pl_texControl:
rts rts
;-------------------------------------------------------------------------------
; >> pl_getScripts
; Called by PLASMA code to get the currently loaded scripts module
pl_getScripts:
lda SCRIPTS_LOC
ldy SCRIPTS_LOC+1
rts
;---------------------------------------------------------------------- ;----------------------------------------------------------------------
INNER_ADVANCE: !zone { INNER_ADVANCE: !zone {
LDA AVATAR_DIR LDA AVATAR_DIR