diff --git a/source/game/game/script_manager.cpp b/source/game/game/script_manager.cpp index b4275c580..afb75c21a 100644 --- a/source/game/game/script_manager.cpp +++ b/source/game/game/script_manager.cpp @@ -552,24 +552,35 @@ namespace Game { luaScript.registerFunction(getFactionPlayerType, "getFactionPlayerType"); - //load code - for (int i = 0; i < scenario->getScriptCount(); ++i) { - const Script * - script = scenario->getScript(i); - luaScript.loadCode("function " + script->getName() + "()" + - script->getCode() + "end\n", - script->getName()); - } - //load code + map scripts; + map::iterator iter; + + //load faction code for (int i = 0; i < world->getFactionCount(); ++i) { FactionType const* type = world->getFaction(i)->getType(); for (int j = 0; j < type->getScriptCount(); j++) { const Script* script = type->getScript(j); - luaScript.loadCode("function " + script->getName() + "()" + - script->getCode() + "end\n", - script->getName()); + iter = scripts.find(script->getName()); + if (iter == scripts.end()) + scripts[script->getName()] = *script; + else + iter->second.appendCode(script->getCode()); } } + //load scenario code + for (int i = 0; i < scenario->getScriptCount(); ++i) { + const Script* script = scenario->getScript(i); + iter = scripts.find(script->getName()); + if (iter == scripts.end()) + scripts[script->getName()] = *script; + else + iter->second.appendCode(script->getCode()); + } + + for (iter = scripts.begin(); iter != scripts.end(); ++iter) { + luaScript.loadCode("function " + iter->second.getName() + "()" + + iter->second.getCode() + "end\n", iter->second.getName()); + } //setup message box messageBox.init(Lang::getInstance().getString("Ok")); diff --git a/source/game/world/scenario.h b/source/game/world/scenario.h index b22570ce4..2449403c8 100644 --- a/source/game/world/scenario.h +++ b/source/game/world/scenario.h @@ -117,15 +117,29 @@ namespace Game { string code; public: - Script(const string & name, const string & code) { + Script() { + } + + Script(const string& name, const string& code) { this->name = name; this->code = code; - } const string & getName() const { + } + + const string& getName() const { return name; } - const string & getCode() const { + + const string& getCode() const { return code; } + + void setCode(const string& newCode) { + code = newCode; + } + + void appendCode(const string& newCode) { + code += newCode; + } }; // =====================================================