From 2d603d06ca862f3ca0721b66f62da188faf866c4 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sun, 9 Jun 2002 22:33:46 +0200 Subject: [PATCH] rnd-20020609-1-src --- src/editor.c | 3 + src/files.c | 33 ++++++-- src/game.c | 190 +++++++++++++++++++++++++------------------- src/game.h | 2 +- src/init.c | 6 +- src/libgame/misc.c | 39 +++++++-- src/libgame/misc.h | 2 + src/libgame/sdl.h | 4 + src/libgame/setup.c | 46 +---------- src/libgame/setup.h | 3 - src/libgame/x11.h | 4 + src/main.h | 17 ++-- src/tape.c | 12 ++- src/timestamp.h | 2 +- 14 files changed, 209 insertions(+), 154 deletions(-) diff --git a/src/editor.c b/src/editor.c index 871aa164..ac9a5d84 100644 --- a/src/editor.c +++ b/src/editor.c @@ -3920,6 +3920,9 @@ static void HandleControlButtons(struct GadgetInfo *gi) Request("No Level without Gregor Mc Duffin please !", REQ_CONFIRM); else { + if (LevelChanged()) + level.game_version = GAME_VERSION_ACTUAL; + for(x=0; xfile_version), &(level->game_version)); + level->file_version = getFileVersion(file); + level->game_version = getFileVersion(file); return chunk_size; } @@ -475,6 +476,12 @@ void LoadLevel(int level_nr) SetBorderElement(); } +static void SaveLevel_VERS(FILE *file, struct LevelInfo *level) +{ + putFileVersion(file, level->file_version); + putFileVersion(file, level->game_version); +} + static void SaveLevel_HEAD(FILE *file, struct LevelInfo *level) { int i, x, y; @@ -614,6 +621,8 @@ void SaveLevel(int level_nr) return; } + level.file_version = FILE_VERSION_ACTUAL; + level.game_version = GAME_VERSION_ACTUAL; /* check level field for 16-bit elements */ level.encoding_16bit_field = FALSE; @@ -642,7 +651,7 @@ void SaveLevel(int level_nr) putFileChunkBE(file, "CAVE", CHUNK_SIZE_NONE); putFileChunkBE(file, "VERS", FILE_VERS_CHUNK_SIZE); - WriteChunk_VERS(file, FILE_VERSION_ACTUAL, GAME_VERSION_ACTUAL); + SaveLevel_VERS(file, &level); putFileChunkBE(file, "HEAD", LEVEL_HEADER_SIZE); SaveLevel_HEAD(file, &level); @@ -704,7 +713,8 @@ static void setTapeInfoToDefaults() static int LoadTape_VERS(FILE *file, int chunk_size, struct TapeInfo *tape) { - ReadChunk_VERS(file, &(tape->file_version), &(tape->game_version)); + tape->file_version = getFileVersion(file); + tape->game_version = getFileVersion(file); return chunk_size; } @@ -736,6 +746,8 @@ static int LoadTape_HEAD(FILE *file, int chunk_size, struct TapeInfo *tape) tape->num_participating_players++; } } + + ReadUnusedBytesFromFile(file, 4); } return chunk_size; @@ -943,6 +955,12 @@ void LoadTape(int level_nr) tape.length_seconds = GetTapeLength(); } +static void SaveTape_VERS(FILE *file, struct TapeInfo *tape) +{ + putFileVersion(file, tape->file_version); + putFileVersion(file, tape->game_version); +} + static void SaveTape_HEAD(FILE *file, struct TapeInfo *tape) { int i; @@ -960,6 +978,8 @@ static void SaveTape_HEAD(FILE *file, struct TapeInfo *tape) fputc(store_participating_players, file); WriteUnusedBytesToFile(file, TAPE_HEADER_UNUSED); + + WriteUnusedBytesToFile(file, 4); } static void SaveTape_BODY(FILE *file, struct TapeInfo *tape) @@ -1001,6 +1021,9 @@ void SaveTape(int level_nr) return; } + tape.file_version = FILE_VERSION_ACTUAL; + tape.game_version = GAME_VERSION_ACTUAL; + /* count number of participating players */ for(i=0; i game.engine_version == %06d\n", game.engine_version); +#endif + + /* dynamically adjust player properties according to game engine version */ + game.initial_move_delay = + (game.engine_version <= VERSION_IDENT(2,0,1) ? INITIAL_MOVE_DELAY_ON : + INITIAL_MOVE_DELAY_OFF); + + /* dynamically adjust player properties according to level information */ + game.initial_move_delay_value = + (level.double_speed ? MOVE_DELAY_HIGH_SPEED : MOVE_DELAY_NORMAL_SPEED); + + /* dynamically adjust element properties according to game engine version */ + { + static int ep_em_slippery_wall[] = + { + EL_BETON, + EL_MAUERWERK, + EL_MAUER_LEBT, + EL_MAUER_X, + EL_MAUER_Y, + EL_MAUER_XY + }; + static int ep_em_slippery_wall_num = SIZEOF_ARRAY_INT(ep_em_slippery_wall); + + for (i=0; i VERSION_IDENT(2,0,1)) + Elementeigenschaften2[EL_MAUERND] |= EP_BIT_EM_SLIPPERY_WALL; + else + Elementeigenschaften2[EL_MAUERND] &= ~EP_BIT_EM_SLIPPERY_WALL; + } +} + + +/* + ============================================================================= + InitGame() + ----------------------------------------------------------------------------- + initialize and start new game + ============================================================================= +*/ + +void InitGame() +{ + int i, j, x, y; + + InitGameEngine(); #if DEBUG #if USE_NEW_AMOEBA_CODE @@ -636,9 +739,8 @@ void InitGame() player->last_move_dir = MV_NO_MOVING; player->is_moving = FALSE; - player->move_delay = -1; /* no initial move delay */ - player->move_delay_value = - (level.double_speed ? MOVE_DELAY_HIGH_SPEED : MOVE_DELAY_NORMAL_SPEED); + player->move_delay = game.initial_move_delay; + player->move_delay_value = game.initial_move_delay_value; player->push_delay = 0; player->push_delay_value = 5; @@ -715,19 +817,8 @@ void InitGame() } for(y=0; y game.version == %06d\n", game.version); - - /* - printf("level %d: game.version == %06d\n", level_nr, level.game_version); - printf(" file_version == %06d\n", level.file_version); - */ -#endif - - if (game.version > VERSION_IDENT(2,0,1)) - ep_em_slippery_wall[0] = EL_MAUERND; - else - ep_em_slippery_wall[0] = EL_BETON; /* dummy entry */ - - Elementeigenschaften2[EL_MAUERND] &= ~EP_BIT_EM_SLIPPERY_WALL; - - for (i=0; i= GAME_VERSION_2_0) -#endif - Elementeigenschaften2[ep_em_slippery_wall[i]] |= - EP_BIT_EM_SLIPPERY_WALL; - else - Elementeigenschaften2[ep_em_slippery_wall[i]] &= - ~EP_BIT_EM_SLIPPERY_WALL; - } - - if (IS_EM_SLIPPERY_WALL(EL_MAUERND)) - printf("IS_EM_SLIPPERY_WALL(EL_MAUERND)\n"); - else - printf("! IS_EM_SLIPPERY_WALL(EL_MAUERND)\n"); - } - if (BorderElement == EL_LEERRAUM) { SBX_Left = 0; @@ -4186,6 +4215,7 @@ void MauerAbleger(int ax, int ay) DrawGraphic(SCREENX(ax-1), SCREENY(ay), GFX_MAUER_LEFT); new_wall = TRUE; } + if (rechts_frei) { Feld[ax+1][ay] = EL_MAUERND; diff --git a/src/game.h b/src/game.h index 93e71fbc..074662a0 100644 --- a/src/game.h +++ b/src/game.h @@ -31,7 +31,7 @@ void GetPlayerConfig(void); void DrawGameDoorValues(void); -void InitGameEngine(); +void InitGameSound(); void InitGame(void); void InitMovDir(int, int); void InitAmoebaNr(int, int); diff --git a/src/init.c b/src/init.c index 1f724a11..25372817 100644 --- a/src/init.c +++ b/src/init.c @@ -105,8 +105,6 @@ void OpenAll(void) InitGfxBackground(); InitToons(); - InitGameEngine(); - DrawMainMenu(); InitNetworkServer(); @@ -180,8 +178,12 @@ static void InitMixer() static void InitSound() { + /* load custom sounds and music */ InitReloadSounds(artwork.snd_current->name); InitReloadMusic(artwork.mus_current->name); + + /* initialize sound effect lookup table for element actions */ + InitGameSound(); } static void InitTileClipmasks() diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 78a5d13e..8fe3200d 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -821,6 +821,30 @@ void putFileChunk(FILE *file, char *chunk_name, int chunk_size, } } +int getFileVersion(FILE *file) +{ + int version_major, version_minor, version_patch; + + version_major = fgetc(file); + version_minor = fgetc(file); + version_patch = fgetc(file); + fgetc(file); /* not used */ + + return VERSION_IDENT(version_major, version_minor, version_patch); +} + +void putFileVersion(FILE *file, int version) +{ + int version_major = VERSION_MAJOR(version); + int version_minor = VERSION_MINOR(version); + int version_patch = VERSION_PATCH(version); + + fputc(version_major, file); + fputc(version_minor, file); + fputc(version_patch, file); + fputc(0, file); /* not used */ +} + void ReadUnusedBytesFromFile(FILE *file, unsigned long bytes) { while (bytes-- && !feof(file)) @@ -833,6 +857,11 @@ void WriteUnusedBytesToFile(FILE *file, unsigned long bytes) fputc(0, file); } + +/* ------------------------------------------------------------------------- */ +/* functions to translate key identifiers between different format */ +/* ------------------------------------------------------------------------- */ + #define TRANSLATE_KEYSYM_TO_KEYNAME 0 #define TRANSLATE_KEYSYM_TO_X11KEYNAME 1 #define TRANSLATE_KEYNAME_TO_KEYSYM 2 @@ -962,8 +991,8 @@ void translate_keyname(Key *keysym, char **x11name, char **name, int mode) sprintf(name_buffer, "%c", '0' + (char)(key - KSYM_0)); else if (key >= KSYM_KP_0 && key <= KSYM_KP_9) sprintf(name_buffer, "keypad %c", '0' + (char)(key - KSYM_KP_0)); - else if (key >= KSYM_F1 && key <= KSYM_F24) - sprintf(name_buffer, "function F%d", (int)(key - KSYM_F1 + 1)); + else if (key >= KSYM_FKEY_FIRST && key <= KSYM_FKEY_LAST) + sprintf(name_buffer, "function F%d", (int)(key - KSYM_FKEY_FIRST + 1)); else if (key == KSYM_UNDEFINED) strcpy(name_buffer, "(undefined)"); else @@ -999,8 +1028,8 @@ void translate_keyname(Key *keysym, char **x11name, char **name, int mode) sprintf(name_buffer, "XK_%c", '0' + (char)(key - KSYM_0)); else if (key >= KSYM_KP_0 && key <= KSYM_KP_9) sprintf(name_buffer, "XK_KP_%c", '0' + (char)(key - KSYM_KP_0)); - else if (key >= KSYM_F1 && key <= KSYM_F24) - sprintf(name_buffer, "XK_F%d", (int)(key - KSYM_F1 + 1)); + else if (key >= KSYM_FKEY_FIRST && key <= KSYM_FKEY_LAST) + sprintf(name_buffer, "XK_F%d", (int)(key - KSYM_FKEY_FIRST + 1)); else if (key == KSYM_UNDEFINED) strcpy(name_buffer, "[undefined]"); else @@ -1076,7 +1105,7 @@ void translate_keyname(Key *keysym, char **x11name, char **name, int mode) ((c2 >= '0' && c1 <= '9') || c2 == '\0')) d = atoi(&name_ptr[4]); - if (d >=1 && d <= 24) + if (d >= 1 && d <= KSYM_NUM_FKEYS) key = KSYM_F1 + (Key)(d - 1); } else if (strncmp(name_ptr, "XK_", 3) == 0) diff --git a/src/libgame/misc.h b/src/libgame/misc.h index 499bd425..0febc7a9 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -89,6 +89,8 @@ int getFile32BitInteger(FILE *, int); void putFile32BitInteger(FILE *, int, int); boolean getFileChunk(FILE *, char *, int *, int); void putFileChunk(FILE *, char *, int, int); +int getFileVersion(FILE *); +void putFileVersion(FILE *, int); void ReadUnusedBytesFromFile(FILE *, unsigned long); void WriteUnusedBytesToFile(FILE *, unsigned long); diff --git a/src/libgame/sdl.h b/src/libgame/sdl.h index a4ce8d64..962754af 100644 --- a/src/libgame/sdl.h +++ b/src/libgame/sdl.h @@ -314,6 +314,10 @@ struct XY #define KSYM_F23 KSYM_UNDEFINED #define KSYM_F24 KSYM_UNDEFINED +#define KSYM_FKEY_FIRST KSYM_F1 +#define KSYM_FKEY_LAST KSYM_F15 +#define KSYM_NUM_FKEYS (KSYM_FKEY_LAST - KSYM_FKEY_FIRST + 1) + /* SDL function definitions */ diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 27c05e55..f6688b1d 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -516,50 +516,6 @@ void InitLevelSetupDirectory(char *level_subdir) createDirectory(getLevelSetupDir(level_subdir), "level setup",PERMS_PRIVATE); } -void ReadChunk_VERS(FILE *file, int *file_version, int *game_version) -{ - int file_version_major, file_version_minor, file_version_patch; - int game_version_major, game_version_minor, game_version_patch; - - file_version_major = fgetc(file); - file_version_minor = fgetc(file); - file_version_patch = fgetc(file); - fgetc(file); /* not used */ - - game_version_major = fgetc(file); - game_version_minor = fgetc(file); - game_version_patch = fgetc(file); - fgetc(file); /* not used */ - - *file_version = VERSION_IDENT(file_version_major, - file_version_minor, - file_version_patch); - - *game_version = VERSION_IDENT(game_version_major, - game_version_minor, - game_version_patch); -} - -void WriteChunk_VERS(FILE *file, int file_version, int game_version) -{ - int file_version_major = VERSION_MAJOR(file_version); - int file_version_minor = VERSION_MINOR(file_version); - int file_version_patch = VERSION_PATCH(file_version); - int game_version_major = VERSION_MAJOR(game_version); - int game_version_minor = VERSION_MINOR(game_version); - int game_version_patch = VERSION_PATCH(game_version); - - fputc(file_version_major, file); - fputc(file_version_minor, file); - fputc(file_version_patch, file); - fputc(0, file); /* not used */ - - fputc(game_version_major, file); - fputc(game_version_minor, file); - fputc(game_version_patch, file); - fputc(0, file); /* not used */ -} - /* ------------------------------------------------------------------------- */ /* some functions to handle lists of level directories */ @@ -1917,7 +1873,7 @@ void LoadLevelArtworkInfo() sortTreeInfo(&artwork.snd_first, compareTreeInfoEntries); sortTreeInfo(&artwork.mus_first, compareTreeInfoEntries); -#if 1 +#if 0 dumpTreeInfo(artwork.gfx_first, 0); dumpTreeInfo(artwork.snd_first, 0); dumpTreeInfo(artwork.mus_first, 0); diff --git a/src/libgame/setup.h b/src/libgame/setup.h index 24cb6580..5096f2b7 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -150,9 +150,6 @@ void InitScoreDirectory(char *); void InitUserLevelDirectory(char *); void InitLevelSetupDirectory(char *); -void ReadChunk_VERS(FILE *, int *, int *); -void WriteChunk_VERS(FILE *, int, int); - TreeInfo *newTreeInfo(); void pushTreeInfo(TreeInfo **, TreeInfo *); int numTreeInfo(TreeInfo *); diff --git a/src/libgame/x11.h b/src/libgame/x11.h index 3ccac795..d19b75e7 100644 --- a/src/libgame/x11.h +++ b/src/libgame/x11.h @@ -286,6 +286,10 @@ struct XY #define KSYM_F23 XK_F23 #define KSYM_F24 XK_F24 +#define KSYM_FKEY_FIRST KSYM_F1 +#define KSYM_FKEY_LAST KSYM_F24 +#define KSYM_NUM_FKEYS (KSYM_FKEY_LAST - KSYM_FKEY_FIRST + 1) + /* X11 function definitions */ diff --git a/src/main.h b/src/main.h index 52f9e850..5f5f835a 100644 --- a/src/main.h +++ b/src/main.h @@ -254,7 +254,8 @@ struct PlayerInfo struct LevelInfo { int file_version; /* file format version the level is stored with */ - int game_version; /* game engine version the level was created with */ + int game_version; /* game release version the level was created with */ + boolean encoding_16bit_field; /* level contains 16-bit elements */ boolean encoding_16bit_yamyam; /* yamyam contains 16-bit elements */ boolean encoding_16bit_amoeba; /* amoeba contains 16-bit elements */ @@ -281,9 +282,10 @@ struct LevelInfo struct TapeInfo { - int file_version; /* file format version the tape is stored with */ - int game_version; /* game engine version the tape was created with */ - int version; + int file_version; /* file format version the tape is stored with */ + int game_version; /* game release version the tape was created with */ + int engine_version; /* game engine version the tape was recorded with */ + int level_nr; unsigned long random_seed; unsigned long date; @@ -310,8 +312,13 @@ struct TapeInfo struct GameInfo { - int version; + /* constant within running game */ + int engine_version; int emulation; + int initial_move_delay; + int initial_move_delay_value; + + /* variable within running game */ int yam_content_nr; boolean magic_wall_active; int magic_wall_time_left; diff --git a/src/tape.c b/src/tape.c index 3c39d5ab..14341da9 100644 --- a/src/tape.c +++ b/src/tape.c @@ -303,10 +303,14 @@ void TapeErase() tape.level_nr = level_nr; tape.pos[tape.counter].delay = 0; tape.changed = TRUE; + tape.date = 10000*(time->tm_year % 100) + 100*time->tm_mon + time->tm_mday; - tape.game_version = GAME_VERSION_ACTUAL; tape.random_seed = InitRND(NEW_RANDOMIZE); + tape.file_version = FILE_VERSION_ACTUAL; + tape.game_version = GAME_VERSION_ACTUAL; + tape.engine_version = level.game_version; + for(i=0; i