diff --git a/source/glest_game/facilities/game_util.cpp b/source/glest_game/facilities/game_util.cpp index 55f8e3ec..bd58e079 100644 --- a/source/glest_game/facilities/game_util.cpp +++ b/source/glest_game/facilities/game_util.cpp @@ -28,6 +28,7 @@ namespace Glest { namespace Game { const char *mailString = " http://bugs.megaglest.org"; const string glestVersionString = "v3.10.0-dev"; +const string lastCompatibleSaveGameVersionString = "v3.9.0"; #if defined(GITVERSION) const string GIT_RawRev = string(GITVERSION); const string GIT_Rev = string("Rev: ") + string(GITVERSION); diff --git a/source/glest_game/facilities/game_util.h b/source/glest_game/facilities/game_util.h index 059c74ea..6c27e85b 100644 --- a/source/glest_game/facilities/game_util.h +++ b/source/glest_game/facilities/game_util.h @@ -29,6 +29,7 @@ namespace Glest{ namespace Game{ extern const char *mailString; extern const string glestVersionString; +extern const string lastCompatibleSaveGameVersionString; extern const string networkVersionString; void initSpecialStrings(); diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index b8c8ef2e..1cbb15fc 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -6686,7 +6686,7 @@ void Game::loadGame(string name,Program *programPtr,bool isMasterserverMode,cons Lang &lang= Lang::getInstance(); string gameVer = versionNode->getAttribute("version")->getValue(); - if(gameVer != glestVersionString && checkVersionComptability(gameVer, glestVersionString) == false) { + if(gameVer != glestVersionString && checkVersionComptability(gameVer, glestVersionString) == false){ char szBuf[8096]=""; snprintf(szBuf,8096,lang.getString("SavedGameBadVersion").c_str(),gameVer.c_str(),glestVersionString.c_str()); throw megaglest_runtime_error(szBuf,true); @@ -6747,7 +6747,10 @@ void Game::loadGame(string name,Program *programPtr,bool isMasterserverMode,cons Lang &lang= Lang::getInstance(); string gameVer = versionNode->getAttribute("version")->getValue(); - if(gameVer != glestVersionString && checkVersionComptability(gameVer, glestVersionString) == false) { + // this is the version check for loading normal save games from menu_state_load_game + if (gameVer != glestVersionString + && (compareMajorMinorVersion(gameVer, lastCompatibleSaveGameVersionString) < 0 + || compareMajorMinorVersion(glestVersionString, gameVer) < 0)) { char szBuf[8096]=""; snprintf(szBuf,8096,lang.getString("SavedGameBadVersion").c_str(),gameVer.c_str(),glestVersionString.c_str()); throw megaglest_runtime_error(szBuf,true); @@ -6765,6 +6768,12 @@ void Game::loadGame(string name,Program *programPtr,bool isMasterserverMode,cons XmlNode *selectionNode = guiNode->getChild("Selection"); XmlNode *statsNode = worldNode->getChild("Stats"); XmlNode *minimapNode = worldNode->getChild("Minimap"); + + if(gameVer != glestVersionString && checkVersionComptability(gameVer, glestVersionString) == false){ + char szBuf[8096]=""; + snprintf(szBuf,8096,lang.getString("SavedGameBadVersion").c_str(),gameVer.c_str(),glestVersionString.c_str()); + throw megaglest_runtime_error(szBuf,true); + } // This is explored fog of war for the host player, clear it minimapNode->clearChild("fowPixmap1"); @@ -6837,7 +6846,13 @@ void Game::loadGame(string name,Program *programPtr,bool isMasterserverMode,cons newGame->tickCount = gameNode->getAttribute("tickCount")->getIntValue(); //bool paused; - newGame->paused = gameNode->getAttribute("paused")->getIntValue() != 0; + if(newGame->inJoinGameLoading==true){ + newGame->paused = gameNode->getAttribute("paused")->getIntValue() != 0; + }else{ + //newGame->paused = gameNode->getAttribute("paused")->getIntValue() != 0; + newGame->paused = true; + } + if(newGame->paused) newGame->console.addLine(lang.getString("GamePaused")); //bool gameOver; newGame->gameOver = gameNode->getAttribute("gameOver")->getIntValue() != 0; //bool renderNetworkStatus; diff --git a/source/glest_game/menu/menu_state_load_game.cpp b/source/glest_game/menu/menu_state_load_game.cpp index dc214e63..f871e5ba 100644 --- a/source/glest_game/menu/menu_state_load_game.cpp +++ b/source/glest_game/menu/menu_state_load_game.cpp @@ -85,8 +85,14 @@ MenuStateLoadGame::MenuStateLoadGame(Program *program, MainMenu *mainMenu): infoHeaderLabel.setFont3D(CoreData::getInstance().getMenuFontBig3D()); infoHeaderLabel.setText(lang.getString("SavegameInfo")); + versionWarningLabel.registerGraphicComponent(containerName,"versionWarningLabel"); + versionWarningLabel.init(550, 350); + versionWarningLabel.setText(""); + versionWarningLabel.setTextColor(Vec3f(1.0f,0.5f,0.5f)); + + infoTextLabel.registerGraphicComponent(containerName,"infoTextLabel"); - infoTextLabel.init(550, 350); + infoTextLabel.init(550, 310); infoTextLabel.setText(""); abortButton.registerGraphicComponent(containerName,"abortButton"); @@ -337,25 +343,26 @@ void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){ if(gameVer != glestVersionString && checkVersionComptability(gameVer, glestVersionString) == false) { char szBuf[8096]=""; snprintf(szBuf,8096,lang.getString("SavedGameBadVersion").c_str(),gameVer.c_str(),glestVersionString.c_str()); - infoTextLabel.setText(szBuf); + versionWarningLabel.setText(szBuf); } else { - XmlNode *gameNode = rootNode->getChild("Game"); - GameSettings newGameSettings; - newGameSettings.loadGame(gameNode); - - char szBuf[8096]=""; - snprintf(szBuf,8096,lang.getString("LoadSavedGameInfo").c_str(), - newGameSettings.getMap().c_str(), - newGameSettings.getTileset().c_str(), - newGameSettings.getTech().c_str(), - newGameSettings.getScenario().c_str(), - newGameSettings.getFactionCount(), - (newGameSettings.getThisFactionIndex() >= 0 && - newGameSettings.getThisFactionIndex() < newGameSettings.getFactionCount() ? - newGameSettings.getFactionTypeName(newGameSettings.getThisFactionIndex()).c_str() : "")); - infoTextLabel.setText(szBuf); + versionWarningLabel.setText(""); } + XmlNode *gameNode = rootNode->getChild("Game"); + GameSettings newGameSettings; + newGameSettings.loadGame(gameNode); + + char szBuf[8096]=""; + snprintf(szBuf,8096,lang.getString("LoadSavedGameInfo").c_str(), + newGameSettings.getMap().c_str(), + newGameSettings.getTileset().c_str(), + newGameSettings.getTech().c_str(), + newGameSettings.getScenario().c_str(), + newGameSettings.getFactionCount(), + (newGameSettings.getThisFactionIndex() >= 0 && + newGameSettings.getThisFactionIndex() < newGameSettings.getFactionCount() ? + newGameSettings.getFactionTypeName(newGameSettings.getThisFactionIndex()).c_str() : "")); + infoTextLabel.setText(szBuf); } catch(const megaglest_runtime_error &ex) { char szBuf[8096]=""; @@ -401,6 +408,8 @@ void MenuStateLoadGame::render() { renderer.renderLabel(&savedGamesLabel); renderer.renderLabel(&infoHeaderLabel); renderer.renderLabel(&infoTextLabel); + if(versionWarningLabel.getText()!="") + renderer.renderLabel(&versionWarningLabel); renderer.renderButton(&abortButton); renderer.renderButton(&deleteButton); diff --git a/source/glest_game/menu/menu_state_load_game.h b/source/glest_game/menu/menu_state_load_game.h index 84e0d16f..eeeb146e 100644 --- a/source/glest_game/menu/menu_state_load_game.h +++ b/source/glest_game/menu/menu_state_load_game.h @@ -41,6 +41,7 @@ private: GraphicLabel savedGamesLabel; GraphicLabel infoHeaderLabel; GraphicLabel infoTextLabel; + GraphicLabel versionWarningLabel; GraphicLine lines[2]; diff --git a/source/glest_game/types/upgrade_type.cpp b/source/glest_game/types/upgrade_type.cpp index 78ad754a..dcb22d5b 100644 --- a/source/glest_game/types/upgrade_type.cpp +++ b/source/glest_game/types/upgrade_type.cpp @@ -1395,14 +1395,16 @@ void TotalUpgrade::loadGame(const XmlNode *rootNode) { node->getAttribute("value")->getIntValue(); } - attackSpeed = upgradeTypeBaseNode->getAttribute("attackSpeed")->getIntValue(); - attackSpeedIsMultiplier = upgradeTypeBaseNode->getAttribute("attackSpeedIsMultiplier")->getIntValue() != 0; - vector attackSpeedIsMultiplierValueNodeList = upgradeTypeBaseNode->getChildList("attackSpeedIsMultiplierValueList"); - for(unsigned int i = 0; i < attackSpeedIsMultiplierValueNodeList.size(); ++i) { - XmlNode *node = attackSpeedIsMultiplierValueNodeList[i]; + if(upgradeTypeBaseNode->hasAttribute("attackSpeed")){ + attackSpeed = upgradeTypeBaseNode->getAttribute("attackSpeed")->getIntValue(); + attackSpeedIsMultiplier = upgradeTypeBaseNode->getAttribute("attackSpeedIsMultiplier")->getIntValue() != 0; + vector attackSpeedIsMultiplierValueNodeList = upgradeTypeBaseNode->getChildList("attackSpeedIsMultiplierValueList"); + for(unsigned int i = 0; i < attackSpeedIsMultiplierValueNodeList.size(); ++i) { + XmlNode *node = attackSpeedIsMultiplierValueNodeList[i]; - attackSpeedIsMultiplierValueList[node->getAttribute("key")->getValue()] = - node->getAttribute("value")->getIntValue(); + attackSpeedIsMultiplierValueList[node->getAttribute("key")->getValue()] = + node->getAttribute("value")->getIntValue(); + } } } diff --git a/source/shared_lib/include/util/util.h b/source/shared_lib/include/util/util.h index b6306bc2..5e3c0c7c 100644 --- a/source/shared_lib/include/util/util.h +++ b/source/shared_lib/include/util/util.h @@ -239,6 +239,9 @@ float saturate(float value); int round(float f); //misc +int compareMajorMinorVersion(string versionA,string versionB); +int getMajor(string version); +int getMinor(string version); bool checkVersionComptability(string clientVersionString, string serverVersionString); template diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index 5142acea..56c28904 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -787,6 +787,44 @@ int round(float f){ } // ==================== misc ==================== +int compareMajorMinorVersion(string versionA,string versionB){ + int majorA=getMajor(versionA); + int minorA=getMinor(versionA); + int majorB=getMajor(versionB); + int minorB=getMinor(versionB); + + if(majorA parts=split(version.substr(1),"."); + + if(parts.size()>2 && parts[0] != "" && IsNumeric(parts[0].c_str(),false)) + return strToInt(parts[0]); + else + return 0; +} + +int getMinor(string version){ + vector parts=split(version.substr(1),"."); + + if(parts.size()>2 && parts[1] != "" && IsNumeric(parts[1].c_str(),false)) + return strToInt(parts[1]); + else + return 0; +} bool checkVersionComptability(string clientVersionString, string serverVersionString) { //SystemFlags::VERBOSE_MODE_ENABLED = true;