mirror of
https://github.com/glest/glest-source.git
synced 2025-08-15 04:43:58 +02:00
several changes for loading saved games
allow to load older compatible save game introduced a "last backward compatible version" for loading games fixed a bug allowing to load older games
This commit is contained in:
@@ -28,6 +28,7 @@ namespace Glest { namespace Game {
|
|||||||
|
|
||||||
const char *mailString = " http://bugs.megaglest.org";
|
const char *mailString = " http://bugs.megaglest.org";
|
||||||
const string glestVersionString = "v3.10.0-dev";
|
const string glestVersionString = "v3.10.0-dev";
|
||||||
|
const string lastCompatibleSaveGameVersionString = "v3.9.0";
|
||||||
#if defined(GITVERSION)
|
#if defined(GITVERSION)
|
||||||
const string GIT_RawRev = string(GITVERSION);
|
const string GIT_RawRev = string(GITVERSION);
|
||||||
const string GIT_Rev = string("Rev: ") + string(GITVERSION);
|
const string GIT_Rev = string("Rev: ") + string(GITVERSION);
|
||||||
|
@@ -29,6 +29,7 @@ namespace Glest{ namespace Game{
|
|||||||
|
|
||||||
extern const char *mailString;
|
extern const char *mailString;
|
||||||
extern const string glestVersionString;
|
extern const string glestVersionString;
|
||||||
|
extern const string lastCompatibleSaveGameVersionString;
|
||||||
extern const string networkVersionString;
|
extern const string networkVersionString;
|
||||||
|
|
||||||
void initSpecialStrings();
|
void initSpecialStrings();
|
||||||
|
@@ -6686,7 +6686,7 @@ void Game::loadGame(string name,Program *programPtr,bool isMasterserverMode,cons
|
|||||||
|
|
||||||
Lang &lang= Lang::getInstance();
|
Lang &lang= Lang::getInstance();
|
||||||
string gameVer = versionNode->getAttribute("version")->getValue();
|
string gameVer = versionNode->getAttribute("version")->getValue();
|
||||||
if(gameVer != glestVersionString && checkVersionComptability(gameVer, glestVersionString) == false) {
|
if(gameVer != glestVersionString && checkVersionComptability(gameVer, glestVersionString) == false){
|
||||||
char szBuf[8096]="";
|
char szBuf[8096]="";
|
||||||
snprintf(szBuf,8096,lang.getString("SavedGameBadVersion").c_str(),gameVer.c_str(),glestVersionString.c_str());
|
snprintf(szBuf,8096,lang.getString("SavedGameBadVersion").c_str(),gameVer.c_str(),glestVersionString.c_str());
|
||||||
throw megaglest_runtime_error(szBuf,true);
|
throw megaglest_runtime_error(szBuf,true);
|
||||||
@@ -6747,7 +6747,10 @@ void Game::loadGame(string name,Program *programPtr,bool isMasterserverMode,cons
|
|||||||
|
|
||||||
Lang &lang= Lang::getInstance();
|
Lang &lang= Lang::getInstance();
|
||||||
string gameVer = versionNode->getAttribute("version")->getValue();
|
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]="";
|
char szBuf[8096]="";
|
||||||
snprintf(szBuf,8096,lang.getString("SavedGameBadVersion").c_str(),gameVer.c_str(),glestVersionString.c_str());
|
snprintf(szBuf,8096,lang.getString("SavedGameBadVersion").c_str(),gameVer.c_str(),glestVersionString.c_str());
|
||||||
throw megaglest_runtime_error(szBuf,true);
|
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 *selectionNode = guiNode->getChild("Selection");
|
||||||
XmlNode *statsNode = worldNode->getChild("Stats");
|
XmlNode *statsNode = worldNode->getChild("Stats");
|
||||||
XmlNode *minimapNode = worldNode->getChild("Minimap");
|
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
|
// This is explored fog of war for the host player, clear it
|
||||||
minimapNode->clearChild("fowPixmap1");
|
minimapNode->clearChild("fowPixmap1");
|
||||||
|
|
||||||
@@ -6837,7 +6846,13 @@ void Game::loadGame(string name,Program *programPtr,bool isMasterserverMode,cons
|
|||||||
newGame->tickCount = gameNode->getAttribute("tickCount")->getIntValue();
|
newGame->tickCount = gameNode->getAttribute("tickCount")->getIntValue();
|
||||||
|
|
||||||
//bool paused;
|
//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;
|
//bool gameOver;
|
||||||
newGame->gameOver = gameNode->getAttribute("gameOver")->getIntValue() != 0;
|
newGame->gameOver = gameNode->getAttribute("gameOver")->getIntValue() != 0;
|
||||||
//bool renderNetworkStatus;
|
//bool renderNetworkStatus;
|
||||||
|
@@ -85,8 +85,14 @@ MenuStateLoadGame::MenuStateLoadGame(Program *program, MainMenu *mainMenu):
|
|||||||
infoHeaderLabel.setFont3D(CoreData::getInstance().getMenuFontBig3D());
|
infoHeaderLabel.setFont3D(CoreData::getInstance().getMenuFontBig3D());
|
||||||
infoHeaderLabel.setText(lang.getString("SavegameInfo"));
|
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.registerGraphicComponent(containerName,"infoTextLabel");
|
||||||
infoTextLabel.init(550, 350);
|
infoTextLabel.init(550, 310);
|
||||||
infoTextLabel.setText("");
|
infoTextLabel.setText("");
|
||||||
|
|
||||||
abortButton.registerGraphicComponent(containerName,"abortButton");
|
abortButton.registerGraphicComponent(containerName,"abortButton");
|
||||||
@@ -337,25 +343,26 @@ void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
if(gameVer != glestVersionString && checkVersionComptability(gameVer, glestVersionString) == false) {
|
if(gameVer != glestVersionString && checkVersionComptability(gameVer, glestVersionString) == false) {
|
||||||
char szBuf[8096]="";
|
char szBuf[8096]="";
|
||||||
snprintf(szBuf,8096,lang.getString("SavedGameBadVersion").c_str(),gameVer.c_str(),glestVersionString.c_str());
|
snprintf(szBuf,8096,lang.getString("SavedGameBadVersion").c_str(),gameVer.c_str(),glestVersionString.c_str());
|
||||||
infoTextLabel.setText(szBuf);
|
versionWarningLabel.setText(szBuf);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
XmlNode *gameNode = rootNode->getChild("Game");
|
versionWarningLabel.setText("");
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
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) {
|
catch(const megaglest_runtime_error &ex) {
|
||||||
char szBuf[8096]="";
|
char szBuf[8096]="";
|
||||||
@@ -401,6 +408,8 @@ void MenuStateLoadGame::render() {
|
|||||||
renderer.renderLabel(&savedGamesLabel);
|
renderer.renderLabel(&savedGamesLabel);
|
||||||
renderer.renderLabel(&infoHeaderLabel);
|
renderer.renderLabel(&infoHeaderLabel);
|
||||||
renderer.renderLabel(&infoTextLabel);
|
renderer.renderLabel(&infoTextLabel);
|
||||||
|
if(versionWarningLabel.getText()!="")
|
||||||
|
renderer.renderLabel(&versionWarningLabel);
|
||||||
|
|
||||||
renderer.renderButton(&abortButton);
|
renderer.renderButton(&abortButton);
|
||||||
renderer.renderButton(&deleteButton);
|
renderer.renderButton(&deleteButton);
|
||||||
|
@@ -41,6 +41,7 @@ private:
|
|||||||
GraphicLabel savedGamesLabel;
|
GraphicLabel savedGamesLabel;
|
||||||
GraphicLabel infoHeaderLabel;
|
GraphicLabel infoHeaderLabel;
|
||||||
GraphicLabel infoTextLabel;
|
GraphicLabel infoTextLabel;
|
||||||
|
GraphicLabel versionWarningLabel;
|
||||||
|
|
||||||
GraphicLine lines[2];
|
GraphicLine lines[2];
|
||||||
|
|
||||||
|
@@ -1395,14 +1395,16 @@ void TotalUpgrade::loadGame(const XmlNode *rootNode) {
|
|||||||
node->getAttribute("value")->getIntValue();
|
node->getAttribute("value")->getIntValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
attackSpeed = upgradeTypeBaseNode->getAttribute("attackSpeed")->getIntValue();
|
if(upgradeTypeBaseNode->hasAttribute("attackSpeed")){
|
||||||
attackSpeedIsMultiplier = upgradeTypeBaseNode->getAttribute("attackSpeedIsMultiplier")->getIntValue() != 0;
|
attackSpeed = upgradeTypeBaseNode->getAttribute("attackSpeed")->getIntValue();
|
||||||
vector<XmlNode *> attackSpeedIsMultiplierValueNodeList = upgradeTypeBaseNode->getChildList("attackSpeedIsMultiplierValueList");
|
attackSpeedIsMultiplier = upgradeTypeBaseNode->getAttribute("attackSpeedIsMultiplier")->getIntValue() != 0;
|
||||||
for(unsigned int i = 0; i < attackSpeedIsMultiplierValueNodeList.size(); ++i) {
|
vector<XmlNode *> attackSpeedIsMultiplierValueNodeList = upgradeTypeBaseNode->getChildList("attackSpeedIsMultiplierValueList");
|
||||||
XmlNode *node = attackSpeedIsMultiplierValueNodeList[i];
|
for(unsigned int i = 0; i < attackSpeedIsMultiplierValueNodeList.size(); ++i) {
|
||||||
|
XmlNode *node = attackSpeedIsMultiplierValueNodeList[i];
|
||||||
|
|
||||||
attackSpeedIsMultiplierValueList[node->getAttribute("key")->getValue()] =
|
attackSpeedIsMultiplierValueList[node->getAttribute("key")->getValue()] =
|
||||||
node->getAttribute("value")->getIntValue();
|
node->getAttribute("value")->getIntValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -239,6 +239,9 @@ float saturate(float value);
|
|||||||
int round(float f);
|
int round(float f);
|
||||||
|
|
||||||
//misc
|
//misc
|
||||||
|
int compareMajorMinorVersion(string versionA,string versionB);
|
||||||
|
int getMajor(string version);
|
||||||
|
int getMinor(string version);
|
||||||
bool checkVersionComptability(string clientVersionString, string serverVersionString);
|
bool checkVersionComptability(string clientVersionString, string serverVersionString);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@@ -787,6 +787,44 @@ int round(float f){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ==================== misc ====================
|
// ==================== 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<majorB) return -1;
|
||||||
|
else if(majorA==majorB){
|
||||||
|
if(minorA<minorB) return -1;
|
||||||
|
else if(minorA==minorB){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int getMajor(string version){
|
||||||
|
vector<string> 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<string> 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) {
|
bool checkVersionComptability(string clientVersionString, string serverVersionString) {
|
||||||
//SystemFlags::VERBOSE_MODE_ENABLED = true;
|
//SystemFlags::VERBOSE_MODE_ENABLED = true;
|
||||||
|
Reference in New Issue
Block a user