Fixed LUA loading for multiple factions

This commit is contained in:
mathusummut
2019-02-04 00:30:05 +01:00
parent e12e4ff732
commit a124a4a75a
2 changed files with 40 additions and 15 deletions

View File

@@ -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<string, Script> scripts;
map<string, Script>::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"));

View File

@@ -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;
}
};
// =====================================================