diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-02-26 22:06:10 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-03-02 18:12:07 +0100 |
commit | 34ac0d64e23f2b2d3981dbb0ea72157f334805dd (patch) | |
tree | 114b1f7a65956c097f7a59078292c9fa29c6451f /src/scripting/script.cpp | |
parent | e896d0b0125b48e12d43d99ace4498e56d968d50 (diff) | |
download | manaserv-34ac0d64e23f2b2d3981dbb0ea72157f334805dd.tar.gz manaserv-34ac0d64e23f2b2d3981dbb0ea72157f334805dd.tar.bz2 manaserv-34ac0d64e23f2b2d3981dbb0ea72157f334805dd.tar.xz manaserv-34ac0d64e23f2b2d3981dbb0ea72157f334805dd.zip |
Merged all the different Lua states into one
No more Lua state for each status effect, monster, item effect or map. All
scripts are loaded into the same state. This should be more efficient overall
and make it easier to implement dynamic reloading of the scripts in the
future.
Now, this introduces the problem of name collisions between different Lua
scripts. For now this is solved by using more specific function names, like
'tick_plague' and 'tick_jump' rather than just 'tick'. The plan is however
to get rid of these globals, and register these callbacks from the script,
so that they can be local functions without the danger of colliding with
other scripts.
Reviewed-by: Erik Schilling
Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src/scripting/script.cpp')
-rw-r--r-- | src/scripting/script.cpp | 90 |
1 files changed, 0 insertions, 90 deletions
diff --git a/src/scripting/script.cpp b/src/scripting/script.cpp index 722979fd..db44bd57 100644 --- a/src/scripting/script.cpp +++ b/src/scripting/script.cpp @@ -33,7 +33,6 @@ typedef std::map< std::string, Script::Factory > Engines; static Engines *engines = NULL; -Script *Script::globalEventScript = NULL; Script::Script(): mMap(NULL), @@ -107,92 +106,3 @@ void Script::loadNPC(const std::string &name, int id, int x, int y, push(y); execute(); } - -bool Script::loadGlobalEventScript(const std::string &file) -{ - std::string engineName = determineEngineByFilename(file); - if (Script *script = Script::create(engineName)) - { - globalEventScript = script; - return globalEventScript->loadFile(file); - } - return false; -} - -bool Script::executeGlobalEventFunction(const std::string &function, Being* obj) -{ - bool isScriptHandled = false; - if (Script *script = globalEventScript) - { - script->setMap(obj->getMap()); - script->prepare(function); - script->push(obj); - script->execute(); - script->setMap(NULL); - isScriptHandled = true; // TODO: don't set to true when execution failed - } - return isScriptHandled; -} - - -void Script::addDataToSpecial(int id, Special *special) -{ - /* currently only gets the recharge cost. - TODO: get any other info in a similar way, but - first we have to agree on what other - info we actually want to provide. - */ - if (special) - { - if (Script *script = globalEventScript) - { - script->prepare("get_special_recharge_cost"); - script->push(id); - int scriptReturn = script->execute(); - special->neededMana = scriptReturn; - } - } - -} - -bool Script::performSpecialAction(int specialId, Being *caster) -{ - if (Script *script = globalEventScript) - { - script->prepare("use_special"); - script->push(caster); - script->push(specialId); - script->execute(); - } - return true; -} - -bool Script::performCraft(Being *crafter, - const std::list<InventoryItem> &recipe) -{ - if (Script *script = globalEventScript) - { - script->prepare("on_craft"); - script->push(crafter); - script->push(recipe); - script->execute(); - } - return true; -} - -std::string Script::determineEngineByFilename(const std::string &filename) -{ - std::string ext = filename.substr(filename.find_last_of(".") + 1); - - if (ext == "lua") - { - return "lua"; - } - else - { - // Set to default engine and print warning - LOG_WARN("Unknown file extension for script \"" - + filename + "\", falling back to default script engine"); - return Configuration::getValue("script_defaultEngine", "lua"); - } -} |