public abstract class StreamScriptLogic extends UT2004BotLogicController
This basically allows us to create a agent with logic implemented in some scripting language (like JavaScript or Python). Beware, Java has currently implemented only one engine and that is JavaScript, for others it is necessary to provide custom binding library for the language (like jython).
The script that will be executed shoudl contain all the normal functions that are expected, i.e.:
You have to specify the file to load and engine to bind before
starting the agent.
Subclasses has to implement StreamScriptedAgent.getScriptFile() to
specify the script. This is done mostly because of google Guice.
Also, if subclass is utilizing some script that is not available as default,
it should override StreamScriptedAgent.engineIsGoingToBeBinded() to set it up.
TODO: this class is rather ugly, it deserves some clean up.
It should go approx. like this * Create a new instance * Create ScriptEngineManager * call engineIsGoingToBeBinded() * get engine from manager based on extension or something How to get data: get file get stream from file What can be done:
| Modifier and Type | Field and Description |
|---|---|
protected ScriptEngine |
engine
ScriptEngine which contains the file with logic.
|
protected Invocable |
invocableEngine
Same engine as in
engine, but recasted as Invocable, allowing us to call methods. |
protected ScriptEngineManager |
scriptEngineManager |
logicModulebot, log, USER_LOG_CATEGORY_ID| Constructor and Description |
|---|
StreamScriptLogic() |
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
callFunction(String name)
Calls function without parameters from the ScriptEngine.
|
protected abstract ScriptEngine |
createScriptEngine(ScriptEngineManager manager)
Return correct ScriptEngine for script this bot is going to run.
|
protected abstract void |
engineBinded()
This method is called when the engine is binded.
|
protected boolean |
evalStream(Reader reader)
Evaluates the stream of the script.
|
UT2004Bot |
getBot() |
protected abstract Reader |
getScriptStream()
Return stream for script that this class should execute.
|
void |
initializeController(UT2004Bot bot)
Constructor which is needed when you have to initialize the
environment of the scripting language.
|
protected abstract void |
scriptBinded()
This method is called after the script is evaluated.
|
protected void |
setAttribute(String name,
Object attribute)
Sets attribute to the global scope of the engine.
|
beforeFirstLogic, getLogicInitializeTime, getLogicShutdownTime, initializeLogic, logic, logicInitialize, logicShutdownbotFirstSpawn, botInitialized, botKilled, botShutdown, finishControllerInitialization, getAct, getInitializeCommand, getLog, getPassword, getWorldView, prepareBotclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbotFirstSpawn, botInitialized, botKilled, botShutdown, finishControllerInitialization, getAct, getInitializeCommand, getLog, getPassword, getWorldView, prepareBotprotected ScriptEngineManager scriptEngineManager
protected ScriptEngine engine
protected Invocable invocableEngine
engine, but recasted as Invocable, allowing us to call methods.public void initializeController(UT2004Bot bot)
Currently used by SPOSHBot.
initializeController in interface IUT2004BotControllerinitializeController in class UT2004BotLogicControllerprotected abstract ScriptEngine createScriptEngine(ScriptEngineManager manager)
Because this class is using stream instead of file we don't know what is scripting language of processed script. That is what this function is for.
manager - ScriptEngineManager that is used to manage engines.ScriptEngine for this agent.protected abstract Reader getScriptStream() throws IOException
IOExceptionprotected abstract void scriptBinded()
protected abstract void engineBinded()
protected final void setAttribute(String name, Object attribute)
name - attribute - protected final boolean evalStream(Reader reader) throws ScriptedAgentException
is - ScriptedAgentExceptionprotected final boolean callFunction(String name) throws ScriptedAgentException
name - ScriptedAgentExceptionpublic UT2004Bot getBot()
getBot in interface IUT2004BotControllergetBot in class UT2004BotControllerCopyright © 2012 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.