diff --git a/binaries/data/mods/public/gui/common/functions_utility_loadsave.js b/binaries/data/mods/public/gui/common/functions_utility_loadsave.js index 4ca61f4665..e0d637ecd7 100644 --- a/binaries/data/mods/public/gui/common/functions_utility_loadsave.js +++ b/binaries/data/mods/public/gui/common/functions_utility_loadsave.js @@ -9,7 +9,7 @@ function generateLabel(metadata, engineInfo) var dateString = sprintf(translate("\\[%(date)s]"), { date: dateTimeString }); if (engineInfo) { - if (!hasSameVersion(metadata, engineInfo)) + if (!hasSameSavegameVersion(metadata, engineInfo) || !hasSameEngineVersion(metadata, engineInfo)) dateString = "[color=\"red\"]" + dateString + "[/color]"; else if (!hasSameMods(metadata, engineInfo)) dateString = "[color=\"orange\"]" + dateString + "[/color]"; @@ -23,9 +23,17 @@ function generateLabel(metadata, engineInfo) /** * Check the version compatibility between the saved game to be loaded and the engine */ -function hasSameVersion(metadata, engineInfo) +function hasSameSavegameVersion(metadata, engineInfo) { - return (metadata.version_major == engineInfo.version_major); + return metadata.version_major == engineInfo.version_major; +} + +/** + * Check the version compatibility between the saved game to be loaded and the engine + */ +function hasSameEngineVersion(metadata, engineInfo) +{ + return metadata.engine_version && metadata.engine_version == engineInfo.engine_version; } /** @@ -33,15 +41,8 @@ function hasSameVersion(metadata, engineInfo) */ function hasSameMods(metadata, engineInfo) { - if (!metadata.mods) // only here for backwards compatibility with previous saved games - var gameMods = []; - else - var gameMods = metadata.mods; - - if (gameMods.length != engineInfo.mods.length) + if (!metadata.mods || metadata.mods.length != engineInfo.mods.length) return false; - for (var i = 0; i < gameMods.length; ++i) - if (gameMods[i] != engineInfo.mods[i]) - return false; - return true; + + return metadata.mods.every((mod, index) => mod == engineInfo.mods[index]); } diff --git a/binaries/data/mods/public/gui/savedgames/load.js b/binaries/data/mods/public/gui/savedgames/load.js index 3c3e370c8a..d89082fae1 100644 --- a/binaries/data/mods/public/gui/savedgames/load.js +++ b/binaries/data/mods/public/gui/savedgames/load.js @@ -40,19 +40,34 @@ function loadGame() // check game compatibility before really loading it var engineInfo = Engine.GetEngineInfo(); - if (!hasSameVersion(metadata, engineInfo) || !hasSameMods(metadata, engineInfo)) + var sameMods = hasSameMods(metadata, engineInfo); + var sameEngineVersion = hasSameEngineVersion(metadata, engineInfo); + var sameSavegameVersion = hasSameSavegameVersion(metadata, engineInfo); + if (!sameEngineVersion || !sameSavegameVersion || !sameMods) { // version not compatible ... ask for confirmation var btCaptions = [translate("Yes"), translate("No")]; var btCode = [function(){ reallyLoadGame(gameId); }, init]; var message = translate("This saved game may not be compatible:"); - if (!hasSameVersion(metadata, engineInfo)) - message += "\n" + sprintf(translate("It needs 0 A.D. version %(requiredVersion)s, while you are running version %(currentVersion)s."), { + + if (!sameEngineVersion) + { + if (metadata.engine_version) + message += "\n" + sprintf(translate("It needs 0 A.D. version %(requiredVersion)s, while you are running version %(currentVersion)s."), { + requiredVersion: metadata.engine_version, + currentVersion: engineInfo.engine_version + }); + else + message += "\n" + translate("It needs an older version of 0 A.D."); + } + + if (!sameSavegameVersion) + message += "\n" + sprintf(translate("It needs 0 A.D. savegame version %(requiredVersion)s, while you have savegame version %(currentVersion)s."), { requiredVersion: metadata.version_major, currentVersion: engineInfo.version_major }); - if (!hasSameMods(metadata, engineInfo)) + if (!sameMods) { if (!metadata.mods) // only for backwards compatibility with previous saved games metadata.mods = []; diff --git a/source/lobby/XmppClient.cpp b/source/lobby/XmppClient.cpp index 369ab90b14..9cc3dc2cd6 100644 --- a/source/lobby/XmppClient.cpp +++ b/source/lobby/XmppClient.cpp @@ -24,6 +24,7 @@ #include "lib/utf8.h" #include "ps/CLogger.h" #include "ps/ConfigDB.h" +#include "ps/Pyrogenesis.h" #include "scriptinterface/ScriptInterface.h" //debug @@ -97,7 +98,7 @@ XmppClient::XmppClient(const std::string& sUsername, const std::string& sPasswor m_client->registerConnectionListener(this); m_client->setPresence(gloox::Presence::Available, -1); - m_client->disco()->setVersion("Pyrogenesis", "0.0.19"); + m_client->disco()->setVersion("Pyrogenesis", engine_version); m_client->disco()->setIdentity("client", "bot"); m_client->setCompression(false); diff --git a/source/ps/Pyrogenesis.cpp b/source/ps/Pyrogenesis.cpp index a5dd43f0d8..9e9e5330f1 100644 --- a/source/ps/Pyrogenesis.cpp +++ b/source/ps/Pyrogenesis.cpp @@ -24,6 +24,8 @@ #include "lib/sysdep/sysdep.h" #include "lib/svn_revision.h" +const char engine_version[] = "0.0.19"; + // convert contents of file from char to wchar_t and // append to file. static void AppendAsciiFile(FILE* out, const OsPath& pathname) @@ -54,6 +56,7 @@ static void AppendAsciiFile(FILE* out, const OsPath& pathname) void psBundleLogs(FILE* f) { fwprintf(f, L"SVN Revision: %ls\n\n", svn_revision); + fwprintf(f, L"Engine Version: %hs\n\n", engine_version); fwprintf(f, L"System info:\n\n"); OsPath path1 = psLogDir()/"system_info.txt"; diff --git a/source/ps/Pyrogenesis.h b/source/ps/Pyrogenesis.h index 81a6c10037..01aa5e4cd7 100644 --- a/source/ps/Pyrogenesis.h +++ b/source/ps/Pyrogenesis.h @@ -26,6 +26,8 @@ Standard declarations which are included in all projects. #include "lib/os_path.h" +extern const char engine_version[]; + extern void psBundleLogs(FILE* f); // set during InitVfs extern void psSetLogDir(const OsPath& logDir); // set during InitVfs extern const OsPath& psLogDir(); // used by AppHooks and engine code when reporting errors diff --git a/source/ps/SavedGame.cpp b/source/ps/SavedGame.cpp index bb6416a071..05166587fb 100644 --- a/source/ps/SavedGame.cpp +++ b/source/ps/SavedGame.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 Wildfire Games. +/* Copyright (C) 2015 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -29,6 +29,7 @@ #include "ps/Filesystem.h" #include "ps/Game.h" #include "ps/Mod.h" +#include "ps/Pyrogenesis.h" #include "scriptinterface/ScriptInterface.h" #include "simulation2/Simulation2.h" @@ -86,6 +87,7 @@ Status SavedGames::Save(const std::wstring& name, const std::wstring& descriptio simulation.GetScriptInterface().Eval("({})", &metadata); simulation.GetScriptInterface().SetProperty(metadata, "version_major", SAVED_GAME_VERSION_MAJOR); simulation.GetScriptInterface().SetProperty(metadata, "version_minor", SAVED_GAME_VERSION_MINOR); + simulation.GetScriptInterface().SetProperty(metadata, "engine_version", std::string(engine_version)); simulation.GetScriptInterface().SetProperty(metadata, "mods", g_modsLoaded); simulation.GetScriptInterface().SetProperty(metadata, "time", (double)now); simulation.GetScriptInterface().SetProperty(metadata, "player", playerID); @@ -300,7 +302,8 @@ JS::Value SavedGames::GetEngineInfo(ScriptInterface& scriptInterface) scriptInterface.Eval("({})", &metainfo); scriptInterface.SetProperty(metainfo, "version_major", SAVED_GAME_VERSION_MAJOR); scriptInterface.SetProperty(metainfo, "version_minor", SAVED_GAME_VERSION_MINOR); - scriptInterface.SetProperty(metainfo, "mods" , g_modsLoaded); + scriptInterface.SetProperty(metainfo, "engine_version", std::string(engine_version)); + scriptInterface.SetProperty(metainfo, "mods", g_modsLoaded); return metainfo; }