Merge branch 'develop' of github-softcoder-megaglest:MegaGlest/megaglest-source into develop

This commit is contained in:
SoftCoder 2014-11-18 21:40:12 -08:00
commit 5676a055ba
10 changed files with 97 additions and 79 deletions

View File

@ -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);

View File

@ -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();

View File

@ -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;

View File

@ -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);

View File

@ -41,6 +41,7 @@ private:
GraphicLabel savedGamesLabel;
GraphicLabel infoHeaderLabel;
GraphicLabel infoTextLabel;
GraphicLabel versionWarningLabel;
GraphicLine lines[2];

View File

@ -1029,56 +1029,5 @@ string FactionType::getName(bool translatedValue) const {
return lang.getTechTreeString("FactionName_" + name,name.c_str());
}
void FactionType::saveGame(XmlNode *rootNode) {
std::map<string,string> mapTagReplacements;
XmlNode *factionTypeNode = rootNode->addChild("FactionType");
// string name;
factionTypeNode->addAttribute("name",name, mapTagReplacements);
// UnitTypes unitTypes;
for(unsigned int i = 0; i < unitTypes.size(); ++i) {
XmlNode *unitTypesNode = factionTypeNode->addChild("unitTypes");
unitTypesNode->addAttribute("name",unitTypes[i].getName(false), mapTagReplacements);
}
// UpgradeTypes upgradeTypes;
for(unsigned int i = 0; i < upgradeTypes.size(); ++i) {
XmlNode *upgradeTypesNode = factionTypeNode->addChild("upgradeTypes");
upgradeTypesNode->addAttribute("name",upgradeTypes[i].getName(false), mapTagReplacements);
}
// StartingUnits startingUnits;
for(unsigned int i = 0; i < startingUnits.size(); ++i) {
XmlNode *startingUnitsNode = factionTypeNode->addChild("startingUnits");
startingUnitsNode->addAttribute("name",startingUnits[i].first->getName(false), mapTagReplacements);
startingUnitsNode->addAttribute("count",intToStr(startingUnits[i].second), mapTagReplacements);
}
// Resources startingResources;
for(unsigned int i = 0; i < startingResources.size(); ++i) {
startingResources[i].saveGame(factionTypeNode);
}
// StrSound *music;
// FactionPersonalityType personalityType;
factionTypeNode->addAttribute("personalityType",intToStr(personalityType), mapTagReplacements);
// std::map<AIBehaviorUnitCategory, std::vector<PairPUnitTypeInt> > mapAIBehaviorUnitCategories;
for(std::map<AIBehaviorUnitCategory, std::vector<PairPUnitTypeInt> >::iterator iterMap = mapAIBehaviorUnitCategories.begin();
iterMap != mapAIBehaviorUnitCategories.end(); ++iterMap) {
std::vector<PairPUnitTypeInt> &vct = iterMap->second;
for(unsigned int i = 0; i < vct.size(); ++i) {
PairPUnitTypeInt &item = vct[i];
XmlNode *mapAIBehaviorUnitCategoriesNode = factionTypeNode->addChild("mapAIBehaviorUnitCategories");
mapAIBehaviorUnitCategoriesNode->addAttribute("key",intToStr(iterMap->first), mapTagReplacements);
mapAIBehaviorUnitCategoriesNode->addAttribute("unitType",item.first->getName(false), mapTagReplacements);
mapAIBehaviorUnitCategoriesNode->addAttribute("count",intToStr(item.second), mapTagReplacements);
}
}
// std::vector<const UpgradeType*> vctAIBehaviorUpgrades;
//for(unsigned int i = 0; i < vctAIBehaviorUpgrades.size(); ++i) {
// vctAIBehaviorUpgrades[i]->saveGame(factionTypeNode);
//}
}
}}//end namespace

View File

@ -156,7 +156,6 @@ public:
void deletePixels();
bool factionUsesResourceType(const ResourceType *rt) const;
void saveGame(XmlNode *rootNode);
};
}}//end namespace

View File

@ -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<XmlNode *> 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<XmlNode *> 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();
}
}
}

View File

@ -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<typename T>

View File

@ -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<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) {
//SystemFlags::VERBOSE_MODE_ENABLED = true;