2011-08-24 14:14:44 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2003 Parallel Realities
|
2015-03-01 21:37:32 +01:00
|
|
|
Copyright (C) 2011, 2012, 2013 Guus Sliepen
|
2019-05-22 00:47:32 +02:00
|
|
|
Copyright (C) 2015-2019 Julie Marchant <onpon4@riseup.net>
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
2015-02-26 17:20:36 +01:00
|
|
|
as published by the Free Software Foundation; either version 3
|
2011-08-24 14:14:44 +02:00
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-02-26 17:20:36 +01:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2015-02-26 17:20:36 +01:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-08-24 14:14:44 +02:00
|
|
|
*/
|
|
|
|
|
2017-01-25 16:48:29 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include "SDL.h"
|
2011-08-26 21:29:04 +02:00
|
|
|
|
2016-11-26 00:21:31 +01:00
|
|
|
#include "defs.h"
|
|
|
|
#include "structs.h"
|
|
|
|
|
2017-01-25 16:48:29 +01:00
|
|
|
#include "engine.h"
|
|
|
|
#include "game.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "intermission.h"
|
|
|
|
#include "player.h"
|
2017-02-04 21:42:59 +01:00
|
|
|
#include "save.h"
|
2017-01-25 16:48:29 +01:00
|
|
|
#include "screen.h"
|
|
|
|
#include "weapons.h"
|
|
|
|
|
2011-08-26 21:29:04 +02:00
|
|
|
static char saveSlot[10][25];
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Reads in each save game that it finds and gives it an appropriate
|
|
|
|
description using the area variable contained in the game binary
|
|
|
|
data. It returns the slot number (1 - 10) of the most recently
|
|
|
|
used file. On the title screen, this is used to determine whether
|
|
|
|
a player can "Continue Current Game" and "Load Saved Game".
|
|
|
|
*/
|
2016-11-17 01:43:03 +01:00
|
|
|
int save_initSlots()
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
char fileName[PATH_MAX];
|
2016-01-10 04:00:20 +01:00
|
|
|
int system;
|
2019-06-02 17:28:26 +02:00
|
|
|
char stationedName[STRMAX];
|
2019-06-02 00:16:32 +02:00
|
|
|
int imagePos = 0;
|
2011-08-24 14:14:44 +02:00
|
|
|
Game tempGame;
|
|
|
|
struct stat fileInfo;
|
|
|
|
int modTime = 0;
|
2016-01-10 04:26:31 +01:00
|
|
|
int continueSaveIndex = -1;
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
//READ SAVE GAME DATA
|
2015-03-03 05:32:48 +01:00
|
|
|
for (int i = 0 ; i <= 5 ; i++)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2016-01-10 04:00:20 +01:00
|
|
|
sprintf(fileName, "%ssave%.2d.sav", engine.configDirectory, i);
|
2017-03-28 16:35:11 +02:00
|
|
|
fp = fopen(fileName, "r");
|
2016-01-10 04:00:20 +01:00
|
|
|
if (fp != NULL)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2016-01-10 04:00:20 +01:00
|
|
|
if (fscanf(fp, "%d%*c", &game.saveFormat) < 1)
|
|
|
|
{
|
|
|
|
printf("Error: Could not determine the version of the save file.\n");
|
|
|
|
sprintf(saveSlot[i], "Corrupt Game Data");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
sprintf(saveSlot[i], "AUTOSAVE");
|
2016-01-10 04:26:31 +01:00
|
|
|
continueSaveIndex = 0;
|
2016-01-10 04:00:20 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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)
|
2019-06-02 00:16:32 +02:00
|
|
|
gfx_createTextObject(TS_SAVESLOT_0 + i, saveSlot[i], 0,
|
2016-01-10 04:00:20 +01:00
|
|
|
imagePos, FONT_WHITE);
|
|
|
|
|
|
|
|
if (stat(fileName, &fileInfo) != -1)
|
|
|
|
{
|
|
|
|
if (fileInfo.st_mtime > modTime)
|
|
|
|
{modTime = fileInfo.st_mtime; continueSaveIndex = i;}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fp);
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-10 04:00:20 +01:00
|
|
|
sprintf(fileName, "%ssave%.2d.dat", engine.configDirectory, i);
|
|
|
|
|
2017-03-28 16:35:11 +02:00
|
|
|
fp = fopen(fileName, "r");
|
2016-01-10 04:00:20 +01:00
|
|
|
if (fp == NULL)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2016-01-10 04:00:20 +01:00
|
|
|
sprintf(saveSlot[i], (i == 0 ? "AUTOSAVE (Empty)" : "Empty"));
|
|
|
|
if (engine.gameSection == SECTION_TITLE)
|
|
|
|
gfx_createTextObject(TS_SAVESLOT_0 + i, saveSlot[i],
|
2019-06-02 00:16:32 +02:00
|
|
|
0, imagePos, FONT_WHITE);
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-10 04:00:20 +01:00
|
|
|
if (i == 0)
|
2015-03-03 05:32:48 +01:00
|
|
|
{
|
2016-01-10 04:00:20 +01:00
|
|
|
sprintf(saveSlot[i], "AUTOSAVE");
|
2016-01-10 04:26:31 +01:00
|
|
|
continueSaveIndex = 0;
|
2015-03-03 05:32:48 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-10 04:00:20 +01:00
|
|
|
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);
|
|
|
|
}
|
2015-03-03 05:32:48 +01:00
|
|
|
}
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2016-01-10 04:00:20 +01:00
|
|
|
if (engine.gameSection == SECTION_TITLE)
|
2019-06-02 00:16:32 +02:00
|
|
|
gfx_createTextObject(TS_SAVESLOT_0 + i, saveSlot[i], 0,
|
2016-01-10 04:00:20 +01:00
|
|
|
imagePos, FONT_WHITE);
|
2015-03-03 05:32:48 +01:00
|
|
|
|
2016-01-10 04:00:20 +01:00
|
|
|
if (stat(fileName, &fileInfo) != -1)
|
|
|
|
{
|
|
|
|
if (fileInfo.st_mtime > modTime)
|
|
|
|
{modTime = fileInfo.st_mtime; continueSaveIndex = i;}
|
|
|
|
}
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2016-01-10 04:00:20 +01:00
|
|
|
fclose(fp);
|
|
|
|
}
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
imagePos += 20;
|
|
|
|
}
|
|
|
|
|
|
|
|
return continueSaveIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Fill in later...
|
|
|
|
*/
|
2016-11-17 01:43:03 +01:00
|
|
|
int save_load(int slot)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2016-01-10 01:58:07 +01:00
|
|
|
char filename[PATH_MAX];
|
|
|
|
FILE *fp;
|
2016-01-12 20:03:08 +01:00
|
|
|
unsigned long timeTaken;
|
2016-01-09 03:33:40 +01:00
|
|
|
|
2016-01-10 01:58:07 +01:00
|
|
|
sprintf(filename, "%ssave%.2d.sav", engine.configDirectory, slot);
|
2017-03-28 16:35:11 +02:00
|
|
|
fp = fopen(filename, "r");
|
2016-01-09 03:33:40 +01:00
|
|
|
|
2016-01-10 01:58:07 +01:00
|
|
|
if (fp != NULL)
|
2016-01-09 03:33:40 +01:00
|
|
|
{
|
2016-01-10 01:58:07 +01:00
|
|
|
if (fscanf(fp, "%d%*c", &game.saveFormat) < 1)
|
2016-01-09 03:33:40 +01:00
|
|
|
{
|
2016-01-10 01:58:07 +01:00
|
|
|
printf("Error: Could not determine the version of the save file.\n");
|
|
|
|
fclose(fp);
|
2016-11-17 01:43:03 +01:00
|
|
|
return 0;
|
2016-01-09 03:33:40 +01:00
|
|
|
}
|
|
|
|
|
2016-01-10 01:58:07 +01:00
|
|
|
switch (game.saveFormat)
|
|
|
|
{
|
|
|
|
case 4:
|
|
|
|
if ((fscanf(fp, "%d%*c", &game.difficulty) < 1) ||
|
|
|
|
(fscanf(fp, "%d %d %d %d %d %d %d %d%*c",
|
|
|
|
&game.minPlasmaRateLimit, &game.minPlasmaDamageLimit,
|
|
|
|
&game.minPlasmaOutputLimit, &game.maxPlasmaRateLimit,
|
|
|
|
&game.maxPlasmaDamageLimit, &game.maxPlasmaOutputLimit,
|
|
|
|
&game.maxPlasmaAmmoLimit, &game.maxRocketAmmoLimit) < 8) ||
|
2016-01-10 04:00:20 +01:00
|
|
|
(fscanf(fp, "%d %d %d%*c%*[^\n]%*c", &game.system, &game.area,
|
2016-01-10 01:58:07 +01:00
|
|
|
&game.stationedPlanet) < 3) ||
|
|
|
|
(fscanf(fp, "%d %d%*c", &game.hasWingMate1, &game.hasWingMate2) < 2) ||
|
|
|
|
(fscanf(fp, "%d %d %d %d%*c", &player.maxShield,
|
|
|
|
&player.ammo[0], &player.ammo[1], &player.weaponType[1]) < 4) ||
|
|
|
|
(fscanf(fp, "%d %d %d%*c",
|
2016-11-25 19:47:12 +01:00
|
|
|
&weapons[W_PLAYER_WEAPON].ammo[0],
|
|
|
|
&weapons[W_PLAYER_WEAPON].damage,
|
|
|
|
&weapons[W_PLAYER_WEAPON].reload[0]) < 3) ||
|
2016-01-10 01:58:07 +01:00
|
|
|
(fscanf(fp, "%d %d %d %d %d %d %d %d%*c",
|
|
|
|
&game.minPlasmaRate, &game.minPlasmaDamage,
|
|
|
|
&game.minPlasmaOutput, &game.maxPlasmaRate,
|
|
|
|
&game.maxPlasmaDamage, &game.maxPlasmaOutput,
|
|
|
|
&game.maxPlasmaAmmo, &game.maxRocketAmmo) < 8) ||
|
|
|
|
(fscanf(fp, "%d %d %d %d %d %d %d %d %d %d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d%*c",
|
|
|
|
&game.missionCompleted[0], &game.missionCompleted[1],
|
|
|
|
&game.missionCompleted[2], &game.missionCompleted[3],
|
|
|
|
&game.missionCompleted[4], &game.missionCompleted[5],
|
|
|
|
&game.missionCompleted[6], &game.missionCompleted[7],
|
|
|
|
&game.missionCompleted[8], &game.missionCompleted[9]) < 10) ||
|
|
|
|
(fscanf(fp, "%d%*c", &game.experimentalShield) < 1) ||
|
|
|
|
(fscanf(fp, "%d %d%*c", &game.cash, &game.cashEarned) < 2) ||
|
|
|
|
(fscanf(fp, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d%*c",
|
|
|
|
&game.shots, &game.hits, &game.accuracy, &game.totalKills,
|
|
|
|
&game.wingMate1Kills, &game.wingMate2Kills,
|
|
|
|
&game.wingMate1Ejects, &game.wingMate2Ejects,
|
|
|
|
&game.totalOtherKills, &game.shieldPickups,
|
|
|
|
&game.rocketPickups, &game.cellPickups, &game.powerups,
|
|
|
|
&game.minesKilled, &game.slavesRescued) < 15) ||
|
2016-01-12 20:03:08 +01:00
|
|
|
(fscanf(fp, "%lu%*c", &timeTaken) < 1))
|
2016-01-10 01:58:07 +01:00
|
|
|
{
|
|
|
|
printf("Warning: Save data is not correctly formatted. Some data may be lost.\n");
|
|
|
|
}
|
2016-01-12 20:03:08 +01:00
|
|
|
else
|
|
|
|
{
|
2016-01-12 20:52:24 +01:00
|
|
|
game.timeTaken = (Uint32)(timeTaken);
|
2016-01-12 20:03:08 +01:00
|
|
|
}
|
2016-01-10 01:58:07 +01:00
|
|
|
game.destinationPlanet = game.stationedPlanet;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("Error: Save format version not recognized.\n");
|
|
|
|
fclose(fp);
|
2016-11-17 01:43:03 +01:00
|
|
|
return 0;
|
2016-01-10 01:58:07 +01:00
|
|
|
}
|
2016-01-09 03:33:40 +01:00
|
|
|
|
2016-01-10 01:58:07 +01:00
|
|
|
fclose(fp);
|
2016-01-09 03:33:40 +01:00
|
|
|
}
|
2016-01-10 01:58:07 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf(filename, "%ssave%.2d.dat", engine.configDirectory, slot);
|
|
|
|
fp = fopen(filename, "rb");
|
2016-01-09 03:33:40 +01:00
|
|
|
|
2016-01-10 01:58:07 +01:00
|
|
|
if (fp == NULL)
|
2016-11-17 01:43:03 +01:00
|
|
|
return 0;
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2016-01-10 01:58:07 +01:00
|
|
|
if (fread(&game, sizeof(Game), 1, fp) != 1)
|
|
|
|
{
|
|
|
|
printf("Save game error. The file was not of the expected format.\n");
|
|
|
|
fclose(fp);
|
2016-11-17 01:43:03 +01:00
|
|
|
return 0;
|
2016-01-10 01:58:07 +01:00
|
|
|
}
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
2016-01-10 01:58:07 +01:00
|
|
|
if (game.saveFormat < 2)
|
|
|
|
game.difficulty = DIFFICULTY_NORMAL;
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2016-11-25 19:47:12 +01:00
|
|
|
weapons[W_PLAYER_WEAPON] = game.playerWeapon;
|
|
|
|
weapons[W_PLAYER_WEAPON].imageIndex[0] = SP_PLASMA_GREEN;
|
|
|
|
weapons[W_PLAYER_WEAPON].imageIndex[1] = SP_PLASMA_GREEN;
|
2016-01-10 01:58:07 +01:00
|
|
|
player = game.thePlayer;
|
2017-02-04 21:42:59 +01:00
|
|
|
|
|
|
|
save(slot);
|
|
|
|
remove(filename);
|
2016-01-10 01:58:07 +01:00
|
|
|
}
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
// Re-init all the planets in this system...
|
2016-11-25 18:29:15 +01:00
|
|
|
intermission_initPlanets(game.system);
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
// ... and then override with completition status
|
2016-11-26 06:36:33 +01:00
|
|
|
for (int i = 0 ; i < MAX_PLANETS ; i++)
|
2016-11-25 18:29:15 +01:00
|
|
|
intermission_planets[i].missionCompleted = game.missionCompleted[i];
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2016-11-17 01:43:03 +01:00
|
|
|
return 1;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
2016-11-17 01:43:03 +01:00
|
|
|
void save(int slot)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2015-03-31 21:23:17 +02:00
|
|
|
FILE *fp;
|
|
|
|
char fileName[PATH_MAX];
|
|
|
|
|
2015-03-03 05:32:48 +01:00
|
|
|
if ((slot < 0) || (slot > 5))
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2015-03-03 05:32:48 +01:00
|
|
|
printf("Error - Saves may only be 0 to 5\n");
|
2011-08-24 14:14:44 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-10 01:58:07 +01:00
|
|
|
sprintf(fileName, "%ssave%.2d.sav", engine.configDirectory, slot);
|
2017-03-28 16:35:11 +02:00
|
|
|
fp = fopen(fileName, "w");
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2016-01-10 01:58:07 +01:00
|
|
|
|
|
|
|
game.saveFormat = 4;
|
2016-11-26 06:36:33 +01:00
|
|
|
for (int i = 0 ; i < MAX_PLANETS ; i++)
|
2016-11-25 18:29:15 +01:00
|
|
|
game.missionCompleted[i] = intermission_planets[i].missionCompleted;
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
if (fp != NULL)
|
|
|
|
{
|
2016-01-10 01:58:07 +01:00
|
|
|
if (fprintf(fp,
|
|
|
|
"%d\n"
|
|
|
|
"%d\n"
|
|
|
|
"%d %d %d %d %d %d %d %d\n"
|
|
|
|
"%d %d %d\n"
|
2016-01-10 04:00:20 +01:00
|
|
|
"%s\n"
|
2016-01-10 01:58:07 +01:00
|
|
|
"%d %d\n"
|
|
|
|
"%d %d %d %d\n"
|
|
|
|
"%d %d %d\n"
|
|
|
|
"%d %d %d %d %d %d %d %d\n"
|
|
|
|
"%d %d %d %d %d %d %d %d %d %d 0 0 0 0 0 0 0 0 0 0\n"
|
|
|
|
"%d\n"
|
|
|
|
"%d %d\n"
|
|
|
|
"%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n"
|
2016-01-12 20:03:08 +01:00
|
|
|
"%lu\n",
|
2016-01-10 01:58:07 +01:00
|
|
|
|
|
|
|
game.saveFormat,
|
|
|
|
|
|
|
|
game.difficulty,
|
|
|
|
|
|
|
|
game.minPlasmaRateLimit, game.minPlasmaDamageLimit,
|
|
|
|
game.minPlasmaOutputLimit, game.maxPlasmaRateLimit,
|
|
|
|
game.maxPlasmaDamageLimit, game.maxPlasmaOutputLimit,
|
|
|
|
game.maxPlasmaAmmoLimit, game.maxRocketAmmoLimit,
|
|
|
|
|
|
|
|
game.system, game.area, game.stationedPlanet,
|
|
|
|
|
2016-11-25 19:47:12 +01:00
|
|
|
intermission_planets[game.stationedPlanet].name,
|
2016-01-10 04:00:20 +01:00
|
|
|
|
2016-01-10 01:58:07 +01:00
|
|
|
game.hasWingMate1, game.hasWingMate2,
|
|
|
|
|
|
|
|
player.maxShield, player.ammo[0], player.ammo[1],
|
|
|
|
player.weaponType[1],
|
|
|
|
|
2016-11-25 19:47:12 +01:00
|
|
|
weapons[W_PLAYER_WEAPON].ammo[0], weapons[W_PLAYER_WEAPON].damage,
|
|
|
|
weapons[W_PLAYER_WEAPON].reload[0],
|
2016-01-10 01:58:07 +01:00
|
|
|
|
|
|
|
game.minPlasmaRate, game.minPlasmaDamage, game.minPlasmaOutput,
|
|
|
|
game.maxPlasmaRate, game.maxPlasmaDamage, game.maxPlasmaOutput,
|
|
|
|
game.maxPlasmaAmmo, game.maxRocketAmmo,
|
|
|
|
|
|
|
|
game.missionCompleted[0], game.missionCompleted[1],
|
|
|
|
game.missionCompleted[2], game.missionCompleted[3],
|
|
|
|
game.missionCompleted[4], game.missionCompleted[5],
|
|
|
|
game.missionCompleted[6], game.missionCompleted[7],
|
|
|
|
game.missionCompleted[8], game.missionCompleted[9],
|
|
|
|
|
|
|
|
game.experimentalShield,
|
|
|
|
|
|
|
|
game.cash, game.cashEarned,
|
|
|
|
|
|
|
|
game.shots, game.hits, game.accuracy, game.totalKills,
|
|
|
|
game.wingMate1Kills, game.wingMate2Kills, game.wingMate1Ejects,
|
|
|
|
game.wingMate2Ejects, game.totalOtherKills, game.shieldPickups,
|
|
|
|
game.rocketPickups, game.cellPickups, game.powerups,
|
|
|
|
game.minesKilled, game.slavesRescued,
|
|
|
|
|
2016-01-12 20:03:08 +01:00
|
|
|
(unsigned long)(game.timeTaken)) <= 0)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
printf("Error Saving Game to Slot %d\n", slot);
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("Error Saving Game to Slot %d\n", slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recall to update the save slots... (lazy, yes)
|
2016-11-17 01:43:03 +01:00
|
|
|
save_initSlots();
|
2013-09-30 16:52:43 +02:00
|
|
|
engine.keyState[KEY_FIRE] = 0;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
2016-11-17 01:43:03 +01:00
|
|
|
void save_createSurface(SDL_Surface *savesSurface, int clickedSlot)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2015-03-31 21:23:17 +02:00
|
|
|
int y = 10;
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2015-12-31 16:47:27 +01:00
|
|
|
gfx_drawRect(savesSurface, 0, 0, 348, 298, 0x00, 0x00, 0x00);
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2015-03-03 05:32:48 +01:00
|
|
|
for (int i = 1 ; i <= 5 ; i++)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
if (clickedSlot == i)
|
2015-12-31 16:47:27 +01:00
|
|
|
gfx_drawRect(savesSurface, 5, y, 338, 25, 0x99, 0x00, 0x00);
|
2011-08-24 14:14:44 +02:00
|
|
|
else
|
2015-12-31 16:47:27 +01:00
|
|
|
gfx_drawRect(savesSurface, 5, y, 338, 25, 0x00, 0x00, 0x99);
|
2015-11-06 16:12:57 +01:00
|
|
|
gfx_renderString(saveSlot[i], 70, y + 5, FONT_WHITE, 0, savesSurface);
|
2011-08-24 14:14:44 +02:00
|
|
|
y += 30;
|
|
|
|
}
|
|
|
|
|
2015-11-06 16:12:57 +01:00
|
|
|
gfx_renderString("*** HELP ***", 120, 170, FONT_WHITE, 0, savesSurface);
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2015-03-03 05:32:48 +01:00
|
|
|
switch (clickedSlot)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
2015-03-03 05:32:48 +01:00
|
|
|
case 5:
|
2015-12-31 16:47:27 +01:00
|
|
|
gfx_drawRect(savesSurface, 5, 265, 100, 25, 0x00, 0x99, 0x00);
|
|
|
|
gfx_drawRect(savesSurface, 125, 265, 100, 25, 0x99, 0x99, 0x00);
|
|
|
|
gfx_drawRect(savesSurface, 243, 265, 100, 25, 0x99, 0x00, 0x00);
|
2015-11-06 16:12:57 +01:00
|
|
|
gfx_renderString("SAVE", 40, 270, FONT_WHITE, 0, savesSurface);
|
|
|
|
gfx_renderString("CANCEL", 150, 270, FONT_WHITE, 0, savesSurface);
|
|
|
|
gfx_renderString("DELETE", 270, 270, FONT_WHITE, 0, savesSurface);
|
2011-08-26 23:53:46 +02:00
|
|
|
|
2019-06-05 01:10:24 +02:00
|
|
|
gfx_renderUnicode("SAVE will save the game", 17, 200, FONT_WHITE, 0,
|
2015-03-03 05:32:48 +01:00
|
|
|
savesSurface);
|
2019-06-05 01:10:24 +02:00
|
|
|
gfx_renderUnicode("CANCEL will unselect that slot", 17, 220,
|
2015-11-06 16:12:57 +01:00
|
|
|
FONT_WHITE, 0, savesSurface);
|
2019-06-05 01:10:24 +02:00
|
|
|
gfx_renderUnicode("DELETE will remove the save", 17, 240,
|
2015-11-06 16:12:57 +01:00
|
|
|
FONT_WHITE, 0, savesSurface);
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
case -1:
|
2019-06-05 01:10:24 +02:00
|
|
|
gfx_renderUnicode("First click a Save game slot to use", 17, 200,
|
2015-11-06 16:12:57 +01:00
|
|
|
FONT_WHITE, 0, savesSurface);
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
case -10:
|
2019-06-05 01:10:24 +02:00
|
|
|
gfx_renderUnicode("Game Saved", 130, 200, FONT_WHITE, 0,
|
2015-11-06 16:12:57 +01:00
|
|
|
savesSurface);
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
case -11:
|
2019-06-05 01:10:24 +02:00
|
|
|
gfx_renderUnicode("Save Deleted", 130, 200, FONT_WHITE, 0,
|
2015-11-06 16:12:57 +01:00
|
|
|
savesSurface);
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-09-30 16:52:43 +02:00
|
|
|
engine.keyState[KEY_FIRE] = 0;
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Displays the save slot available. For use with an interface that
|
|
|
|
has the cursor enabled. It returns the index number of the slot clicked
|
|
|
|
so that the function invoking it can perform a load or save on that slot.
|
|
|
|
*/
|
2017-02-02 23:45:47 +01:00
|
|
|
int save_showSlots(SDL_Surface *savesSurface, int saveSlot, int x, int y)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2015-03-31 21:23:17 +02:00
|
|
|
int clickedSlot = -1;
|
|
|
|
|
2011-08-24 14:14:44 +02:00
|
|
|
SDL_Rect r;
|
2017-02-02 23:45:47 +01:00
|
|
|
r.x = x + 1;
|
|
|
|
r.y = y + 15;
|
2011-08-24 14:14:44 +02:00
|
|
|
r.w = 348;
|
|
|
|
r.h = 25;
|
|
|
|
|
2013-09-30 16:52:43 +02:00
|
|
|
if ((engine.keyState[KEY_FIRE]))
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2015-03-03 05:32:48 +01:00
|
|
|
for (int i = 1 ; i <= 5 ; i++)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2015-09-25 22:28:09 +02:00
|
|
|
if (game_collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6,
|
2015-03-03 05:32:48 +01:00
|
|
|
r.x, r.y, r.w, r.h))
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
clickedSlot = i;
|
2016-11-17 01:43:03 +01:00
|
|
|
save_createSurface(savesSurface, i);
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
r.y += 30;
|
|
|
|
}
|
|
|
|
|
2017-02-02 23:45:47 +01:00
|
|
|
if (game_collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6,
|
|
|
|
x + 15, y + 265, 100, 25))
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2016-11-17 01:43:03 +01:00
|
|
|
save(saveSlot);
|
|
|
|
save_createSurface(savesSurface, -10);
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
2017-02-02 23:45:47 +01:00
|
|
|
if (game_collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6,
|
|
|
|
x + 135, y + 265, 100, 25))
|
2016-11-17 01:43:03 +01:00
|
|
|
save_createSurface(savesSurface, -1);
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2017-02-02 23:45:47 +01:00
|
|
|
if (game_collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6,
|
|
|
|
x + 253, y + 265, 100, 25))
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
char filename[PATH_MAX];
|
2017-02-04 21:42:59 +01:00
|
|
|
sprintf(filename, "%ssave%.2d.sav", engine.configDirectory,
|
2015-03-03 05:32:48 +01:00
|
|
|
saveSlot);
|
2011-08-24 14:14:44 +02:00
|
|
|
remove(filename);
|
2016-11-17 01:43:03 +01:00
|
|
|
save_initSlots();
|
|
|
|
save_createSurface(savesSurface, -11);
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clickedSlot > -1)
|
|
|
|
saveSlot = clickedSlot;
|
|
|
|
|
|
|
|
return saveSlot;
|
|
|
|
}
|