From 05651fcbc154b1d8321d6e4e9374cfcdd274feda Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Mon, 23 Nov 1998 00:06:29 +0100 Subject: [PATCH] rnd-19981123-1 --- src/files.c | 402 ++++++++++++++++++++++++++++++++++++-------------- src/game.c | 50 ++++--- src/main.h | 25 ++-- src/screens.c | 2 - src/tools.c | 1 - 5 files changed, 330 insertions(+), 150 deletions(-) diff --git a/src/files.c b/src/files.c index 46671d46..cb1199d3 100644 --- a/src/files.c +++ b/src/files.c @@ -22,7 +22,14 @@ #include "tape.h" #include "joystick.h" -#define MAX_LINE_LEN 1000 +#define MAX_LINE_LEN 1000 /* file input line length */ +#define CHUNK_ID_LEN 4 /* IFF style chunk id length */ +#define LEVEL_HEADER_SIZE 80 /* size of level file header */ +#define LEVEL_HEADER_UNUSED 18 /* unused level header bytes */ +#define TAPE_HEADER_SIZE 20 /* size of tape file header */ +#define TAPE_HEADER_UNUSED 7 /* unused tape header bytes */ +#define FILE_VERSION_1_0 10 /* old 1.0 file version */ +#define FILE_VERSION_1_2 12 /* actual file version */ static void SaveUserLevelInfo(); /* for 'InitUserLevelDir()' */ static char *getSetupLine(char *, int); /* for 'SaveUserLevelInfo()' */ @@ -139,13 +146,52 @@ static void InitUserLevelDirectory(char *level_subdir) } } +static void setLevelInfoToDefaults() +{ + int i, x, y; + + lev_fieldx = level.fieldx = STD_LEV_FIELDX; + lev_fieldy = level.fieldy = STD_LEV_FIELDY; + + for(x=0; x 0 && cookie[strlen(cookie) - 1] == '\n') + cookie[strlen(cookie) - 1] = '\0'; + + if (strcmp(cookie, LEVEL_COOKIE_10) == 0) /* old 1.0 level format */ + file_version = FILE_VERSION_1_0; + else if (strcmp(cookie, LEVEL_COOKIE) != 0) /* unknown level format */ { - fgets(cookie, LEVEL_COOKIE_LEN, file); - fgetc(file); + Error(ERR_WARN, "wrong file identifier of level file '%s'", filename); + fclose(file); + return; + } - if (strcmp(cookie,LEVEL_COOKIE)) + /* read chunk "HEAD" */ + if (file_version >= FILE_VERSION_1_2) + { + /* first check header chunk identifier and chunk length */ + fgets(chunk, CHUNK_ID_LEN + 1, file); + chunk_length = + (fgetc(file)<<24) | (fgetc(file)<<16) | (fgetc(file)<<8) | fgetc(file); + if (strcmp(chunk, "HEAD") || chunk_length != LEVEL_HEADER_SIZE) { - Error(ERR_WARN, "wrong format of level file '%s'", filename); + Error(ERR_WARN, "wrong 'HEAD' chunk of level file '%s'", filename); fclose(file); - file = NULL; + return; } } - if (file) - { - lev_fieldx = level.fieldx = fgetc(file); - lev_fieldy = level.fieldy = fgetc(file); - - level.time = (fgetc(file)<<8) | fgetc(file); - level.edelsteine = (fgetc(file)<<8) | fgetc(file); - for(i=0; i= FILE_VERSION_1_2) { - lev_fieldx = level.fieldx = STD_LEV_FIELDX; - lev_fieldy = level.fieldy = STD_LEV_FIELDY; - - level.time = 100; - level.edelsteine = 0; - strcpy(level.name, "Nameless Level"); - for(i=0; i> 24) & 0xff, file); + fputc((chunk_length >> 16) & 0xff, file); + fputc((chunk_length >> 8) & 0xff, file); + fputc((chunk_length >> 0) & 0xff, file); fputc(level.fieldx, file); fputc(level.fieldy, file); @@ -275,9 +337,17 @@ void SaveLevel(int level_nr) fputc(level.dauer_ablenk, file); fputc(level.amoebe_inhalt, file); - for(i=0; i> 24) & 0xff, file); + fputc((chunk_length >> 16) & 0xff, file); + fputc((chunk_length >> 8) & 0xff, file); + fputc((chunk_length >> 0) & 0xff, file); + for(y=0; y 0 && cookie[strlen(cookie) - 1] == '\n') + cookie[strlen(cookie) - 1] = '\0'; + + if (strcmp(cookie, TAPE_COOKIE_10) == 0) /* old 1.0 tape format */ + file_version = FILE_VERSION_1_0; + else if (strcmp(cookie, TAPE_COOKIE) != 0) /* unknown tape format */ { - fgets(cookie, LEVELREC_COOKIE_LEN, file); - fgetc(file); - if (!strcmp(cookie, LEVELREC_COOKIE_10)) /* old 1.0 tape format */ - levelrec_10 = TRUE; - else if (strcmp(cookie, LEVELREC_COOKIE)) /* unknown tape format */ + Error(ERR_WARN, "wrong file identifier of tape file '%s'", filename); + fclose(file); + return; + } + + /* read chunk "HEAD" */ + if (file_version >= FILE_VERSION_1_2) + { + /* first check header chunk identifier and chunk length */ + fgets(chunk, CHUNK_ID_LEN + 1, file); + chunk_length = + (fgetc(file)<<24) | (fgetc(file)<<16) | (fgetc(file)<<8) | fgetc(file); + + if (strcmp(chunk, "HEAD") || chunk_length != TAPE_HEADER_SIZE) { - Error(ERR_WARN, "wrong format of level recording file '%s'", filename); + Error(ERR_WARN, "wrong 'HEAD' chunk of tape file '%s'", filename); fclose(file); - file = NULL; + return; } } - if (!file) - return; - tape.random_seed = (fgetc(file)<<24) | (fgetc(file)<<16) | (fgetc(file)<<8) | fgetc(file); tape.date = @@ -323,6 +413,28 @@ void LoadTape(int level_nr) tape.length = (fgetc(file)<<24) | (fgetc(file)<<16) | (fgetc(file)<<8) | fgetc(file); + /* read header fields that are new since version 1.2 */ + if (file_version >= FILE_VERSION_1_2) + { + byte store_participating_players = fgetc(file); + + for(i=0; i= FILE_VERSION_1_2) { - int j; + /* next check body chunk identifier and chunk length */ + fgets(chunk, CHUNK_ID_LEN + 1, file); + chunk_length = + (fgetc(file)<<24) | (fgetc(file)<<16) | (fgetc(file)<<8) | fgetc(file); + if (strcmp(chunk, "BODY") || + chunk_length != (num_participating_players + 1) * tape.length) + { + Error(ERR_WARN, "wrong 'BODY' chunk of tape file '%s'", filename); + fclose(file); + return; + } + } + for(i=0; i= MAX_TAPELEN) break; for(j=0; j 0) - { - tape.pos[i].action[j] = MV_NO_MOVING; + tape.pos[i].action[j] = MV_NO_MOVING; + + /* pre-1.2 tapes store data for only one player */ + if (file_version == FILE_VERSION_1_0 && j > 0) continue; - } - tape.pos[i].action[j] = fgetc(file); + + if (player_participates[j]) + tape.pos[i].action[j] = fgetc(file); } tape.pos[i].delay = fgetc(file); - if (levelrec_10) + if (file_version == FILE_VERSION_1_0) { /* eliminate possible diagonal moves in old tapes */ /* this is only for backward compatibility */ @@ -392,10 +520,14 @@ void LoadTape(int level_nr) void SaveTape(int level_nr) { - int i; + int i, j; char filename[MAX_FILENAME_LEN]; FILE *file; boolean new_tape = TRUE; + boolean player_participates[MAX_PLAYERS]; + byte store_participating_players; + int num_participating_players; + int chunk_length; InitTapeDirectory(leveldir[leveldir_nr].filename); @@ -413,36 +545,80 @@ void SaveTape(int level_nr) return; } + for(i=0; i> 24) & 0xff,file); - fputc((tape.random_seed >> 16) & 0xff,file); - fputc((tape.random_seed >> 8) & 0xff,file); - fputc((tape.random_seed >> 0) & 0xff,file); + fputc((chunk_length >> 24) & 0xff, file); + fputc((chunk_length >> 16) & 0xff, file); + fputc((chunk_length >> 8) & 0xff, file); + fputc((chunk_length >> 0) & 0xff, file); - fputc((tape.date >> 24) & 0xff,file); - fputc((tape.date >> 16) & 0xff,file); - fputc((tape.date >> 8) & 0xff,file); - fputc((tape.date >> 0) & 0xff,file); + fputc((tape.random_seed >> 24) & 0xff, file); + fputc((tape.random_seed >> 16) & 0xff, file); + fputc((tape.random_seed >> 8) & 0xff, file); + fputc((tape.random_seed >> 0) & 0xff, file); - fputc((tape.length >> 24) & 0xff,file); - fputc((tape.length >> 16) & 0xff,file); - fputc((tape.length >> 8) & 0xff,file); - fputc((tape.length >> 0) & 0xff,file); + fputc((tape.date >> 24) & 0xff, file); + fputc((tape.date >> 16) & 0xff, file); + fputc((tape.date >> 8) & 0xff, file); + fputc((tape.date >> 0) & 0xff, file); + + fputc((tape.length >> 24) & 0xff, file); + fputc((tape.length >> 16) & 0xff, file); + fputc((tape.length >> 8) & 0xff, file); + fputc((tape.length >> 0) & 0xff, file); + + fputc(store_participating_players, file); + + for(i=0; i> 24) & 0xff, file); + fputc((chunk_length >> 16) & 0xff, file); + fputc((chunk_length >> 8) & 0xff, file); + fputc((chunk_length >> 0) & 0xff, file); for(i=0; ielement_nr); - printf("[Local player is %d and currently %s.]\n", - local_player->element_nr, - local_player->active ? "active" : "not active"); + if (options.verbose) + { + printf("Player %d activated.\n", player->element_nr); + printf("[Local player is %d and currently %s.]\n", + local_player->element_nr, + local_player->active ? "active" : "not active"); + } } Feld[x][y] = EL_LEERRAUM; @@ -367,20 +370,22 @@ void InitGame() } } - for (i=0; ipresent, - player->connected, - player->active); - if (local_player == player) - printf("Player %d is local player.\n", i+1); + for (i=0; ipresent, + player->connected, + player->active); + if (local_player == player) + printf("Player %d is local player.\n", i+1); + } } - game_emulation = (emulate_bd ? EMU_BOULDERDASH : emulate_sb ? EMU_SOKOBAN : EMU_NONE); @@ -438,11 +443,12 @@ void InitGame() XAutoRepeatOff(display); - - for (i=0; i<4; i++) - printf("Spieler %d %saktiv.\n", - i+1, (stored_player[i].active ? "" : "nicht ")); - + if (options.verbose) + { + for (i=0; i<4; i++) + printf("Spieler %d %saktiv.\n", + i+1, (stored_player[i].active ? "" : "nicht ")); + } } void InitMovDir(int x, int y) @@ -3414,11 +3420,11 @@ boolean MoveFigure(struct PlayerInfo *player, int dx, int dy) if (player->MovPos) { - /* should only happen if pre-1.0 tape recordings are played */ + /* should only happen if pre-1.2 tape recordings are played */ /* this is only for backward compatibility */ #if DEBUG - printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.0 LEVEL TAPES.\n"); + printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES.\n"); #endif while (player->MovPos) diff --git a/src/main.h b/src/main.h index 2026f3a4..cbf07655 100644 --- a/src/main.h +++ b/src/main.h @@ -194,7 +194,6 @@ typedef unsigned char byte; #define MAX_LEVNAMLEN 32 #define MAX_LEVSCORE_ENTRIES 16 -#define NUM_FREE_LVHD_BYTES 18 #define MAX_TAPELEN (1000 * 50) /* max. time * framerate */ #define MAX_LEVDIR_FILENAME (64+1) @@ -1115,22 +1114,24 @@ extern int num_bg_loops; #define JOYDAT_PERMS LEVEL_PERMS #define SETUP_PERMS LEVEL_PERMS -/* old cookies */ -#define LEVELREC_COOKIE_10 "ROCKSNDIAMONDS_LEVELREC_FILE_VERSION_1.0" - -#define LEVEL_COOKIE "ROCKSNDIAMONDS_LEVEL_FILE_VERSION_1.0" +#define LEVEL_COOKIE "ROCKSNDIAMONDS_LEVEL_FILE_VERSION_1.2" #define SCORE_COOKIE "ROCKSNDIAMONDS_SCORE_FILE_VERSION_1.2" -#define LEVELREC_COOKIE "ROCKSNDIAMONDS_LEVELREC_FILE_VERSION_1.2" +#define TAPE_COOKIE "ROCKSNDIAMONDS_TAPE_FILE_VERSION_1.2" #define SETUP_COOKIE "ROCKSNDIAMONDS_SETUP_FILE_VERSION_1.2" #define LEVELSETUP_COOKIE "ROCKSNDIAMONDS_LEVELSETUP_FILE_VERSION_1.2" #define LEVELINFO_COOKIE "ROCKSNDIAMONDS_LEVELINFO_FILE_VERSION_1.2" -#define LEVEL_COOKIE_LEN (strlen(LEVEL_COOKIE)+1) -#define SCORE_COOKIE_LEN (strlen(SCORE_COOKIE)+1) -#define LEVELREC_COOKIE_LEN (strlen(LEVELREC_COOKIE)+1) -#define SETUP_COOKIE_LEN (strlen(SETUP_COOKIE)+1) -#define LEVELSETUP_COOKIE_LEN (strlen(LEVELSETUP_COOKIE)+1) -#define LEVELINFO_COOKIE_LEN (strlen(LEVELINFO_COOKIE)+1) +/* old cookies for backward compatibility */ +#define LEVEL_COOKIE_10 "ROCKSNDIAMONDS_LEVEL_FILE_VERSION_1.0" +#define TAPE_COOKIE_10 "ROCKSNDIAMONDS_LEVELREC_FILE_VERSION_1.0" + +#define LEVEL_COOKIE_LEN (strlen(LEVEL_COOKIE) + 1) +#define SCORE_COOKIE_LEN (strlen(SCORE_COOKIE) + 1) +#define LEVELREC_COOKIE_LEN (strlen(LEVELREC_COOKIE) + 1) +#define TAPE_COOKIE_LEN (strlen(TAPE_COOKIE) + 1) +#define SETUP_COOKIE_LEN (strlen(SETUP_COOKIE) + 1) +#define LEVELSETUP_COOKIE_LEN (strlen(LEVELSETUP_COOKIE) + 1) +#define LEVELINFO_COOKIE_LEN (strlen(LEVELINFO_COOKIE) + 1) #define VERSION_STRING "1.2 preview 1" #define GAMETITLE_STRING "Rocks'n'Diamonds" diff --git a/src/screens.c b/src/screens.c index 82c3e764..bcf96b32 100644 --- a/src/screens.c +++ b/src/screens.c @@ -892,9 +892,7 @@ void HandleChooseLevel(int mx, int my, int dx, int dy, int button) getLastPlayedLevelOfLevelSeries(leveldir[leveldir_nr].filename); SaveLevelSetup(); - TapeErase(); - LoadTape(level_nr); game_status = MAINMENU; DrawMainMenu(); diff --git a/src/tools.c b/src/tools.c index 671e2d89..e6b8d9a9 100644 --- a/src/tools.c +++ b/src/tools.c @@ -11,7 +11,6 @@ * tools.c * ***********************************************************/ -#include #include #ifdef __FreeBSD__ -- 2.34.1