Can now define a Help global function in Outlaw, and it'll get called when '?' is hit in the gme.

This commit is contained in:
Martin Haye 2016-07-01 17:19:12 -07:00
parent 30a9f15ae2
commit bb0a9339fe
3 changed files with 28 additions and 4 deletions

View File

@ -2329,7 +2329,8 @@ end
// Translate global scripts to code
def gsmod = new ScriptModule()
gsmod.genScriptDefs(new File("build/src/plasma/gen_globalScripts.plh.new"), dataIn.global.scripts)
gsmod.genScriptDefs(new File("build/src/plasma/gen_globalScripts.plh.new"), dataIn.global.scripts,
["newGame", "help"] as Set)
replaceIfDiff("build/src/plasma/gen_globalScripts.plh")
gsmod.packGlobalScripts(new File("build/src/plasma/gen_globalScripts.pla.new"), dataIn.global.scripts)
replaceIfDiff("build/src/plasma/gen_globalScripts.pla")
@ -2528,19 +2529,25 @@ end
}
/**
* Generate header for a set of scripts.
* Generate header for a set of scripts. If any of the 'required' scripts are not
* found, they'll get a special offset of -1.
*/
def genScriptDefs(outFile, inScripts)
def genScriptDefs(outFile, inScripts, required)
{
out = new PrintWriter(new FileWriter(outFile))
out << "// Generated code - DO NOT MODIFY BY HAND\n\n"
// Generate a name for each script, and a constant in the function table.
def found = [] as Set
inScripts.script.eachWithIndex { script, idx ->
def name = getScriptName(script)
assert name
scriptNames[script] = "sc_${humanNameToSymbol(name, false)}"
out << "const ${scriptNames[script]} = ${idx*2}\n"
found.add(humanNameToSymbol(name, false))
}
(required - found).each { name ->
out << "const sc_$name = -1 // not found\n"
}
out.close()
}

View File

@ -266,7 +266,7 @@ def newGame()
globalScriptsModule = mmgr(QUEUE_LOAD, MODULE_GEN_GLOBAL_SCRIPTS<<8 | RES_TYPE_MODULE)
mmgr(FINISH_LOAD, LEAVE_OPEN)
playersModule()=>makeInitialParty()
globalScriptsModule()=>sc_newGame()
if sc_newGame >= 0; globalScriptsModule()=>sc_newGame(); fin
end
///////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -33,6 +33,7 @@ include "gen_images.plh"
include "gen_modules.plh"
include "gen_enemies.plh"
include "gen_players.plh"
include "gen_globalScripts.plh"
include "combat.plh"
include "party.plh"
include "diskops.plh"
@ -2022,6 +2023,21 @@ def loadGame
restoreMapPos()
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def help
word globalScriptsModule
if sc_help >= 0
flipToPage1()
setMapWindow(); clearWindow()
loadEngine(MODULE_GEN_GLOBAL_SCRIPTS)=>sc_help()
restoreMapPos()
else
scriptDisplayStr("Help not available.\n")
fin
end
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
// Set up the command table for 3D mode
def initCmds()
@ -2043,6 +2059,7 @@ def initCmds()
cmdTbl['3'] = @showPlayer3
cmdTbl[$13] = @saveGame // ctrl-S
cmdTbl[$0c] = @loadGame // ctrl-L
cmdTbl['?'] = @help
// Commands handled differently in 3D vs 2D
if mapIs3D