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/playtype.plh\"\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
def code = getSingle(blk.field, 'CODE')
outIndented("scriptCombat(${escapeString(code)})\n")
outIndented("tmp = scriptCombat(${escapeString(code)})); if (!tmp); return; fin\n")
}
def packTeleport(blk)

View File

@ -78,7 +78,6 @@ byte q_mapNum = 1
word q_x = 0
word q_y = 0
byte q_dir = 0
word q_encounter = NULL
// For decimal conversion and display tabbing
byte decimalBuf[7]
@ -1370,7 +1369,7 @@ def adjustDir(n)
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Move backward one step (3D mode)
// Move backward one step (3D mode). Also actually works in 2D mode.
def _moveBackward()
adjustDir(8)
moveForward()
@ -1556,9 +1555,6 @@ def kbdLoop()
if q_mapNum
setMap(q_mapIs3D, q_mapNum, q_x, q_y, q_dir)
q_mapNum = 0
elsif q_encounter
doCombat(q_encounter)
q_encounter = NULL
fin
if needRender
doRender()
@ -1920,6 +1916,7 @@ end
// Called by user-defined map scripts to initiate a combat encounter.
def _scriptCombat(mapCode)
word pScripts
word result
// Lock the currently running script in memory so combat engine doesn't destroy our calling
// context.
@ -1935,12 +1932,15 @@ def _scriptCombat(mapCode)
skipScripts = TRUE
// 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)
if pScripts
mmgr(UNLOCK_MEMORY, pScripts)
fin
// Let the caller know what happened (1=won, 0=fled)
return result
end
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -1951,6 +1951,11 @@ def doCombat(mapCode)
global=>p_enemyGroups = NULL
mmgr(HEAP_COLLECT, 0)
restoreMapPos()
// If the party fled the combat instead of winning, back up to previous square.
if (!result)
moveBackward()
fin
return result
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_render ; params: none
JMP pl_texControl ; params: 1=load, 0=unload
JMP pl_getScripts ; params: none
;----------------------------------------------------------------------
; >> START LOADING MAP SECTIONS
@ -1232,6 +1233,14 @@ pl_setDir:
pl_texControl:
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 {
LDA AVATAR_DIR