Added a difficulty indicator to save slots, removed old format support

This commit is contained in:
Layla Marchant 2020-05-26 22:20:38 -04:00
parent 9a627a77bb
commit b3856c6a3c
2 changed files with 41 additions and 84 deletions

View File

@ -26,9 +26,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "structs.h" #include "structs.h"
typedef struct Game_ { typedef struct Game_ {
Object thePlayer;
Object playerWeapon;
int saveFormat; int saveFormat;
int difficulty; int difficulty;
@ -73,8 +70,8 @@ typedef struct Game_ {
int stationedPlanet; int stationedPlanet;
int destinationPlanet; int destinationPlanet;
char stationedName[20]; char stationedName[STRMAX_SHORT];
char destinationName[20]; char destinationName[STRMAX_SHORT];
double distanceCovered; double distanceCovered;
int minPlasmaRate; int minPlasmaRate;

View File

@ -48,9 +48,10 @@ int save_initSlots()
{ {
char fileName[PATH_MAX]; char fileName[PATH_MAX];
int system; int system;
char stationedName[STRMAX]; char stationedName[STRMAX_SHORT];
int difficulty;
char difficulty_text[STRMAX_SHORT];
int imagePos = 0; int imagePos = 0;
Game tempGame;
struct stat fileInfo; struct stat fileInfo;
int modTime = 0; int modTime = 0;
int continueSaveIndex = -1; int continueSaveIndex = -1;
@ -78,15 +79,33 @@ int save_initSlots()
} }
else else
{ {
if (fscanf(fp, "%*[^\n]%*c%*[^\n]%*c%d %*d %*d%*c%[^\n]%*c", &system, switch (game.saveFormat)
stationedName) < 2)
{ {
strcpy(saveSlot[i], _("Corrupt Game Data")); case 4:
} case 5:
else if (fscanf(fp,
{ "%d%*c"
snprintf(saveSlot[i], STRMAX_SHORT, "%s, %s", game_systemNames[system], "%*[^\n]%*c"
stationedName); "%d %*d %*d%*c%"
"[^\n]%*c",
&difficulty, &system,
stationedName) < 2)
{
strcpy(saveSlot[i], _("Corrupt Game Data"));
}
else
{
if (game.saveFormat == 4)
difficulty += DIFFICULTY_EASY;
game_getDifficultyText(difficulty_text, difficulty);
snprintf(saveSlot[i], STRMAX_SHORT,
"%s, %s (%s)", game_systemNames[system],
stationedName, difficulty_text);
}
break;
default:
strcpy(saveSlot[i], _("Corrupt Game Data"));
} }
} }
@ -104,49 +123,11 @@ int save_initSlots()
} }
else else
{ {
snprintf(fileName, PATH_MAX, "%ssave%.2d.dat", engine.configDirectory, i); /// Used for empty save slots.
strcpy(saveSlot[i], (i == 0 ? _("AUTOSAVE (Empty)") : _("Empty")));
fp = fopen(fileName, "r"); if (engine.gameSection == SECTION_TITLE)
if (fp == NULL) gfx_createTextObject(TS_SAVESLOT_0 + i, saveSlot[i],
{ 0, imagePos, FONT_WHITE);
/// Used for empty save slots.
strcpy(saveSlot[i], (i == 0 ? _("AUTOSAVE (Empty)") : _("Empty")));
if (engine.gameSection == SECTION_TITLE)
gfx_createTextObject(TS_SAVESLOT_0 + i, saveSlot[i],
0, imagePos, FONT_WHITE);
}
else
{
if (i == 0)
{
strcpy(saveSlot[i], _("AUTOSAVE"));
continueSaveIndex = 0;
}
else
{
if (fread(&tempGame, sizeof(Game), 1, fp) != 1)
{
strcpy(saveSlot[i], _("Corrupt Game Data"));
}
else
{
snprintf(saveSlot[i], STRMAX_SHORT, "%s, %s", game_systemNames[tempGame.system],
tempGame.stationedName);
}
}
if (engine.gameSection == SECTION_TITLE)
gfx_createTextObject(TS_SAVESLOT_0 + i, saveSlot[i], 0,
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;
} }
@ -178,6 +159,7 @@ int save_load(int slot)
switch (game.saveFormat) switch (game.saveFormat)
{ {
case 4: case 4:
case 5:
if ((fscanf(fp, "%d%*c", &game.difficulty) < 1) || if ((fscanf(fp, "%d%*c", &game.difficulty) < 1) ||
(fscanf(fp, "%d %d %d %d %d %d %d %d%*c", (fscanf(fp, "%d %d %d %d %d %d %d %d%*c",
&game.minPlasmaRateLimit, &game.minPlasmaDamageLimit, &game.minPlasmaRateLimit, &game.minPlasmaDamageLimit,
@ -220,6 +202,8 @@ int save_load(int slot)
else else
{ {
game.timeTaken = (Uint32)(timeTaken); game.timeTaken = (Uint32)(timeTaken);
if (game.saveFormat == 4)
game.difficulty += DIFFICULTY_EASY;
} }
game.destinationPlanet = game.stationedPlanet; game.destinationPlanet = game.stationedPlanet;
break; break;
@ -233,31 +217,7 @@ int save_load(int slot)
} }
else else
{ {
snprintf(filename, PATH_MAX, "%ssave%.2d.dat", engine.configDirectory, slot); return 0;
fp = fopen(filename, "rb");
if (fp == NULL)
return 0;
if (fread(&game, sizeof(Game), 1, fp) != 1)
{
printf("Save game error. The file was not of the expected format.\n");
fclose(fp);
return 0;
}
fclose(fp);
if (game.saveFormat < 2)
game.difficulty = DIFFICULTY_NORMAL;
weapons[W_PLAYER_WEAPON] = game.playerWeapon;
weapons[W_PLAYER_WEAPON].imageIndex[0] = SP_PLASMA_GREEN;
weapons[W_PLAYER_WEAPON].imageIndex[1] = SP_PLASMA_GREEN;
player = game.thePlayer;
save(slot);
remove(filename);
} }
// Re-init all the planets in this system... // Re-init all the planets in this system...
@ -285,7 +245,7 @@ void save(int slot)
fp = fopen(fileName, "w"); fp = fopen(fileName, "w");
game.saveFormat = 4; game.saveFormat = 5;
for (int i = 0 ; i < MAX_PLANETS ; i++) for (int i = 0 ; i < MAX_PLANETS ; i++)
game.missionCompleted[i] = intermission_planets[i].missionCompleted; game.missionCompleted[i] = intermission_planets[i].missionCompleted;