Prepare for scripted event handling

This commit is contained in:
David Schmenk 2016-07-04 12:59:24 -07:00
parent fc365eaee8
commit e9012275d5
3 changed files with 21 additions and 4 deletions

View File

@ -1235,14 +1235,24 @@ def initMap(x, y, dir)
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Send an event to the script
export def scriptEvent(event, param)
if global=>w_mapScript
return global=>w_mapScript(event, param)
fin
return -1
end
// Check for script(s) attached to the given location, and call them if there are any. // Check for script(s) attached to the given location, and call them if there are any.
// Returns TRUE if any were triggered. // Returns TRUE if any were triggered.
def checkScripts(x, y) def checkScripts(x, y)
word p word p
word pNext
word script word script
word pNext
byte anyTriggered byte anyTriggered
scriptEvent(EVENT_LEAVE, 0)
global=>w_mapScript = 0
anyTriggered = FALSE anyTriggered = FALSE
x = x - triggerOriginX x = x - triggerOriginX
y = y - triggerOriginY y = y - triggerOriginY
@ -1256,10 +1266,10 @@ def checkScripts(x, y)
p = p + 2 p = p + 2
while p < pNext while p < pNext
if x == ^p if x == ^p
script = p=>1 script = p=>1
setWindow2() setWindow2()
skipScripts = FALSE skipScripts = FALSE
script() script() // When should the script be installed as an event handler?
clearPortrait() clearPortrait()
// Some scripts need to suppress running of any further scripts on the square // Some scripts need to suppress running of any further scripts on the square
// because they swapped out the render engine. // because they swapped out the render engine.
@ -1271,6 +1281,7 @@ def checkScripts(x, y)
fin fin
p = pNext p = pNext
loop loop
scriptEvent(EVENT_ENTER, 0)
return anyTriggered return anyTriggered
end end

View File

@ -66,3 +66,8 @@ const LEAVE_OPEN = 1
const HEAP_BOTTOM = $F000 const HEAP_BOTTOM = $F000
const HEAP_SIZE = $800 const HEAP_SIZE = $800
// Event code
const EVENT_ENTER = 1
const EVENT_LEAVE = 2
const EVENT_USE_ITEM = 3

View File

@ -25,7 +25,8 @@ struc Global
word w_mapX word w_mapX
word w_mapY word w_mapY
byte b_mapDir byte b_mapDir
word w_mapScript
// Shared player gold amount // Shared player gold amount
word w_gold word w_gold