From edacc25821b4522584c8d73baade8af55f4463a8 Mon Sep 17 00:00:00 2001 From: onpon4 Date: Sat, 9 Jan 2016 22:00:20 -0500 Subject: [PATCH] Fixed incomplete transition to the new save format. Had to slightly adjust the save format as well. --- src/cutscene.cpp | 6 --- src/engine.cpp | 10 ++--- src/loadSave.cpp | 106 ++++++++++++++++++++++++++++++++++------------- 3 files changed, 81 insertions(+), 41 deletions(-) diff --git a/src/cutscene.cpp b/src/cutscene.cpp index a7b2666..0d64a6d 100644 --- a/src/cutscene.cpp +++ b/src/cutscene.cpp @@ -168,12 +168,6 @@ void cutscene_init(int scene) messages[4].face = FS_SID; strcpy(messages[4].message, "I think so. I'll come up with a plan of action."); - messages[5].face = FS_SID; - strcpy(messages[5].message, "Just remember that we won't be in Spirit anymore and you may run into WEAPCO patrols while travelling."); - - messages[6].face = FS_CHRIS; - strcpy(messages[6].message, "Sounds like fun!"); - break; case 3: diff --git a/src/engine.cpp b/src/engine.cpp index a6ddf44..42f6e21 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -133,9 +133,7 @@ void engine_showError(int errorId, const char *name) } /* -This gets the user's home directory, then creates the .parallelrealities -and .parallelrealities/starfighter directories so that saves and -temporary data files can be written there. +This gets the user's home directory, then creates the config directory. */ void engine_setupConfigDirectory() { @@ -147,15 +145,15 @@ void engine_setupConfigDirectory() char dir[PATH_MAX]; strcpy(dir, ""); - sprintf(dir, "%s/.parallelrealities", userHome); + sprintf(dir, "%s/.config", userHome); if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST)) engine_showError(2, dir); - sprintf(dir, "%s/.parallelrealities/starfighter", userHome); + sprintf(dir, "%s/.config/starfighter", userHome); if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST)) engine_showError(2, dir); - sprintf(engine.configDirectory, "%s/.parallelrealities/starfighter/", userHome); + sprintf(engine.configDirectory, "%s/.config/starfighter/", userHome); } /* diff --git a/src/loadSave.cpp b/src/loadSave.cpp index d243fe4..ef08e55 100644 --- a/src/loadSave.cpp +++ b/src/loadSave.cpp @@ -31,6 +31,8 @@ a player can "Continue Current Game" and "Load Saved Game". int initSaveSlots() { char fileName[PATH_MAX]; + int system; + char stationedName[255]; int imagePos = screen->h / 3 + 50; Game tempGame; struct stat fileInfo; @@ -42,47 +44,91 @@ int initSaveSlots() //READ SAVE GAME DATA for (int i = 0 ; i <= 5 ; i++) { - sprintf(fileName, "%ssave%.2d.dat", engine.configDirectory, i); - + sprintf(fileName, "%ssave%.2d.sav", engine.configDirectory, i); fp = fopen(fileName, "rb"); - if (fp == NULL) + if (fp != NULL) { - sprintf(saveSlot[i], (i == 0 ? "AUTOSAVE (Empty)" : "Empty")); - if (engine.gameSection == SECTION_TITLE) - gfx_createTextObject(TS_SAVESLOT_0 + i, saveSlot[i], - -1, imagePos, FONT_WHITE); - } - else - { - if (i == 0) + if (fscanf(fp, "%d%*c", &game.saveFormat) < 1) { - sprintf(saveSlot[i], "AUTOSAVE"); + printf("Error: Could not determine the version of the save file.\n"); + sprintf(saveSlot[i], "Corrupt Game Data"); } else { - if (fread(&tempGame, sizeof(Game), 1, fp) != 1) + if (i == 0) { - sprintf(saveSlot[i], "Corrupt Game Data"); + sprintf(saveSlot[i], "AUTOSAVE"); } else { - sprintf(saveSlot[i], "%s, %s", systemNames[tempGame.system], - tempGame.stationedName); + if (fscanf(fp, "%*[^\n]%*c%*[^\n]%*c%d %*d %*d%*c%[^\n]%*c", &system, + stationedName) < 2) + { + sprintf(saveSlot[i], "Corrupt Game Data"); + } + else + { + sprintf(saveSlot[i], "%s, %s", systemNames[system], + stationedName); + } + } + + if (engine.gameSection == SECTION_TITLE) + gfx_createTextObject(TS_SAVESLOT_0 + i, saveSlot[i], -1, + imagePos, FONT_WHITE); + + if (stat(fileName, &fileInfo) != -1) + { + if (fileInfo.st_mtime > modTime) + {modTime = fileInfo.st_mtime; continueSaveIndex = i;} } } - - if (engine.gameSection == SECTION_TITLE) - gfx_createTextObject(TS_SAVESLOT_0 + i, saveSlot[i], -1, - imagePos, FONT_WHITE); - - if (stat(fileName, &fileInfo) != -1) - { - if (fileInfo.st_mtime > modTime) - {modTime = fileInfo.st_mtime; continueSaveIndex = i;} - } - fclose(fp); } + else + { + sprintf(fileName, "%ssave%.2d.dat", engine.configDirectory, i); + + fp = fopen(fileName, "rb"); + if (fp == NULL) + { + sprintf(saveSlot[i], (i == 0 ? "AUTOSAVE (Empty)" : "Empty")); + if (engine.gameSection == SECTION_TITLE) + gfx_createTextObject(TS_SAVESLOT_0 + i, saveSlot[i], + -1, imagePos, FONT_WHITE); + } + else + { + if (i == 0) + { + sprintf(saveSlot[i], "AUTOSAVE"); + } + else + { + if (fread(&tempGame, sizeof(Game), 1, fp) != 1) + { + sprintf(saveSlot[i], "Corrupt Game Data"); + } + else + { + sprintf(saveSlot[i], "%s, %s", systemNames[tempGame.system], + tempGame.stationedName); + } + } + + if (engine.gameSection == SECTION_TITLE) + gfx_createTextObject(TS_SAVESLOT_0 + i, saveSlot[i], -1, + imagePos, FONT_WHITE); + + if (stat(fileName, &fileInfo) != -1) + { + if (fileInfo.st_mtime > modTime) + {modTime = fileInfo.st_mtime; continueSaveIndex = i;} + } + + fclose(fp); + } + } imagePos += 20; } @@ -103,7 +149,6 @@ bool loadGame(int slot) if (fp != NULL) { if (fscanf(fp, "%d%*c", &game.saveFormat) < 1) - { printf("Error: Could not determine the version of the save file.\n"); fclose(fp); @@ -119,7 +164,7 @@ bool loadGame(int slot) &game.minPlasmaOutputLimit, &game.maxPlasmaRateLimit, &game.maxPlasmaDamageLimit, &game.maxPlasmaOutputLimit, &game.maxPlasmaAmmoLimit, &game.maxRocketAmmoLimit) < 8) || - (fscanf(fp, "%d %d %d%*c", &game.system, &game.area, + (fscanf(fp, "%d %d %d%*c%*[^\n]%*c", &game.system, &game.area, &game.stationedPlanet) < 3) || (fscanf(fp, "%d %d%*c", &game.hasWingMate1, &game.hasWingMate2) < 2) || (fscanf(fp, "%d %d %d %d%*c", &player.maxShield, @@ -226,6 +271,7 @@ void saveGame(int slot) "%d\n" "%d %d %d %d %d %d %d %d\n" "%d %d %d\n" + "%s\n" "%d %d\n" "%d %d %d %d\n" "%d %d %d\n" @@ -247,6 +293,8 @@ void saveGame(int slot) game.system, game.area, game.stationedPlanet, + game.stationedName, + game.hasWingMate1, game.hasWingMate2, player.maxShield, player.ammo[0], player.ammo[1],