Commit 06fba6a9 authored by Steven Fuller's avatar Steven Fuller

Finished rewriting config files and save games. Hoping that everything still

works...
parent 3d610c50
...@@ -77,3 +77,33 @@ at a time ...@@ -77,3 +77,33 @@ at a time
possible to calculate the sound lengths in terms of 70Hz (adlib sound len / 2, possible to calculate the sound lengths in terms of 70Hz (adlib sound len / 2,
pcm sound len / 100). pcm sound len / 100).
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
Save game header:
8 bytes: WOLF3D, 0, 0
4 bytes: SAV, 0
4 bytes: version (integer)
4 bytes: game type (WL1, WL6, SDM, SOD)
4 bytes: seconds past 1970 (time(NULL))
4 bytes: padding
4 bytes: checksum for the data (after text string)
32 bytes: text string
< data follows >
---
Config header:
8 bytes: WOLF3D, 0, 0
4 bytes: CFG, 0
4 bytes: version (integer)
4 bytes: game type (WL1, WL6, SDM, SOD)
4 bytes: seconds past 1970 (time(NULL))
4 bytes: padding
4 bytes: checksum for the data
Version 0xFFFFFFFF Data: (Unofficial Config data)
<see wl_main.c>
Version 0x00000000 Data: (Official)
<undetermined>
------------------------------------------------------------------------------
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
#define MaxScores 7 #define MaxScores 7
typedef struct { typedef struct {
char name[MaxHighName + 1]; char name[MaxHighName + 1];
long score; int score;
word completed,episode; int completed, episode;
} HighScore; } HighScore;
#define MaxString 128 // Maximum input string size #define MaxString 128 // Maximum input string size
......
...@@ -226,11 +226,18 @@ int OpenWrite(char *fn) ...@@ -226,11 +226,18 @@ int OpenWrite(char *fn)
{ {
int fp; int fp;
/* fp = creat(fn, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); */
fp = open(fn, O_CREAT|O_WRONLY|O_TRUNC|O_BINARY, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); fp = open(fn, O_CREAT|O_WRONLY|O_TRUNC|O_BINARY, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
return fp; return fp;
} }
int OpenWriteAppend(char *fn)
{
int fp;
fp = open(fn, O_CREAT|O_WRONLY|O_BINARY, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
return fp;
}
void CloseWrite(int fp) void CloseWrite(int fp)
{ {
close(fp); close(fp);
...@@ -241,6 +248,11 @@ int WriteSeek(int fp, int offset, int whence) ...@@ -241,6 +248,11 @@ int WriteSeek(int fp, int offset, int whence)
return lseek(fp, offset, whence); return lseek(fp, offset, whence);
} }
int WritePos(int fp)
{
return lseek(fp, 0, SEEK_CUR);
}
int WriteInt8(int fp, int8_t d) int WriteInt8(int fp, int8_t d)
{ {
return write(fp, &d, 1); return write(fp, &d, 1);
......
...@@ -25,9 +25,11 @@ char *ultoa(unsigned long value, char *string, int radix); ...@@ -25,9 +25,11 @@ char *ultoa(unsigned long value, char *string, int radix);
#endif /* DOSISM */ #endif /* DOSISM */
extern int OpenWrite(char *fn); extern int OpenWrite(char *fn);
extern int OpenWriteAppend(char *fn);
extern void CloseWrite(int fp); extern void CloseWrite(int fp);
extern int WriteSeek(int fp, int offset, int whence); extern int WriteSeek(int fp, int offset, int whence);
extern int WritePos(int fp);
extern int WriteInt8(int fp, int8_t d); extern int WriteInt8(int fp, int8_t d);
extern int WriteInt16(int fp, int16_t d); extern int WriteInt16(int fp, int16_t d);
......
...@@ -689,21 +689,22 @@ extern int shootdelta; ...@@ -689,21 +689,22 @@ extern int shootdelta;
extern boolean startgame,loadedgame; extern boolean startgame,loadedgame;
extern int mouseadjustment; extern int mouseadjustment;
// /* math tables */
// math tables
//
extern int pixelangle[MAXVIEWWIDTH]; extern int pixelangle[MAXVIEWWIDTH];
extern long finetangent[FINEANGLES/4]; extern long finetangent[FINEANGLES/4];
extern fixed sintable[], *costable; extern fixed sintable[], *costable;
extern char configname[13]; extern char configname[13];
void CalcProjection (long focal); void CalcProjection(long focal);
void NewGame (int difficulty,int episode); void NewGame(int difficulty,int episode);
void NewViewSize (int width); void NewViewSize(int width);
boolean LoadTheGame(int file,int x,int y); void ShowViewSize(int width);
boolean SaveTheGame(int file,int x,int y);
void ShowViewSize (int width); int LoadTheGame(char *fn, int x, int y);
int SaveTheGame(char *fn, char *tag, int x, int y);
int ReadSaveTag(char *fn, char *tag);
void ShutdownId(); void ShutdownId();
int WriteConfig(); int WriteConfig();
......
...@@ -1058,7 +1058,7 @@ restartgame: ...@@ -1058,7 +1058,7 @@ restartgame:
SetupGameLevel(); SetupGameLevel();
#ifdef SPEAR #ifdef SPEAR
if (gamestate.mapon == 20) // give them the key allways if (gamestate.mapon == 20) /* give them the key always */
{ {
gamestate.keys |= 1; gamestate.keys |= 1;
DrawKeys(); DrawKeys();
......
...@@ -101,58 +101,145 @@ void CalcTics() ...@@ -101,58 +101,145 @@ void CalcTics()
/* ======================================================================== */ /* ======================================================================== */
#if 0 static void DiskFlopAnim(int x, int y)
/* {
==================== static char which = 0;
=
= ReadConfig if (!x && !y)
= return;
====================
*/
void ReadConfig() VWB_DrawPic(x, y, C_DISKLOADING1PIC+which);
VW_UpdateScreen();
which ^= 1;
}
static int32_t CalcFileChecksum(int fd, int len)
{ {
SDMode sd; int32_t cs;
SMMode sm; int i;
SDSMode sds; int8_t c1, c2;
c1 = ReadInt8(fd);
cs = 0;
for (i = 0; i < len - 1; i++) {
c2 = ReadInt8(fd);
cs += c1 ^ c2;
c1 = c2;
}
return cs;
}
int file; int WriteConfig()
{
int i;
int fd;
int32_t cs;
if ((file = open(configname, O_BINARY | O_RDONLY)) != -1) fd = OpenWrite(configname);
{
//
// valid config file
//
read(file,Scores,sizeof(HighScore) * MaxScores);
read(file,&sd,sizeof(sd)); if (fd != -1) {
read(file,&sm,sizeof(sm)); WriteBytes(fd, (byte *)GAMEHDR, 8); /* WOLF3D, 0, 0 */
read(file,&sds,sizeof(sds)); WriteBytes(fd, (byte *)CFGTYPE, 4); /* CFG, 0 */
/**/ WriteInt32(fd, 0xFFFFFFFF); /* Version (integer) */
WriteBytes(fd, (byte *)GAMETYPE, 4); /* XXX, 0 */
WriteInt32(fd, time(NULL)); /* Time */
WriteInt32(fd, 0x00000000); /* Padding */
WriteInt32(fd, 0x00000000); /* Checksum (placeholder) */
for (i = 0; i < 7; i++) { /* MaxScores = 7 */
WriteBytes(fd, (byte *)Scores[i].name, 58);
WriteInt32(fd, Scores[i].score);
WriteInt32(fd, Scores[i].completed);
WriteInt32(fd, Scores[i].episode);
}
read(file,&mouseenabled,sizeof(mouseenabled)); WriteInt32(fd, viewsize);
read(file,&joystickenabled,sizeof(joystickenabled));
read(file,&joypadenabled,sizeof(joypadenabled));
read(file,&joystickport,sizeof(joystickport));
read(file,&dirscan,sizeof(dirscan)); CloseWrite(fd);
read(file,&buttonscan,sizeof(buttonscan));
read(file,&buttonmouse,sizeof(buttonmouse));
read(file,&buttonjoy,sizeof(buttonjoy));
read(file,&viewsize,sizeof(viewsize)); fd = OpenRead(configname);
read(file,&mouseadjustment,sizeof(mouseadjustment)); ReadSeek(fd, 32, SEEK_SET);
cs = CalcFileChecksum(fd, ReadLength(fd) - 32);
CloseRead(fd);
close(file); fd = OpenWriteAppend(configname);
WriteSeek(fd, 28, SEEK_SET);
WriteInt32(fd, cs);
MainMenu[6].active=1; CloseWrite(fd);
MainItems.curpos=0;
} }
else
{ return 0;
// }
// no config file, so select by hardware
// static void SetDefaults()
{
viewsize = 15; viewsize = 15;
}
int ReadConfig()
{
int fd, configokay;
char buf[8];
int32_t v;
int i;
configokay = 0;
fd = OpenRead(configname);
if (fd != -1) {
ReadBytes(fd, (byte *)buf, 8);
if (strncmp(buf, GAMEHDR, 8))
goto configend;
ReadBytes(fd, (byte *)buf, 4);
if (strncmp(buf, CFGTYPE, 4))
goto configend;
v = ReadInt32(fd);
/**/ if (v != 0xFFFFFFFF)
goto configend;
ReadBytes(fd, (byte *)buf, 4);
if (strncmp(buf, GAMETYPE, 4))
goto configend;
ReadInt32(fd); /* skip over time */
ReadInt32(fd); /* skip over padding */
v = ReadInt32(fd); /* get checksum */
if (v != CalcFileChecksum(fd, ReadLength(fd) - 32))
goto configend;
ReadSeek(fd, 32, SEEK_SET);
for (i = 0; i < 7; i++) { /* MaxScores = 7 */
ReadBytes(fd, (byte *)Scores[i].name, 58);
Scores[i].score = ReadInt32(fd);
Scores[i].completed = ReadInt32(fd);
Scores[i].episode = ReadInt32(fd);
}
viewsize = ReadInt32(fd);
#ifdef UPLOAD
MainMenu[readthis].active = 1;
MainItems.curpos = 0;
#endif
configokay = 1;
}
configend:
if (fd != -1)
CloseRead(fd);
if (!configokay) {
printf("Config: Setting defaults..\n");
SetDefaults();
} }
mouseenabled = false; mouseenabled = false;
...@@ -166,303 +253,462 @@ void ReadConfig() ...@@ -166,303 +253,462 @@ void ReadConfig()
SD_SetMusicMode(smm_AdLib); SD_SetMusicMode(smm_AdLib);
SD_SetSoundMode(sdm_AdLib); SD_SetSoundMode(sdm_AdLib);
SD_SetDigiDevice(sds_SoundBlaster); SD_SetDigiDevice(sds_SoundBlaster);
}
return 0;
}
/* int SaveTheGame(char *fn, char *tag, int dx, int dy)
====================
=
= WriteConfig
=
====================
*/
void WriteConfig()
{ {
int file; objtype *ob;
int fd, i, x, y;
int32_t cs;
file = open(configname, O_CREAT | O_BINARY | O_WRONLY, fd = OpenWrite(fn);
S_IREAD | S_IWRITE | S_IFREG);
if (file != -1) if (fd != -1) {
{ WriteBytes(fd, (byte *)GAMEHDR, 8);
write(file,Scores,sizeof(HighScore) * MaxScores); WriteBytes(fd, (byte *)SAVTYPE, 4);
WriteInt32(fd, 0xFFFFFFFF); /* write version */
WriteBytes(fd, (byte *)GAMETYPE, 4);
WriteInt32(fd, time(NULL));
WriteInt32(fd, 0x00000000);
WriteInt32(fd, 0x00000000); /* write checksum (placeholder) */
WriteBytes(fd, (byte *)tag, 32); /* write savegame name */
DiskFlopAnim(dx, dy);
WriteInt32(fd, gamestate.difficulty);
WriteInt32(fd, gamestate.mapon);
WriteInt32(fd, gamestate.oldscore);
WriteInt32(fd, gamestate.score);
WriteInt32(fd, gamestate.nextextra);
WriteInt32(fd, gamestate.lives);
WriteInt32(fd, gamestate.health);
WriteInt32(fd, gamestate.ammo);
WriteInt32(fd, gamestate.keys);
WriteInt32(fd, gamestate.bestweapon);
WriteInt32(fd, gamestate.weapon);
WriteInt32(fd, gamestate.chosenweapon);
WriteInt32(fd, gamestate.faceframe);
WriteInt32(fd, gamestate.attackframe);
WriteInt32(fd, gamestate.attackcount);
WriteInt32(fd, gamestate.weaponframe);
WriteInt32(fd, gamestate.episode);
WriteInt32(fd, gamestate.secretcount);
WriteInt32(fd, gamestate.treasurecount);
WriteInt32(fd, gamestate.killcount);
WriteInt32(fd, gamestate.secrettotal);
WriteInt32(fd, gamestate.treasuretotal);
WriteInt32(fd, gamestate.killtotal);
WriteInt32(fd, gamestate.TimeCount);
WriteInt32(fd, gamestate.killx);
WriteInt32(fd, gamestate.killy);
WriteInt8(fd, gamestate.victoryflag);
DiskFlopAnim(dx, dy);
#ifdef SPEAR
for (i = 0; i < 20; i++) {
#else
for (i = 0; i < 8; i++) {
#endif
WriteInt32(fd, LevelRatios[i].kill);
WriteInt32(fd, LevelRatios[i].secret);
WriteInt32(fd, LevelRatios[i].treasure);
WriteInt32(fd, LevelRatios[i].time);
}
write(file,&SoundMode,sizeof(SoundMode)); DiskFlopAnim(dx, dy);
write(file,&MusicMode,sizeof(MusicMode));
write(file,&DigiMode,sizeof(DigiMode)); WriteBytes(fd, (byte *)tilemap, 64*64); /* MAPSIZE * MAPSIZE */
DiskFlopAnim(dx, dy);
for (y = 0; y < 64; y++)
for (x = 0; x < 64; x++)
WriteInt32(fd, actorat[y][x]);
DiskFlopAnim(dx, dy);
WriteBytes(fd, (byte *)areaconnect, 37*37); /* NUMAREAS * NUMAREAS */
DiskFlopAnim(dx, dy);
for (i = 0; i < 37; i++)
WriteInt8(fd, areabyplayer[i]);
for (ob = player; ob; ob = ob->next) {
DiskFlopAnim(dx, dy);
WriteInt32(fd, ob->id);
WriteInt32(fd, ob->active);
WriteInt32(fd, ob->ticcount);
WriteInt32(fd, ob->obclass);
WriteInt32(fd, ob->state);
WriteInt8(fd, ob->flags);
WriteInt32(fd, ob->distance);
WriteInt32(fd, ob->dir);
WriteInt32(fd, ob->x);
WriteInt32(fd, ob->y);
WriteInt32(fd, ob->tilex);
WriteInt32(fd, ob->tiley);
WriteInt8(fd, ob->areanumber);
WriteInt32(fd, ob->viewx);
WriteInt32(fd, ob->viewheight);
WriteInt32(fd, ob->transx);
WriteInt32(fd, ob->transy);
WriteInt32(fd, ob->angle);
WriteInt32(fd, ob->hitpoints);
WriteInt32(fd, ob->speed);
WriteInt32(fd, ob->temp1);
WriteInt32(fd, ob->temp2);
WriteInt32(fd, ob->temp3);
}
write(file,&mouseenabled,sizeof(mouseenabled)); WriteInt32(fd, 0xFFFFFFFF); /* end of actor list */
write(file,&joystickenabled,sizeof(joystickenabled));
write(file,&joypadenabled,sizeof(joypadenabled));
write(file,&joystickport,sizeof(joystickport));
write(file,&dirscan,sizeof(dirscan)); DiskFlopAnim(dx, dy);
write(file,&buttonscan,sizeof(buttonscan));
write(file,&buttonmouse,sizeof(buttonmouse));
write(file,&buttonjoy,sizeof(buttonjoy));
write(file,&viewsize,sizeof(viewsize)); WriteInt32(fd, laststatobj - statobjlist); /* ptr offset */
write(file,&mouseadjustment,sizeof(mouseadjustment));
close(file); for (i = 0; i < 400; i++) { /* MAXSTATS */
WriteInt8(fd, statobjlist[i].tilex);
WriteInt8(fd, statobjlist[i].tiley);
WriteInt32(fd, statobjlist[i].shapenum);
WriteInt8(fd, statobjlist[i].flags);
WriteInt8(fd, statobjlist[i].itemnumber);
} }
}
#endif DiskFlopAnim(dx, dy);
void DiskFlopAnim(int x, int y) for (i = 0; i < 64; i++) { /* MAXDOORS */
{ WriteInt32(fd, doorposition[i]);
static char which = 0; }
if (!x && !y) DiskFlopAnim(dx, dy);
return;
VWB_DrawPic(x, y, C_DISKLOADING1PIC+which); for (i = 0; i < 64; i++) { /* MAXDOORS */
VW_UpdateScreen(); WriteInt8(fd, doorobjlist[i].tilex);
WriteInt8(fd, doorobjlist[i].tiley);
WriteInt8(fd, doorobjlist[i].vertical);
WriteInt8(fd, doorobjlist[i].lock);
WriteInt8(fd, doorobjlist[i].action);
WriteInt32(fd, doorobjlist[i].ticcount);
}
which ^= 1; DiskFlopAnim(dx, dy);
}
long DoChecksum(byte *source, unsigned size, long checksum) WriteInt32(fd, pwallstate);
{ WriteInt32(fd, pwallx);
int i; WriteInt32(fd, pwally);
WriteInt32(fd, pwalldir);
WriteInt32(fd, pwallpos);
for (i = 0; i < size-1; i++) DiskFlopAnim(dx, dy);
checksum += source[i]^source[i+1];
return checksum; CloseWrite(fd);
}
int WriteConfig() fd = OpenRead(fn);
{ ReadSeek(fd, 64, SEEK_SET);
int fd; cs = CalcFileChecksum(fd, ReadLength(fd) - 64);
CloseRead(fd);
fd = OpenWrite(configname); fd = OpenWriteAppend(fn);
WriteSeek(fd, 28, SEEK_SET);
WriteInt32(fd, cs);
if (fd != -1) {
CloseWrite(fd); CloseWrite(fd);
} else {
Message(STR_NOSPACE1"\n"
STR_NOSPACE2);
IN_ClearKeysDown();
IN_Ack();
return -1;
} }
return 0; return 0;
} }
int ReadConfig() int ReadSaveTag(char *fn, char *tag)
{ {
char buf[8];
int fd; int fd;
int32_t v;
fd = OpenRead(configname); fd = OpenRead(fn);
if (fd == -1)
goto rstfail;
if (fd != -1) { ReadBytes(fd, (byte *)buf, 8);
CloseRead(fd); if (strncmp(buf, GAMEHDR, 8))
goto rstfail;
#ifdef UPLOAD ReadBytes(fd, (byte *)buf, 4);
MainMenu[readthis].active = 1; if (strncmp(buf, SAVTYPE, 4))
MainItems.curpos = 0; goto rstfail;
#endif
} else {
viewsize = 15;
}
viewsize = 15; v = ReadInt32(fd);
if (v != 0xFFFFFFFF)
goto rstfail;
mouseenabled = false; ReadBytes(fd, (byte *)buf, 4);
if (strncmp(buf, GAMETYPE, 4))
goto rstfail;
joystickenabled = false; ReadInt32(fd);
joypadenabled = false; ReadInt32(fd);
joystickport = 0;
mouseadjustment = 5; v = ReadInt32(fd); /* get checksum */
SD_SetMusicMode(smm_AdLib); ReadSeek(fd, 64, SEEK_SET);
SD_SetSoundMode(sdm_AdLib); if (v != CalcFileChecksum(fd, ReadLength(fd) - 64))
SD_SetDigiDevice(sds_SoundBlaster); goto rstfail;
return 0; ReadSeek(fd, 32, SEEK_SET);
} ReadBytes(fd, (byte *)tag, 32);
int SaveGame() CloseRead(fd);
{
return 0;
}
int LoadGame()
{
return 0; return 0;
} rstfail:
if (fd != -1)
CloseRead(fd);
/* return -1;
================== }
=
= SaveTheGame
=
==================
*/
boolean SaveTheGame(int file, int x, int y) int LoadTheGame(char *fn, int dx, int dy)
{ {
long checksum; char buf[8];
objtype *ob,nullobj; int fd, i, x, y, id;
int32_t v;
checksum = 0;
fd = OpenRead(fn);
if (fd == -1)
goto loadfail;
ReadBytes(fd, (byte *)buf, 8);
if (strncmp(buf, GAMEHDR, 8))
goto loadfail;
ReadBytes(fd, (byte *)buf, 4);
if (strncmp(buf, SAVTYPE, 4))
goto loadfail;
v = ReadInt32(fd);
if (v != 0xFFFFFFFF)
goto loadfail;
ReadBytes(fd, (byte *)buf, 4);
if (strncmp(buf, GAMETYPE, 4))
goto loadfail;
ReadInt32(fd);
ReadInt32(fd);
v = ReadInt32(fd); /* get checksum */
ReadSeek(fd, 64, SEEK_SET);
if (v != CalcFileChecksum(fd, ReadLength(fd) - 64))
goto loadfail;
ReadSeek(fd, 64, SEEK_SET);
DiskFlopAnim(dx, dy);
gamestate.difficulty = ReadInt32(fd);
gamestate.mapon = ReadInt32(fd);
gamestate.oldscore = ReadInt32(fd);
gamestate.score = ReadInt32(fd);
gamestate.nextextra = ReadInt32(fd);
gamestate.lives = ReadInt32(fd);
gamestate.health = ReadInt32(fd);
gamestate.ammo = ReadInt32(fd);
gamestate.keys = ReadInt32(fd);
gamestate.bestweapon = ReadInt32(fd);
gamestate.weapon = ReadInt32(fd);
gamestate.chosenweapon = ReadInt32(fd);
gamestate.faceframe = ReadInt32(fd);
gamestate.attackframe = ReadInt32(fd);
gamestate.attackcount = ReadInt32(fd);
gamestate.weaponframe = ReadInt32(fd);
gamestate.episode = ReadInt32(fd);
gamestate.secretcount = ReadInt32(fd);
gamestate.treasurecount = ReadInt32(fd);
gamestate.killcount = ReadInt32(fd);
gamestate.secrettotal = ReadInt32(fd);
gamestate.treasuretotal = ReadInt32(fd);
gamestate.killtotal = ReadInt32(fd);
gamestate.TimeCount = ReadInt32(fd);
gamestate.killx = ReadInt32(fd);
gamestate.killy = ReadInt32(fd);
gamestate.victoryflag = ReadInt8(fd);
DiskFlopAnim(dx, dy);
DiskFlopAnim(x,y);
CA_FarWrite (file,(void *)&gamestate,sizeof(gamestate));
checksum = DoChecksum((byte *)&gamestate,sizeof(gamestate),checksum);
DiskFlopAnim(x,y);
#ifdef SPEAR #ifdef SPEAR
CA_FarWrite (file,(void *)&LevelRatios[0],sizeof(LRstruct)*20); for (i = 0; i < 20; i++) {
checksum = DoChecksum((byte *)&LevelRatios[0],sizeof(LRstruct)*20,checksum);
#else #else
CA_FarWrite (file,(void *)&LevelRatios[0],sizeof(LRstruct)*8); for (i = 0; i < 8; i++) {
checksum = DoChecksum((byte *)&LevelRatios[0],sizeof(LRstruct)*8,checksum);
#endif #endif
LevelRatios[i].kill = ReadInt32(fd);
DiskFlopAnim(x,y); LevelRatios[i].secret = ReadInt32(fd);
CA_FarWrite (file,(void *)tilemap,sizeof(tilemap)); LevelRatios[i].treasure = ReadInt32(fd);
checksum = DoChecksum((byte *)tilemap,sizeof(tilemap),checksum); LevelRatios[i].time = ReadInt32(fd);
DiskFlopAnim(x,y);
CA_FarWrite (file,(void *)actorat,sizeof(actorat));
checksum = DoChecksum((byte *)actorat,sizeof(actorat),checksum);
CA_FarWrite (file,(void *)areaconnect,sizeof(areaconnect));
CA_FarWrite (file,(void *)areabyplayer,sizeof(areabyplayer));
for (ob = player; ob; ob=ob->next) {
DiskFlopAnim(x,y);
CA_FarWrite(file, (void *)ob, sizeof(*ob));
} }
nullobj.active = ac_badobject; // end of file marker DiskFlopAnim(dx, dy);
DiskFlopAnim(x,y);
CA_FarWrite (file,(void *)&nullobj,sizeof(nullobj));
DiskFlopAnim(x,y);
CA_FarWrite (file,(void *)&laststatobj,sizeof(laststatobj));
checksum = DoChecksum((byte *)&laststatobj,sizeof(laststatobj),checksum);
DiskFlopAnim(x,y);
CA_FarWrite (file,(void *)statobjlist,sizeof(statobjlist));
checksum = DoChecksum((byte *)statobjlist,sizeof(statobjlist),checksum);
DiskFlopAnim(x,y);
CA_FarWrite (file,(void *)doorposition,sizeof(doorposition));
checksum = DoChecksum((byte *)doorposition,sizeof(doorposition),checksum);
DiskFlopAnim(x,y);
CA_FarWrite (file,(void *)doorobjlist,sizeof(doorobjlist));
checksum = DoChecksum((byte *)doorobjlist,sizeof(doorobjlist),checksum);
DiskFlopAnim(x,y);
CA_FarWrite (file,(void *)&pwallstate,sizeof(pwallstate));
checksum = DoChecksum((byte *)&pwallstate,sizeof(pwallstate),checksum);
CA_FarWrite (file,(void *)&pwallx,sizeof(pwallx));
checksum = DoChecksum((byte *)&pwallx,sizeof(pwallx),checksum);
CA_FarWrite (file,(void *)&pwally,sizeof(pwally));
checksum = DoChecksum((byte *)&pwally,sizeof(pwally),checksum);
CA_FarWrite (file,(void *)&pwalldir,sizeof(pwalldir));
checksum = DoChecksum((byte *)&pwalldir,sizeof(pwalldir),checksum);
CA_FarWrite (file,(void *)&pwallpos,sizeof(pwallpos));
checksum = DoChecksum((byte *)&pwallpos,sizeof(pwallpos),checksum);
//
// WRITE OUT CHECKSUM
//
CA_FarWrite(file, (void *)&checksum, sizeof(checksum));
return true;
}
/* SetupGameLevel();
==================
=
= LoadTheGame
=
==================
*/
boolean LoadTheGame(int file,int x,int y) DiskFlopAnim(dx, dy);
{
long checksum,oldchecksum;
objtype nullobj;
checksum = 0; ReadBytes(fd, (byte *)tilemap, 64*64); /* MAPSIZE * MAPSIZE */
DiskFlopAnim(x,y); DiskFlopAnim(dx, dy);
CA_FarRead (file,(void *)&gamestate,sizeof(gamestate));
checksum = DoChecksum((byte *)&gamestate,sizeof(gamestate),checksum);
DiskFlopAnim(x,y); for (y = 0; y < 64; y++)
#ifdef SPEAR for (x = 0; x < 64; x++)
CA_FarRead (file,(void *)&LevelRatios[0],sizeof(LRstruct)*20); actorat[y][x] = ReadInt32(fd);
checksum = DoChecksum((byte *)&LevelRatios[0],sizeof(LRstruct)*20,checksum);
#else
CA_FarRead (file,(void *)&LevelRatios[0],sizeof(LRstruct)*8);
checksum = DoChecksum((byte *)&LevelRatios[0],sizeof(LRstruct)*8,checksum);
#endif
DiskFlopAnim(x,y); DiskFlopAnim(dx, dy);
SetupGameLevel ();
DiskFlopAnim(x,y); ReadBytes(fd, (byte *)areaconnect, 37*37); /* NUMAREAS * NUMAREAS */
CA_FarRead (file,(void *)tilemap,sizeof(tilemap));
checksum = DoChecksum((byte *)tilemap,sizeof(tilemap),checksum);
DiskFlopAnim(x,y);
CA_FarRead(file,(void *)actorat,sizeof(actorat));
checksum = DoChecksum((byte *)actorat,sizeof(actorat),checksum);
CA_FarRead(file,(void *)areaconnect,sizeof(areaconnect)); DiskFlopAnim(dx, dy);
CA_FarRead(file,(void *)areabyplayer,sizeof(areabyplayer));
for (i = 0; i < 37; i++)
areabyplayer[i] = ReadInt8(fd);
InitActorList(); DiskFlopAnim(dx, dy);
DiskFlopAnim(x,y);
CA_FarRead (file,(void *)player,sizeof(*player));
while (1) InitActorList();
{
DiskFlopAnim(x,y);
CA_FarRead(file,(void *)&nullobj,sizeof(nullobj));
if (nullobj.active == ac_badobject) DiskFlopAnim(dx, dy);
/* player ptr already set up */
id = ReadInt32(fd); /* get id */
player->active = ReadInt32(fd);
player->ticcount = ReadInt32(fd);
player->obclass = ReadInt32(fd);
player->state = ReadInt32(fd);
player->flags = ReadInt8(fd);
player->distance = ReadInt32(fd);
player->dir = ReadInt32(fd);
player->x = ReadInt32(fd);
player->y = ReadInt32(fd);
player->tilex = ReadInt32(fd);
player->tiley = ReadInt32(fd);
player->areanumber = ReadInt8(fd);
player->viewx = ReadInt32(fd);
player->viewheight = ReadInt32(fd);
player->transx = ReadInt32(fd);
player->transy = ReadInt32(fd);
player->angle = ReadInt32(fd);
player->hitpoints = ReadInt32(fd);
player->speed = ReadInt32(fd);
player->temp1 = ReadInt32(fd);
player->temp2 = ReadInt32(fd);
player->temp3 = ReadInt32(fd);
/* update the id */
for (y = 0; y < 64; y++)
for (x = 0; x < 64; x++)
if (actorat[y][x] == (id | 0x8000))
actorat[y][x] = player->id | 0x8000;
while (1) {
DiskFlopAnim(dx, dy);
id = ReadInt32(fd);
if (id == 0xFFFFFFFF)
break; break;
GetNewActor(); GetNewActor();
// don't copy over the links
memcpy(new, &nullobj, sizeof(nullobj)-4); new->active = ReadInt32(fd);
new->ticcount = ReadInt32(fd);
new->obclass = ReadInt32(fd);
new->state = ReadInt32(fd);
new->flags = ReadInt8(fd);
new->distance = ReadInt32(fd);
new->dir = ReadInt32(fd);
new->x = ReadInt32(fd);
new->y = ReadInt32(fd);
new->tilex = ReadInt32(fd);
new->tiley = ReadInt32(fd);
new->areanumber = ReadInt8(fd);
new->viewx = ReadInt32(fd);
new->viewheight = ReadInt32(fd);
new->transx = ReadInt32(fd);
new->transy = ReadInt32(fd);
new->angle = ReadInt32(fd);
new->hitpoints = ReadInt32(fd);
new->speed = ReadInt32(fd);
new->temp1 = ReadInt32(fd);
new->temp2 = ReadInt32(fd);
new->temp3 = ReadInt32(fd);
for (y = 0; y < 64; y++)
for (x = 0; x < 64; x++)
if (actorat[y][x] == (id | 0x8000))
actorat[y][x] = new->id | 0x8000;
} }
DiskFlopAnim(dx, dy);
laststatobj = statobjlist + ReadInt32(fd); /* ptr offset */
for (i = 0; i < 400; i++) { /* MAXSTATS */
statobjlist[i].tilex = ReadInt8(fd);
statobjlist[i].tiley = ReadInt8(fd);
statobjlist[i].shapenum = ReadInt32(fd);
statobjlist[i].flags = ReadInt8(fd);
statobjlist[i].itemnumber = ReadInt8(fd);
statobjlist[i].visspot = &spotvis[statobjlist[i].tilex][statobjlist[i].tiley];
}
DiskFlopAnim(dx, dy);
for (i = 0; i < 64; i++) { /* MAXDOORS */
doorposition[i] = ReadInt32(fd);
}
DiskFlopAnim(dx, dy);
for (i = 0; i < 64; i++) { /* MAXDOORS */
doorobjlist[i].tilex = ReadInt8(fd);
doorobjlist[i].tiley = ReadInt8(fd);
doorobjlist[i].vertical = ReadInt8(fd);
doorobjlist[i].lock = ReadInt8(fd);
doorobjlist[i].action = ReadInt8(fd);
doorobjlist[i].ticcount = ReadInt32(fd);
}
DiskFlopAnim(dx, dy);
pwallstate = ReadInt32(fd);
pwallx = ReadInt32(fd);
pwally = ReadInt32(fd);
pwalldir = ReadInt32(fd);
pwallpos = ReadInt32(fd);
DiskFlopAnim(dx, dy);
CloseRead(fd);
return 0;
loadfail:
if (fd != -1)
CloseRead(fd);
DiskFlopAnim(x,y);
CA_FarRead (file,(void *)&laststatobj,sizeof(laststatobj));
checksum = DoChecksum((byte *)&laststatobj,sizeof(laststatobj),checksum);
DiskFlopAnim(x,y);
CA_FarRead (file,(void *)statobjlist,sizeof(statobjlist));
checksum = DoChecksum((byte *)statobjlist,sizeof(statobjlist),checksum);
DiskFlopAnim(x,y);
CA_FarRead (file,(void *)doorposition,sizeof(doorposition));
checksum = DoChecksum((byte *)doorposition,sizeof(doorposition),checksum);
DiskFlopAnim(x,y);
CA_FarRead (file,(void *)doorobjlist,sizeof(doorobjlist));
checksum = DoChecksum((byte *)doorobjlist,sizeof(doorobjlist),checksum);
DiskFlopAnim(x,y);
CA_FarRead(file,(void *)&pwallstate,sizeof(pwallstate));
checksum = DoChecksum((byte *)&pwallstate,sizeof(pwallstate),checksum);
CA_FarRead(file,(void *)&pwallx,sizeof(pwallx));
checksum = DoChecksum((byte *)&pwallx,sizeof(pwallx),checksum);
CA_FarRead(file,(void *)&pwally,sizeof(pwally));
checksum = DoChecksum((byte *)&pwally,sizeof(pwally),checksum);
CA_FarRead(file,(void *)&pwalldir,sizeof(pwalldir));
checksum = DoChecksum((byte *)&pwalldir,sizeof(pwalldir),checksum);
CA_FarRead(file,(void *)&pwallpos,sizeof(pwallpos));
checksum = DoChecksum((byte *)&pwallpos,sizeof(pwallpos),checksum);
CA_FarRead(file, (void *)&oldchecksum, sizeof(oldchecksum));
if (oldchecksum != checksum)
{
Message(STR_SAVECHT1"\n" Message(STR_SAVECHT1"\n"
STR_SAVECHT2"\n" STR_SAVECHT2"\n"
STR_SAVECHT3"\n" STR_SAVECHT3"\n"
...@@ -471,18 +717,11 @@ boolean LoadTheGame(int file,int x,int y) ...@@ -471,18 +717,11 @@ boolean LoadTheGame(int file,int x,int y)
IN_ClearKeysDown(); IN_ClearKeysDown();
IN_Ack(); IN_Ack();
gamestate.score = 0; NewGame(1, 0);
gamestate.lives = 1; return -1;
gamestate.weapon =
gamestate.chosenweapon =
gamestate.bestweapon = wp_pistol;
gamestate.ammo = 8;
}
return true;
} }
//=========================================================================== /* ======================================================================== */
/* /*
================= =================
......
...@@ -1164,11 +1164,10 @@ void DrawLSAction(int which) ...@@ -1164,11 +1164,10 @@ void DrawLSAction(int which)
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
int CP_LoadGame(int quick) int CP_LoadGame(int quick)
{ {
int handle,which,exit=0; int which, exit=0;
char name[13]; char name[13];
strcpy(name, SaveName);
strcpy(name,SaveName);
// //
// QUICKLOAD? // QUICKLOAD?
...@@ -1180,12 +1179,9 @@ int CP_LoadGame(int quick) ...@@ -1180,12 +1179,9 @@ int CP_LoadGame(int quick)
if (SaveGamesAvail[which]) if (SaveGamesAvail[which])
{ {
name[7]=which+'0'; name[7]=which+'0';
handle=open(name,O_BINARY);
lseek(handle,32,SEEK_SET);
loadedgame=true; loadedgame=true;
LoadTheGame(handle,0,0); LoadTheGame(name, 0, 0);
loadedgame=false; loadedgame=false;
close(handle);
DrawStatusBar(); DrawStatusBar();
...@@ -1209,14 +1205,10 @@ int CP_LoadGame(int quick) ...@@ -1209,14 +1205,10 @@ int CP_LoadGame(int quick)
ShootSnd(); ShootSnd();
name[7]=which+'0'; name[7]=which+'0';
handle=open(name,O_BINARY);
lseek(handle,32,SEEK_SET);
DrawLSAction(0); DrawLSAction(0);
loadedgame=true; loadedgame=true;
LoadTheGame(handle,LSA_X+8,LSA_Y+5); LoadTheGame(name, LSA_X+8, LSA_Y+5);
close(handle);
StartGame=1; StartGame=1;
ShootSnd(); ShootSnd();
...@@ -1321,10 +1313,8 @@ void PrintLSEntry(int w,int color) ...@@ -1321,10 +1313,8 @@ void PrintLSEntry(int w,int color)
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
int CP_SaveGame(int quick) int CP_SaveGame(int quick)
{ {
int handle,which,exit=0; int which, exit=0;
unsigned nwritten; char name[13], input[32];
char name[13],input[32];
strcpy(name,SaveName); strcpy(name,SaveName);
...@@ -1337,15 +1327,8 @@ int CP_SaveGame(int quick) ...@@ -1337,15 +1327,8 @@ int CP_SaveGame(int quick)
if (SaveGamesAvail[which]) if (SaveGamesAvail[which])
{ {
name[7]=which+'0'; name[7] = which+'0';
handle=creat(name,S_IREAD|S_IWRITE); SaveTheGame(name, &SaveGameNames[which][0], 0, 0);
strcpy(input,&SaveGameNames[which][0]);
nwritten = write(handle,(void *)input,32);
lseek(handle,32,SEEK_SET);
SaveTheGame(handle,0,0);
close(handle);
return 1; return 1;
} }
...@@ -1393,17 +1376,9 @@ int CP_SaveGame(int quick) ...@@ -1393,17 +1376,9 @@ int CP_SaveGame(int quick)
if (US_LineInput(LSM_X+LSItems.indent+2,LSM_Y+which*13+1,input,input,true,31,LSM_W-LSItems.indent-30)) if (US_LineInput(LSM_X+LSItems.indent+2,LSM_Y+which*13+1,input,input,true,31,LSM_W-LSItems.indent-30))
{ {
SaveGamesAvail[which] = 1; SaveGamesAvail[which] = 1;
strcpy(&SaveGameNames[which][0],input);
handle = creat(name, S_IREAD|S_IWRITE);
nwritten = write(handle, (void *)input, 32);
lseek(handle, 32, SEEK_SET);
DrawLSAction(1); DrawLSAction(1);
SaveTheGame(handle, LSA_X+8, LSA_Y+5); strcpy(&SaveGameNames[which][0],input);
SaveTheGame(name, input, LSA_X+8, LSA_Y+5);
close(handle);
ShootSnd(); ShootSnd();
exit=1; exit=1;
} }
...@@ -2622,15 +2597,13 @@ void SetupControlPanel() ...@@ -2622,15 +2597,13 @@ void SetupControlPanel()
which=f.ff_name[7]-'0'; which=f.ff_name[7]-'0';
if (which<10) if (which<10)
{ {
int handle;
char temp[32]; char temp[32];
if (ReadSaveTag(f.ff_name, temp) != -1) {
SaveGamesAvail[which]=1; SaveGamesAvail[which]=1;
handle=open(f.ff_name,O_BINARY);
read(handle,temp,32);
close(handle);
strcpy(&SaveGameNames[which][0],temp); strcpy(&SaveGameNames[which][0],temp);
} }
}
} while(!findnext(&f)); } while(!findnext(&f));
#else #else
struct _finddata_t f; struct _finddata_t f;
...@@ -2666,15 +2639,13 @@ void SetupControlPanel() ...@@ -2666,15 +2639,13 @@ void SetupControlPanel()
which=f.name[7]-'0'; which=f.name[7]-'0';
if (which<10) if (which<10)
{ {
int handle;
char temp[32]; char temp[32];
if (ReadSaveTag(f.name, temp) != -1) {
SaveGamesAvail[which]=1; SaveGamesAvail[which]=1;
handle=open(f.name,O_BINARY);
read(handle,temp,32);
close(handle);
strcpy(&SaveGameNames[which][0],temp); strcpy(&SaveGameNames[which][0],temp);
} }
}
} while(_findnext(hand, &f) != -1); } while(_findnext(hand, &f) != -1);
#endif #endif
...@@ -2705,14 +2676,12 @@ void SetupControlPanel() ...@@ -2705,14 +2676,12 @@ void SetupControlPanel()
for (x = 0; x < globbuf.gl_pathc; x++) { for (x = 0; x < globbuf.gl_pathc; x++) {
which = globbuf.gl_pathv[x][7] - '0'; which = globbuf.gl_pathv[x][7] - '0';
if (which < 10) { if (which < 10) {
int handle;
char temp[32]; char temp[32];
SaveGamesAvail[which] = 1; if (ReadSaveTag(globbuf.gl_pathv[x], temp) != -1) {
handle = open(globbuf.gl_pathv[x], O_RDONLY); SaveGamesAvail[which]=1;
read(handle, temp, 32); strcpy(&SaveGameNames[which][0],temp);
close(handle); }
strcpy(SaveGameNames[which], temp);
} }
} }
globfree(&globbuf); globfree(&globbuf);
......
...@@ -50,15 +50,7 @@ memptr demobuffer; ...@@ -50,15 +50,7 @@ memptr demobuffer;
int controlx,controly; // range from -100 to 100 per tic int controlx,controly; // range from -100 to 100 per tic
boolean buttonstate[NUMBUTTONS]; boolean buttonstate[NUMBUTTONS];
//===========================================================================
static void RemoveObj(objtype *gone); static void RemoveObj(objtype *gone);
void StopMusic();
void StartMusic();
void PlayLoop();
/* /*
============================================================================= =============================================================================
...@@ -770,9 +762,6 @@ void InitActorList() ...@@ -770,9 +762,6 @@ void InitActorList()
= Sets the global variable new to point to a free spot in objlist. = Sets the global variable new to point to a free spot in objlist.
= The free spot is inserted at the end of the liked list = The free spot is inserted at the end of the liked list
= =
= When the object list is full, the caller can either have it bomb out ot
= return a dummy object pointer that will never get used
=
========================= =========================
*/ */
...@@ -805,7 +794,7 @@ void GetNewActor() ...@@ -805,7 +794,7 @@ void GetNewActor()
= =
= RemoveObj = RemoveObj
= =
= Add the given object back into the free list, and unlink it from it's = Add the given object back into the free list, and unlink it from its
= neighbors = neighbors
= =
========================= =========================
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment