Automatically name savegames based on the map name instead of canceling the save if no name is entered

git-svn-id: https://svn.eduke32.com/eduke32@1707 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2010-09-14 18:19:38 +00:00
parent fec84e6dbb
commit 68801322dc
3 changed files with 44 additions and 37 deletions

View file

@ -29,6 +29,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "savegame.h"
#include "premap.h"
#include "demo.h"
#include "crc32.h"
#include <sys/stat.h>
extern char inputloc;
@ -4670,6 +4672,10 @@ cheat_for_port_credits:
if (g_currentMenu >= 360 && g_currentMenu <= 369)
{
static uint32_t crc = 0;
if (!crc) crc = crc32once((uint8_t *)&ud.savegame[g_currentMenu-360][0], 19);
Bsprintf(tempbuf,"PLAYERS: %-2d ",ud.multimode);
mgametext(160,156,tempbuf,0,2+8+16);
Bsprintf(tempbuf,"EPISODE: %-2d / LEVEL: %-2d / SKILL: %-2d",1+ud.volume_number,1+ud.level_number,ud.player_skill);
@ -4677,43 +4683,40 @@ cheat_for_port_credits:
if (ud.volume_number == 0 && ud.level_number == 7)
mgametext(160,180,currentboardfilename,0,2+8+16);
x = G_EnterText((320>>1),184,&ud.savegame[g_currentMenu-360][0],19, 999);
x = G_EnterText((320>>1),184,&ud.savegame[g_currentMenu-360][0],20, 999);
if (x == -1)
{
// ReadSaveGameHeaders();
g_player[myconnectindex].ps->gm = MODE_GAME;
if ((!g_netServer && ud.multimode < 2) && ud.recstat != 2)
{
ready2send = 1;
totalclock = ototalclock;
}
crc = 0;
ReadSaveGameHeaders();
ChangeToMenu(351);
goto DISPLAYNAMES;
}
if (x == 1)
{
if (ud.savegame[g_currentMenu-360][0] == 0)
// dirty hack... char 127 in last position indicates an auto-filled name
if (ud.savegame[g_currentMenu-360][0] == 0 || (ud.savegame[g_currentMenu-360][20] == 127 &&
crc == crc32once((uint8_t *)&ud.savegame[g_currentMenu-360][0], 19)))
{
KB_FlushKeyboardQueue();
ChangeToMenu(351);
Bstrncpy(&ud.savegame[g_currentMenu-360][0], MapInfo[ud.volume_number * MAXLEVELS + ud.level_number].name, 19);
ud.savegame[g_currentMenu-360][20] = 127;
}
else
{
if ((g_netServer || ud.multimode > 1))
G_SavePlayer(-1-(g_currentMenu-360));
else G_SavePlayer(g_currentMenu-360);
g_lastSaveSlot = g_currentMenu-360;
g_player[myconnectindex].ps->gm = MODE_GAME;
if ((!g_netServer && ud.multimode < 2) && ud.recstat != 2)
{
ready2send = 1;
totalclock = ototalclock;
}
KB_ClearKeyDown(sc_Escape);
S_PlaySound(EXITMENUSOUND);
if ((g_netServer || ud.multimode > 1))
G_SavePlayer(-1-(g_currentMenu-360));
else G_SavePlayer(g_currentMenu-360);
g_lastSaveSlot = g_currentMenu-360;
g_player[myconnectindex].ps->gm = MODE_GAME;
if ((!g_netServer && ud.multimode < 2) && ud.recstat != 2)
{
ready2send = 1;
totalclock = ototalclock;
}
KB_ClearKeyDown(sc_Escape);
S_PlaySound(EXITMENUSOUND);
crc = 0;
}
rotatesprite(101<<16,97<<16,65536>>1,512,TILE_SAVESHOT,-32,0,2+4+8+64,0,0,xdim-1,ydim-1);

View file

@ -68,10 +68,12 @@ void ReadSaveGameHeaders(void)
kclose(fil);
continue;
}
if (kdfread(&ud.savegame[i][0],19,1,fil) != 1)
if (kdfread(&ud.savegame[i][0],21,1,fil) != 1)
{
ud.savegame[i][0] = 0;
}
else ud.savegame[i][19] = 0;
kclose(fil);
}
}
@ -104,7 +106,7 @@ int32_t G_LoadSaveHeader(char spot,struct savehead *saveh)
if (kdfread(&saveh->numplr,sizeof(int32_t),1,fil) != 1) goto corrupt;
if (kdfread(saveh->name,19,1,fil) != 1) goto corrupt;
if (kdfread(saveh->name,21,1,fil) != 1) goto corrupt;
if (kdfread(&saveh->volnum,sizeof(int32_t),1,fil) != 1) goto corrupt;
if (kdfread(&saveh->levnum,sizeof(int32_t),1,fil) != 1) goto corrupt;
if (kdfread(&saveh->plrskl,sizeof(int32_t),1,fil) != 1) goto corrupt;
@ -187,11 +189,12 @@ int32_t G_LoadPlayer(int32_t spot)
if (numplayers > 1)
{
if (kdfread(&buf,19,1,fil) != 1) goto corrupt;
if (kdfread(&buf,21,1,fil) != 1) goto corrupt;
}
else
{
if (kdfread(&ud.savegame[spot][0],19,1,fil) != 1) goto corrupt;
if (kdfread(&ud.savegame[spot][0],21,1,fil) != 1) goto corrupt;
ud.savegame[spot][19] = 0;
}
@ -653,7 +656,7 @@ int32_t G_SavePlayer(int32_t spot)
dfwrite(&bv,sizeof(bv),1,fil);
dfwrite(&ud.multimode,sizeof(ud.multimode),1,fil);
dfwrite(&ud.savegame[spot][0],19,1,fil);
dfwrite(&ud.savegame[spot][0],21,1,fil);
dfwrite(&ud.volume_number,sizeof(ud.volume_number),1,fil);
dfwrite(&ud.level_number,sizeof(ud.level_number),1,fil);
dfwrite(&ud.player_skill,sizeof(ud.player_skill),1,fil);
@ -2048,7 +2051,7 @@ static uint8_t *dosaveplayer2(int32_t spot, FILE *fil, uint8_t *mem)
if (spot>=0)
{
SAVEWRU(&ud.savegame[spot][0], 19, 1);
SAVEWRU(&ud.savegame[spot][0], 21, 1);
SAVEWRU("1", 1, 1);
if (!waloff[TILE_SAVESHOT])
{
@ -2061,13 +2064,13 @@ static uint8_t *dosaveplayer2(int32_t spot, FILE *fil, uint8_t *mem)
}
else
{
char buf[19];
char buf[21];
const time_t t=time(NULL);
struct tm *st;
Bsprintf(buf, "Eduke32 demo");
if (t>=0 && (st = localtime(&t)))
Bsprintf(buf, "Edemo32 %04d%02d%02d", st->tm_year+1900, st->tm_mon+1, st->tm_mday);
SAVEWRU(&buf, 19, 1);
SAVEWRU(&buf, 21, 1);
SAVEWRU("\0", 1, 1); // demos don't save screenshot
}
@ -2091,7 +2094,7 @@ static uint8_t *dosaveplayer2(int32_t spot, FILE *fil, uint8_t *mem)
static int32_t doloadplayer2(int32_t spot, int32_t fil, uint8_t **memptr)
{
uint8_t *mem = memptr ? *memptr : NULL, *tmem=mem;
char tbuf[19];
char tbuf[21];
int32_t i;
if (readspecdata(svgm_udnetw, fil, &mem))
@ -2102,9 +2105,10 @@ static int32_t doloadplayer2(int32_t spot, int32_t fil, uint8_t **memptr)
if (spot<0 || numplayers > 1)
{
if (LOADRDU(&tbuf, 19, 1)) return -3;
if (LOADRDU(&tbuf, 21, 1)) return -3;
}
else if (LOADRDU(&ud.savegame[spot][0], 19, 1)) return -3;
else if (LOADRDU(&ud.savegame[spot][0], 21, 1)) return -3;
else ud.savegame[spot][19] = 0;
if (LOADRDU(tbuf, 1, 1)) return -3;
if (tbuf[0])

View file

@ -26,7 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#pragma pack(push,1)
struct savehead
{
char name[19];
char name[21];
int32_t numplr,volnum,levnum,plrskl;
char boardfn[BMAX_PATH];
};