Fixed incomplete transition to the new save format.

Had to slightly adjust the save format as well.
This commit is contained in:
onpon4 2016-01-09 22:00:20 -05:00
parent b66bb4bf98
commit edacc25821
3 changed files with 81 additions and 41 deletions

View File

@ -168,12 +168,6 @@ void cutscene_init(int scene)
messages[4].face = FS_SID; messages[4].face = FS_SID;
strcpy(messages[4].message, "I think so. I'll come up with a plan of action."); 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; break;
case 3: case 3:

View File

@ -133,9 +133,7 @@ void engine_showError(int errorId, const char *name)
} }
/* /*
This gets the user's home directory, then creates the .parallelrealities This gets the user's home directory, then creates the config directory.
and .parallelrealities/starfighter directories so that saves and
temporary data files can be written there.
*/ */
void engine_setupConfigDirectory() void engine_setupConfigDirectory()
{ {
@ -147,15 +145,15 @@ void engine_setupConfigDirectory()
char dir[PATH_MAX]; char dir[PATH_MAX];
strcpy(dir, ""); 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)) if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST))
engine_showError(2, dir); 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)) if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST))
engine_showError(2, dir); engine_showError(2, dir);
sprintf(engine.configDirectory, "%s/.parallelrealities/starfighter/", userHome); sprintf(engine.configDirectory, "%s/.config/starfighter/", userHome);
} }
/* /*

View File

@ -31,6 +31,8 @@ a player can "Continue Current Game" and "Load Saved Game".
int initSaveSlots() int initSaveSlots()
{ {
char fileName[PATH_MAX]; char fileName[PATH_MAX];
int system;
char stationedName[255];
int imagePos = screen->h / 3 + 50; int imagePos = screen->h / 3 + 50;
Game tempGame; Game tempGame;
struct stat fileInfo; struct stat fileInfo;
@ -42,47 +44,91 @@ int initSaveSlots()
//READ SAVE GAME DATA //READ SAVE GAME DATA
for (int i = 0 ; i <= 5 ; i++) 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"); fp = fopen(fileName, "rb");
if (fp == NULL) if (fp != NULL)
{ {
sprintf(saveSlot[i], (i == 0 ? "AUTOSAVE (Empty)" : "Empty")); if (fscanf(fp, "%d%*c", &game.saveFormat) < 1)
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"); printf("Error: Could not determine the version of the save file.\n");
sprintf(saveSlot[i], "Corrupt Game Data");
} }
else else
{ {
if (fread(&tempGame, sizeof(Game), 1, fp) != 1) if (i == 0)
{ {
sprintf(saveSlot[i], "Corrupt Game Data"); sprintf(saveSlot[i], "AUTOSAVE");
} }
else else
{ {
sprintf(saveSlot[i], "%s, %s", systemNames[tempGame.system], if (fscanf(fp, "%*[^\n]%*c%*[^\n]%*c%d %*d %*d%*c%[^\n]%*c", &system,
tempGame.stationedName); 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); 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; imagePos += 20;
} }
@ -103,7 +149,6 @@ bool loadGame(int slot)
if (fp != NULL) if (fp != NULL)
{ {
if (fscanf(fp, "%d%*c", &game.saveFormat) < 1) if (fscanf(fp, "%d%*c", &game.saveFormat) < 1)
{ {
printf("Error: Could not determine the version of the save file.\n"); printf("Error: Could not determine the version of the save file.\n");
fclose(fp); fclose(fp);
@ -119,7 +164,7 @@ bool loadGame(int slot)
&game.minPlasmaOutputLimit, &game.maxPlasmaRateLimit, &game.minPlasmaOutputLimit, &game.maxPlasmaRateLimit,
&game.maxPlasmaDamageLimit, &game.maxPlasmaOutputLimit, &game.maxPlasmaDamageLimit, &game.maxPlasmaOutputLimit,
&game.maxPlasmaAmmoLimit, &game.maxRocketAmmoLimit) < 8) || &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) || &game.stationedPlanet) < 3) ||
(fscanf(fp, "%d %d%*c", &game.hasWingMate1, &game.hasWingMate2) < 2) || (fscanf(fp, "%d %d%*c", &game.hasWingMate1, &game.hasWingMate2) < 2) ||
(fscanf(fp, "%d %d %d %d%*c", &player.maxShield, (fscanf(fp, "%d %d %d %d%*c", &player.maxShield,
@ -226,6 +271,7 @@ void saveGame(int slot)
"%d\n" "%d\n"
"%d %d %d %d %d %d %d %d\n" "%d %d %d %d %d %d %d %d\n"
"%d %d %d\n" "%d %d %d\n"
"%s\n"
"%d %d\n" "%d %d\n"
"%d %d %d %d\n" "%d %d %d %d\n"
"%d %d %d\n" "%d %d %d\n"
@ -247,6 +293,8 @@ void saveGame(int slot)
game.system, game.area, game.stationedPlanet, game.system, game.area, game.stationedPlanet,
game.stationedName,
game.hasWingMate1, game.hasWingMate2, game.hasWingMate1, game.hasWingMate2,
player.maxShield, player.ammo[0], player.ammo[1], player.maxShield, player.ammo[0], player.ammo[1],