- added option to specify which game to load when loading a saved game.
- added a hotkey to save games any time during game play (F11). This saves files with a timestamp - we now keep track of the last game the user saved and if commandline does not specify a game to load it uses the last saved game
This commit is contained in:
parent
fc125bec37
commit
3eeb1ddea4
|
@ -2490,6 +2490,17 @@ void Game::keyDown(SDL_KeyboardEvent key) {
|
|||
gameCamera.setMoveY(-1);
|
||||
}
|
||||
}
|
||||
|
||||
if(isKeyPressed(configKeys.getSDLKey("SaveGame"),key) == true) {
|
||||
string file = this->saveGame(GameConstants::saveGameFilePattern);
|
||||
char szBuf[8096]="";
|
||||
sprintf(szBuf,lang.get("GameSaved","",true).c_str(),file.c_str());
|
||||
console.addLine(szBuf);
|
||||
|
||||
Config &config= Config::getInstance();
|
||||
config.setString("LastSavedGame",file);
|
||||
config.save();
|
||||
}
|
||||
}
|
||||
|
||||
//throw runtime_error("Test Error!");
|
||||
|
@ -2635,9 +2646,12 @@ void Game::keyPress(SDL_KeyboardEvent c) {
|
|||
Stats Game::quitGame() {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||
|
||||
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled == true) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled == true) {
|
||||
world.DumpWorldToLog();
|
||||
//}
|
||||
}
|
||||
//printf("Check savegame\n");
|
||||
//printf("Saving...\n");
|
||||
this->saveGame(GameConstants::saveGameFileDefault);
|
||||
|
||||
//Stats stats = *(world.getStats());
|
||||
Stats endStats;
|
||||
|
@ -3438,7 +3452,18 @@ void Game::toggleTeamColorMarker() {
|
|||
renderExtraTeamColor=renderExtraTeamColor%4;
|
||||
}
|
||||
|
||||
void Game::saveGame(string name) {
|
||||
string Game::saveGame(string name) {
|
||||
// auto name file if using saved file pattern string
|
||||
if(name == GameConstants::saveGameFilePattern) {
|
||||
time_t curTime = time(NULL);
|
||||
struct tm *loctime = localtime (&curTime);
|
||||
char szBuf2[100]="";
|
||||
strftime(szBuf2,100,"%Y%m%d_%H%M%S",loctime);
|
||||
|
||||
char szBuf[8096]="";
|
||||
sprintf(szBuf,name.c_str(),szBuf2);
|
||||
name = szBuf;
|
||||
}
|
||||
//XmlTree xmlTree(XML_XERCES_ENGINE);
|
||||
XmlTree xmlTree;
|
||||
xmlTree.init("megaglest-saved-game");
|
||||
|
@ -3595,6 +3620,8 @@ void Game::saveGame(string name) {
|
|||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Saving game to [%s]\n",saveGameFile.c_str());
|
||||
xmlTree.save(saveGameFile);
|
||||
|
||||
return saveGameFile;
|
||||
}
|
||||
|
||||
void Game::loadGame(string name,Program *programPtr,bool isMasterserverMode) {
|
||||
|
|
|
@ -229,7 +229,7 @@ public:
|
|||
|
||||
void endGame();
|
||||
|
||||
void saveGame(string name);
|
||||
string saveGame(string name);
|
||||
static void loadGame(string name,Program *programPtr,bool isMasterserverMode);
|
||||
|
||||
private:
|
||||
|
|
|
@ -126,6 +126,7 @@ public:
|
|||
static const char *application_name;
|
||||
|
||||
static const char *saveGameFileDefault;
|
||||
static const char *saveGameFilePattern;
|
||||
|
||||
// VC++ Chokes on init of non integral static types
|
||||
static const float normalMultiplier;
|
||||
|
|
|
@ -62,6 +62,7 @@ const char *GameConstants::path_ini_CacheLookupKey = "ini";
|
|||
const char *GameConstants::path_logs_CacheLookupKey = "logs";
|
||||
|
||||
const char *GameConstants::saveGameFileDefault = "megaglest-saved.xml";
|
||||
const char *GameConstants::saveGameFilePattern = "megaglest-saved_%s.xml";
|
||||
|
||||
const char *Config::glest_ini_filename = "glest.ini";
|
||||
const char *Config::glestuser_ini_filename = "glestuser.ini";
|
||||
|
|
|
@ -3313,7 +3313,26 @@ int glestMain(int argc, char** argv) {
|
|||
program->initServer(mainWindow,true,false);
|
||||
}
|
||||
else if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_AUTOSTART_LAST_SAVED_GAME])) == true) {
|
||||
program->initSavedGame(mainWindow,false);
|
||||
string fileName = "";
|
||||
int foundParamIndIndex = -1;
|
||||
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_AUTOSTART_LAST_SAVED_GAME]) + string("="),&foundParamIndIndex);
|
||||
if(foundParamIndIndex >= 0) {
|
||||
string loadfileName = argv[foundParamIndIndex];
|
||||
vector<string> paramPartTokens;
|
||||
Tokenize(loadfileName,paramPartTokens,"=");
|
||||
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
|
||||
fileName = paramPartTokens[1];
|
||||
|
||||
if(fileExists(fileName) == false) {
|
||||
char szBuf[8096]="";
|
||||
sprintf(szBuf,"File specified for loading a saved game cannot be found: [%s]",fileName.c_str());
|
||||
printf("\n\n======================================================================================\n%s\n======================================================================================\n\n\n",szBuf);
|
||||
|
||||
throw runtime_error(szBuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
program->initSavedGame(mainWindow,false,fileName);
|
||||
}
|
||||
else if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_PREVIEW_MAP])) == true) {
|
||||
int foundParamIndIndex = -1;
|
||||
|
|
|
@ -200,26 +200,33 @@ void Program::initNormal(WindowGl *window){
|
|||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
|
||||
void Program::initSavedGame(WindowGl *window,bool masterserverMode) {
|
||||
void Program::initSavedGame(WindowGl *window,bool masterserverMode, string saveGameFile) {
|
||||
MainMenu* mainMenu= NULL;
|
||||
|
||||
init(window);
|
||||
mainMenu= new MainMenu(this);
|
||||
setState(mainMenu);
|
||||
|
||||
string saveGameFile = GameConstants::saveGameFileDefault;
|
||||
if(getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) != "") {
|
||||
saveGameFile = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + saveGameFile;
|
||||
}
|
||||
else {
|
||||
string userData = Config::getInstance().getString("UserData_Root","");
|
||||
if(userData != "") {
|
||||
endPathWithSlash(userData);
|
||||
}
|
||||
saveGameFile = userData + saveGameFile;
|
||||
if(saveGameFile == "") {
|
||||
Config &config = Config::getInstance();
|
||||
saveGameFile = config.getString("LastSavedGame","");
|
||||
if(saveGameFile == "") {
|
||||
saveGameFile = GameConstants::saveGameFileDefault;
|
||||
if(getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) != "") {
|
||||
saveGameFile = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + saveGameFile;
|
||||
}
|
||||
else {
|
||||
string userData = Config::getInstance().getString("UserData_Root","");
|
||||
if(userData != "") {
|
||||
endPathWithSlash(userData);
|
||||
}
|
||||
saveGameFile = userData + saveGameFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Loading game from [%s]\n",saveGameFile.c_str());
|
||||
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Loading game from [%s]\n",saveGameFile.c_str());
|
||||
printf("Loading saved game from [%s]\n",saveGameFile.c_str());
|
||||
|
||||
Game::loadGame(saveGameFile,this,masterserverMode);
|
||||
}
|
||||
|
|
|
@ -168,7 +168,7 @@ public:
|
|||
void initNormal(WindowGl *window);
|
||||
void initServer(WindowGl *window,bool autostart=false,bool openNetworkSlots=false,bool masterserverMode=false);
|
||||
void initServer(WindowGl *window, GameSettings *settings);
|
||||
void initSavedGame(WindowGl *window,bool masterserverMode=false);
|
||||
void initSavedGame(WindowGl *window,bool masterserverMode=false,string saveGameFile="");
|
||||
void initClient(WindowGl *window, const Ip &serverIp);
|
||||
void initScenario(WindowGl *window, string autoloadScenarioName);
|
||||
|
||||
|
|
|
@ -143,7 +143,9 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) {
|
|||
printf("\n%s\t\tAutomatically starts a game with the last game",GAME_ARGS[GAME_ARG_AUTOSTART_LASTGAME]);
|
||||
printf("\n\t\t\t\tsettings you played.");
|
||||
|
||||
printf("\n%s\t\tLoads the last saved game.",GAME_ARGS[GAME_ARG_AUTOSTART_LAST_SAVED_GAME]);
|
||||
printf("\n%s=x\t\tLoads the last saved game.",GAME_ARGS[GAME_ARG_AUTOSTART_LAST_SAVED_GAME]);
|
||||
printf("\n \t\tWhere x is an optional name of the saved game file to load.");
|
||||
printf("\n \t\tIf x is not specified we load the last game that was saved.");
|
||||
|
||||
printf("\n%s=x\t\t\tAuto connect to host server at IP or hostname x",GAME_ARGS[GAME_ARG_CLIENT]);
|
||||
printf("\n%s\t\t\tAuto create a host server.",GAME_ARGS[GAME_ARG_SERVER]);
|
||||
|
|
Loading…
Reference in New Issue