Now processes 'leave' events on map scripts.

This commit is contained in:
Martin Haye 2016-09-20 06:15:49 -07:00
parent a2c8008755
commit ce7bf1d6cc
3 changed files with 36 additions and 18 deletions

View File

@ -2804,13 +2804,15 @@ end
if (name != null)
scriptNames[script] = "sc_${humanNameToSymbol(name, false)}"
}
// Even if there were no scripts, we still need an init to display
// the map name.
// Generate the table of triggers, and code for each script.
makeTriggerTbl(scripts, xRange, yRange)
scripts.each { script ->
packScript(script)
}
// Even if there were no scripts, we still need an init to display
// the map name.
makeInit(mapName, initScript, maxX, maxY)
out.close()
@ -2826,12 +2828,26 @@ end
withContext(scriptNames[script])
{
if (script.block.size() == 0) {
printWarning("empty script '${script?.@name}' found; skipping.")
printWarning("empty script found; skipping.")
return
}
def proc = script.block[0]
// Record the function's name and start its definition
out << "def ${scriptNames[script]}()\n"
out << "def ${scriptNames[script]}("
// If the script takes arguments, mark those and add them to the definition
def args = [] as Set
if (proc.mutation) {
proc.mutation.arg.eachWithIndex { arg, idx ->
if (idx > 0)
out << ", "
def name = "v_" + humanNameToSymbol(arg.@name, false)
out << name
args << name
}
}
out << ")\n"
indent = 1
// Need to queue up the script, to find out what variables need
@ -2842,7 +2858,6 @@ end
variables = [] as Set
// Process the code inside it
def proc = script.block[0]
assert proc.@type == "procedures_defreturn"
if (proc.statement.size() > 0) {
assert proc.statement.size() == 1
@ -2853,13 +2868,13 @@ end
else
printWarning "empty statement found; skipping."
// Define all the variables that were mentioned
// Define all the variables that were mentioned (except the args)
out.close()
out = outerOutput
variables.each { var ->
(variables - args).each { var ->
outIndented("word $var\n")
}
variables.each { var ->
(variables - args).each { var ->
outIndented("$var = 0\n")
}

View File

@ -10,7 +10,7 @@
import gamelib
// Shared library routines
//////////// Shared library routines ////////////
predef setScriptInfo, scriptDisplayStr, scriptDisplayStrNL, getYN, queue_setMap
predef setSky, setGround, queue_teleport, setPortrait, clearPortrait, moveWayBackward
predef getUpperKey, clearWindow, getGlobals, rand16, printf1, printf2, printf3
@ -28,13 +28,13 @@ import gamelib
predef setGameFlag, getGameFlag, scriptSetAvatar
predef addPlayerToParty, removePlayerFromParty, partyHasPlayer
// Shared string constants
/////////// Shared string constants //////////////
// First: attributes
byte[] S_INTELLIGENCE, S_STRENGTH, S_AGILITY, S_STAMINA, S_CHARISMA, S_SPIRIT, S_LUCK
byte[] S_HEALTH, S_MAX_HEALTH, S_AIMING, S_HAND_TO_HAND, S_DODGING, S_GOLD
// Next: common events
byte[] S_ENTER, S_USE
byte[] S_ENTER, S_LEAVE, S_USE
end

View File

@ -1212,8 +1212,8 @@ def getArgCount(pFunc)
word pBytecode
// skip over JMP to plasma interp, get addr in aux mem
pBytecode = pFunc=>3
pBytecode = pFunc=>3
// Check if the function starts with ENTER op
if readAuxByte(pBytecode) == $58
return readAuxByte(pBytecode+2)
@ -1226,7 +1226,7 @@ end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Send an event to the scripts on the current map square
def scriptEvent(event, param)
byte i
byte i, argCount
word script
if !nMapScripts; return; fin
@ -1235,10 +1235,13 @@ def scriptEvent(event, param)
for i = 0 to nMapScripts-1
script = mapScripts[i]
if getArgCount(script) == 2
script(event, param)
elsif event == @S_ENTER // zero-param scripts are assumed to be strictly 'enter' handlers
argCount = getArgCount(script)
if argCount == 0 and event == @S_ENTER // zero-param scripts are assumed to be strictly 'enter' handlers
script()
elsif argCount == 1
script(event)
elsif argCount == 2
script(event, param)
fin
// Some scripts need to suppress running of any further scripts on the square