Not sure what all that allowZoneInit stuff was about, but we need to able to adjust encounter zones at any time.

This commit is contained in:
Martin Haye 2018-06-07 09:11:07 -07:00
parent f35739aec9
commit eb0e68e33c

View File

@ -79,6 +79,7 @@ predef startGame(firstTime, ask)#0
predef showAnimFrame()#0 predef showAnimFrame()#0
predef showParty()#0 predef showParty()#0
predef unloadTextures()#0 predef unloadTextures()#0
predef clearEncounterZones()#0
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Global variables // Global variables
@ -111,7 +112,6 @@ word triggerTbl
word cmdTbl[96] // ASCII $00..$5F word cmdTbl[96] // ASCII $00..$5F
byte frameLoaded = 0 byte frameLoaded = 0
byte allowZoneInit = FALSE
word curEngine = NULL word curEngine = NULL
word pIntimate = NULL word pIntimate = NULL
export word pResourceIndex = NULL export word pResourceIndex = NULL
@ -2246,9 +2246,7 @@ def initMap(x, y, dir)#0
setWindow2(); clearWindow() setWindow2(); clearWindow()
// Clear the list of encounter zones from any previous maps // Clear the list of encounter zones from any previous maps
if allowZoneInit clearEncounterZones
global=>p_encounterZones = NULL
fin
// Start up the display engine with map data and starting position. This will also load and // Start up the display engine with map data and starting position. This will also load and
// init the script module, if any, which will end up calling us back at the setScriptInfo // init the script module, if any, which will end up calling us back at the setScriptInfo
@ -2618,9 +2616,7 @@ export def setMap(is3D, num, x, y, dir)#0
useMapWindow() useMapWindow()
mapIs3D = is3D mapIs3D = is3D
mapNum = num mapNum = num
allowZoneInit = TRUE
initMap(x, y, dir) initMap(x, y, dir)
allowZoneInit = FALSE
fin fin
// Don't send enter event, because we often land on an "Exit to wilderness?" script // Don't send enter event, because we often land on an "Exit to wilderness?" script
//NO:scriptEvent(S_ENTER, NULL) //NO:scriptEvent(S_ENTER, NULL)
@ -2726,7 +2722,7 @@ export def setScriptInfo(mapName, moduleNum, timeFn, trigTbl, wdt, hgt)#0
showMapName(mapName) showMapName(mapName)
// Get ready for new encounter zones // Get ready for new encounter zones
if allowZoneInit; global=>p_encounterZones = NULL; fin clearEncounterZones
// Back to the main text window. // Back to the main text window.
setWindow2() setWindow2()
@ -3027,15 +3023,13 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
export def addEncounterZone(code, x, y, dist, chance)#0 export def addEncounterZone(code, x, y, dist, chance)#0
word p word p
if allowZoneInit p = mmgr(HEAP_ALLOC, TYPE_ENCOUNTER_ZONE)
p = mmgr(HEAP_ALLOC, TYPE_ENCOUNTER_ZONE) p=>s_name = mmgr(HEAP_INTERN, code)
p=>s_name = mmgr(HEAP_INTERN, code) p=>w_encX = x
p=>w_encX = x p=>w_encY = y
p=>w_encY = y p=>w_encMaxDist = dist
p=>w_encMaxDist = dist p=>w_encChance = chance
p=>w_encChance = chance addToList(@global=>p_encounterZones, p)
addToList(@global=>p_encounterZones, p)
fin
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
@ -3100,7 +3094,8 @@ export def checkEncounter(x, y, force)#0
p = global=>p_encounterZones p = global=>p_encounterZones
while p while p
d = min(abs(x - p=>w_encX), abs(y - p=>w_encY)) d = min(abs(x - p=>w_encX), abs(y - p=>w_encY))
if d < bestDist and (p=>w_encMaxDist == 0 or d < p=>w_encMaxDist) // Using '<=' below so that later-added zones added by a scripted event take precedence
if d <= bestDist and (p=>w_encMaxDist == 0 or d <= p=>w_encMaxDist)
p_bestZone = p p_bestZone = p
bestDist = d bestDist = d
fin fin
@ -3686,9 +3681,7 @@ def startGame(firstTime, ask)#0
mapIs3D = q_mapIs3D mapIs3D = q_mapIs3D
mapNum = q_mapNum mapNum = q_mapNum
q_mapNum = 0 q_mapNum = 0
allowZoneInit = TRUE
initMap(q_x, q_y, q_dir) initMap(q_x, q_y, q_dir)
allowZoneInit = FALSE
saveGame() saveGame()
else else
q_mapNum = 0 q_mapNum = 0