summaryrefslogtreecommitdiff
path: root/src/heretic
diff options
context:
space:
mode:
authorSimon Howard2011-09-05 22:18:16 +0000
committerSimon Howard2011-09-05 22:18:16 +0000
commit5d82119ccad9476d5db479f81952e56cef0e1751 (patch)
treed72ccd12d3618bb111cc637aea684d6984767a85 /src/heretic
parent9ff63977237ba7d7edb7f863c9a6ad4dd5b07cbe (diff)
downloadchocolate-doom-5d82119ccad9476d5db479f81952e56cef0e1751.tar.gz
chocolate-doom-5d82119ccad9476d5db479f81952e56cef0e1751.tar.bz2
chocolate-doom-5d82119ccad9476d5db479f81952e56cef0e1751.zip
Store Heretic savegames in the configuration directory, as with Doom
savegames. Subversion-branch: /branches/raven-branch Subversion-revision: 2361
Diffstat (limited to 'src/heretic')
-rw-r--r--src/heretic/d_main.c30
-rw-r--r--src/heretic/doomdef.h4
-rw-r--r--src/heretic/g_game.c46
-rw-r--r--src/heretic/mn_menu.c31
4 files changed, 58 insertions, 53 deletions
diff --git a/src/heretic/d_main.c b/src/heretic/d_main.c
index 5c2d5cf2..97eb37ed 100644
--- a/src/heretic/d_main.c
+++ b/src/heretic/d_main.c
@@ -421,25 +421,19 @@ void D_StartTitle(void)
void D_CheckRecordFrom(void)
{
int p;
- char file[256];
+ char *filename;
p = M_CheckParm("-recordfrom");
if (!p || p > myargc - 2)
return;
- if (cdrom)
- {
- sprintf(file, SAVEGAMENAMECD "%c.hsg", myargv[p + 1][0]);
- }
- else
- {
- sprintf(file, SAVEGAMENAME "%c.hsg", myargv[p + 1][0]);
- }
- G_LoadGame(file);
+ filename = SV_Filename(myargv[p + 1][0] - '0');
+ G_LoadGame(filename);
G_DoLoadGame(); // load the gameskill etc info from savegame
G_RecordDemo(gameskill, 1, gameepisode, gamemap, myargv[p + 2]);
D_DoomLoop(); // never returns
+ free(filename);
}
/*
@@ -940,6 +934,8 @@ void D_DoomMain(void)
gamedescription = "Heretic (registered)";
}
+ savegamedir = M_GetSaveGameDir("heretic.wad");
+
I_PrintStartupBanner(gamedescription);
// haleyjd: removed WATCOMC
@@ -1033,15 +1029,11 @@ void D_DoomMain(void)
p = M_CheckParm("-loadgame");
if (p && p < myargc - 1)
{
- if (cdrom)
- {
- sprintf(file, SAVEGAMENAMECD "%c.hsg", myargv[p + 1][0]);
- }
- else
- {
- sprintf(file, SAVEGAMENAME "%c.hsg", myargv[p + 1][0]);
- }
- G_LoadGame(file);
+ char *filename;
+
+ filename = SV_Filename(myargv[p + 1][0] - '0');
+ G_LoadGame(filename);
+ free(filename);
}
// Check valid episode and map
diff --git a/src/heretic/doomdef.h b/src/heretic/doomdef.h
index aa1d0c0d..b2508335 100644
--- a/src/heretic/doomdef.h
+++ b/src/heretic/doomdef.h
@@ -66,7 +66,6 @@
#include "d_ticcmd.h"
#define SAVEGAMENAME "hticsav"
-#define SAVEGAMENAMECD "c:\\heretic.cd\\hticsav"
/*
===============================================================================
@@ -740,6 +739,7 @@ void G_SaveGame(int slot, char *description);
// called by M_Responder
// Support routines for saving games
+char *SV_Filename(int slot);
void SV_Open(char *fileName);
void SV_Close(char *fileName);
void SV_Write(void *buffer, int size);
@@ -747,6 +747,8 @@ void SV_WriteByte(byte val);
void SV_WriteWord(unsigned short val);
void SV_WriteLong(unsigned int val);
+extern char *savegamedir;
+
void G_RecordDemo(skill_t skill, int numplayers, int episode, int map,
char *name);
// only called by startup code
diff --git a/src/heretic/g_game.c b/src/heretic/g_game.c
index b37f95e0..9b3e3799 100644
--- a/src/heretic/g_game.c
+++ b/src/heretic/g_game.c
@@ -25,6 +25,7 @@
// G_game.c
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "doomdef.h"
#include "doomkeys.h"
@@ -133,6 +134,7 @@ boolean precache = true; // if true, load all graphics at start
short consistancy[MAXPLAYERS][BACKUPTICS];
+char *savegamedir;
byte *savebuffer, *save_p;
@@ -1294,11 +1296,11 @@ void G_DoWorldDone(void)
//
//---------------------------------------------------------------------------
-char savename[256];
+static char *savename = NULL;
void G_LoadGame(char *name)
{
- strcpy(savename, name);
+ savename = strdup(name);
gameaction = ga_loadgame;
}
@@ -1322,6 +1324,9 @@ void G_DoLoadGame(void)
gameaction = ga_nothing;
length = M_ReadFile(savename, &savebuffer);
+ free(savename);
+ savename = NULL;
+
save_p = savebuffer + SAVESTRINGSIZE;
// Skip the description field
memset(vcheck, 0, sizeof(vcheck));
@@ -1684,21 +1689,15 @@ void G_SaveGame(int slot, char *description)
void G_DoSaveGame(void)
{
int i;
- char name[100];
+ char *filename;
char verString[VERSIONSIZE];
char *description;
- if (cdrom)
- {
- sprintf(name, SAVEGAMENAMECD "%d.hsg", savegameslot);
- }
- else
- {
- sprintf(name, SAVEGAMENAME "%d.hsg", savegameslot);
- }
+ filename = SV_Filename(savegameslot);
+
description = savedescription;
- SV_Open(name);
+ SV_Open(filename);
SV_Write(description, SAVESTRINGSIZE);
memset(verString, 0, sizeof(verString));
DEH_snprintf(verString, VERSIONSIZE, "version %i", HERETIC_VERSION);
@@ -1717,11 +1716,32 @@ void G_DoSaveGame(void)
P_ArchiveWorld();
P_ArchiveThinkers();
P_ArchiveSpecials();
- SV_Close(name);
+ SV_Close(filename);
gameaction = ga_nothing;
savedescription[0] = 0;
P_SetMessage(&players[consoleplayer], DEH_String(TXT_GAMESAVED), true);
+
+ free(filename);
+}
+
+//==========================================================================
+//
+// SV_Filename
+//
+// Generate the filename to use for a particular savegame slot.
+// Returns a malloc()'d buffer that must be freed by the caller.
+//
+//==========================================================================
+
+char *SV_Filename(int slot)
+{
+ char *filename;
+
+ filename = malloc(strlen(savegamedir) + strlen(SAVEGAMENAME) + 8);
+ sprintf(filename, "%s" SAVEGAMENAME "%d.hsg", savegamedir, slot);
+
+ return filename;
}
//==========================================================================
diff --git a/src/heretic/mn_menu.c b/src/heretic/mn_menu.c
index 955e0124..930df426 100644
--- a/src/heretic/mn_menu.c
+++ b/src/heretic/mn_menu.c
@@ -645,19 +645,14 @@ void MN_LoadSlotText(void)
FILE *fp;
int count;
int i;
- char name[256];
+ char *filename;
for (i = 0; i < 6; i++)
{
- if (cdrom)
- {
- sprintf(name, SAVEGAMENAMECD "%d.hsg", i);
- }
- else
- {
- sprintf(name, SAVEGAMENAME "%d.hsg", i);
- }
- fp = fopen(name, "rb+");
+ filename = SV_Filename(i);
+ fp = fopen(filename, "rb+");
+ free(filename);
+
if (!fp)
{
SlotText[i][0] = 0; // empty the string
@@ -826,21 +821,17 @@ static boolean SCMessages(int option)
static boolean SCLoadGame(int option)
{
- char name[256];
+ char *filename;
if (!SlotStatus[option])
{ // slot's empty...don't try and load
return false;
}
- if (cdrom)
- {
- sprintf(name, SAVEGAMENAMECD "%d.hsg", option);
- }
- else
- {
- sprintf(name, SAVEGAMENAME "%d.hsg", option);
- }
- G_LoadGame(name);
+
+ filename = SV_Filename(option);
+ G_LoadGame(filename);
+ free(filename);
+
MN_DeactivateMenu();
BorderNeedRefresh = true;
if (quickload == -1)