diff --git a/src/game.cpp b/src/game.cpp index 88bf821ad..5ac876428 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2534,8 +2534,10 @@ BOOL loadGame(const char *pGameToLoad, BOOL keepObjects, BOOL freeMem, BOOL User if (saveGameVersion >= VERSION_33) { PLAYERSTATS playerStats; + bool scav = game.scavengers; game = saveGameData.sGame; + game.scavengers = scav; // ok, so this is butt ugly. but i'm just getting inspiration from the rest of the code around here. ok? - per productionPlayer= selectedPlayer; bMultiPlayer = saveGameData.multiPlayer; bMultiMessages = bMultiPlayer; diff --git a/src/qtscript.cpp b/src/qtscript.cpp index 942b583a4..acf6f05ea 100644 --- a/src/qtscript.cpp +++ b/src/qtscript.cpp @@ -48,6 +48,7 @@ struct timerNode int frameTime; int ms; int player; + timerNode() {} timerNode(QScriptEngine *caller, QString val, int plr, int frame) : function(val) { player = plr; ms = frame; frameTime = frame + gameTime; engine = caller; } // implement operator less TODO }; @@ -235,13 +236,14 @@ bool saveScriptStates(const char *filename) QSettings ini(QString("wz::") + filename, QSettings::IniFormat); if (!ini.isWritable()) { - qWarning("Savegame file not writable"); + debug(LOG_ERROR, "Savegame file not writable"); + return false; } for (int i = 0; i < scripts.size(); ++i) { - ini.beginGroup(QString("globals_") + QString::number(i)); QScriptEngine *engine = scripts.at(i); QScriptValueIterator it(engine->globalObject()); + ini.beginGroup(QString("globals_") + QString::number(i)); while (it.hasNext()) { it.next(); @@ -252,22 +254,72 @@ bool saveScriptStates(const char *filename) } ini.endGroup(); } + for (int i = 0; i < timers.size(); ++i) + { + timerNode node = timers.at(i); + ini.beginGroup(QString("triggers_") + QString::number(i)); + ini.setValue("player", node.player); + ini.setValue("function", node.function.toUtf8().constData()); + if (!node.baseobj.isEmpty()) + { + ini.setValue("object", node.baseobj.toUtf8().constData()); + } + ini.setValue("frame", node.frameTime); + ini.setValue("ms", node.ms); + ini.endGroup(); + } return true; } +static QScriptEngine *findEngineForPlayer(int match) +{ + for (int i = 0; i < scripts.size(); ++i) + { + QScriptEngine *engine = scripts.at(i); + int player = engine->globalObject().property("me").toInt32(); + if (match == player) + { + return engine; + } + } + ASSERT(false, "Script context for player %d not found", match); + return NULL; +} + bool loadScriptStates(const char *filename) { QSettings ini(QString("wz::") + filename, QSettings::IniFormat); - for (int i = 0; i < scripts.size(); ++i) + QStringList list = ini.childGroups(); + debug(LOG_SAVE, "Loading script states for %d script contexts", scripts.size()); + for (int i = 0; i < list.size(); ++i) { - ini.beginGroup(QString("globals_") + QString::number(i)); - QStringList keys = ini.childKeys(); - QScriptEngine *engine = scripts.at(i); - for (int j = 0; j < keys.size(); ++j) + if (list[i].startsWith("triggers_")) { - engine->globalObject().setProperty(keys.at(i), engine->toScriptValue(ini.value(keys.at(i)))); + ini.beginGroup(list[i]); + timerNode node; + node.player = ini.value("player").toInt(); + node.ms = ini.value("ms").toInt(); + node.frameTime = ini.value("frame").toInt(); + debug(LOG_SAVE, "Registering trigger %d for player %d", i, node.player); + node.engine = findEngineForPlayer(node.player); + node.function = ini.value("function").toString(); + node.baseobj = ini.value("baseobj", QString()).toString(); + timers.push_back(node); + ini.endGroup(); + } + else if (list[i].startsWith("globals_")) + { + ini.beginGroup(list[i]); + int player = ini.value("me").toInt(); + QScriptEngine *engine = findEngineForPlayer(player); + QStringList keys = ini.childKeys(); + debug(LOG_SAVE, "Loading script globals for player %d -- found %d values", player, keys.size()); + for (int j = 0; j < keys.size(); ++j) + { + engine->globalObject().setProperty(keys.at(j), engine->toScriptValue(ini.value(keys.at(j)))); + } + ini.endGroup(); } - ini.endGroup(); } return true; } diff --git a/src/qtscriptfuncs.cpp b/src/qtscriptfuncs.cpp index 7e0246cc7..54190388b 100644 --- a/src/qtscriptfuncs.cpp +++ b/src/qtscriptfuncs.cpp @@ -84,10 +84,6 @@ static QScriptValue js_enumGroup(QScriptContext *context, QScriptEngine *engine) { matches.push_back(psCurr); } - if (matches.size() == 0) - { - return QScriptValue(); - } QScriptValue result = engine->newArray(matches.size()); for (int i = 0; i < matches.size(); i++) { @@ -134,10 +130,6 @@ static QScriptValue js_enumStruct(QScriptContext *context, QScriptEngine *engine matches.push_back(psStruct); } } - if (matches.size() == 0) - { - return QScriptValue(); - } QScriptValue result = engine->newArray(matches.size()); for (int i = 0; i < matches.size(); i++) {