From 30d133ac6c0358f7c895df1af02ff4cca730707f Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Mon, 23 Dec 2002 00:38:21 +0100 Subject: [PATCH] rnd-20021223-1-src --- src/conftime.h | 2 +- src/files.c | 4 +++ src/game.c | 77 +++++++++++++++++++++++++++++++++++++++++--- src/libgame/misc.c | 13 +++++++- src/libgame/system.h | 4 +++ src/main.h | 4 +++ src/screens.c | 3 ++ src/tape.c | 76 ++++++++++++++++++++++++++++++++++++++++++- src/tape.h | 2 ++ 9 files changed, 177 insertions(+), 8 deletions(-) diff --git a/src/conftime.h b/src/conftime.h index 04a3c4c5..c572f214 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2002-12-19 00:19]" +#define COMPILE_DATE_STRING "[2002-12-23 00:34]" diff --git a/src/files.c b/src/files.c index e0446de5..fac13d01 100644 --- a/src/files.c +++ b/src/files.c @@ -125,6 +125,8 @@ static void setLevelInfoToDefaults() break; } } + + level.no_level_file = FALSE; } static int checkLevelElement(int element) @@ -321,6 +323,8 @@ void LoadLevel(int level_nr) if (!(file = fopen(filename, MODE_READ))) { + level.no_level_file = TRUE; + Error(ERR_WARN, "cannot read level '%s' - creating new level", filename); return; } diff --git a/src/game.c b/src/game.c index 06edf650..5a6a2489 100644 --- a/src/game.c +++ b/src/game.c @@ -100,6 +100,7 @@ #define NUM_GAME_BUTTONS 6 /* forward declaration for internal use */ +static void InitBeltMovement(void); static void CloseAllOpenTimegates(void); static void CheckGravityMovement(struct PlayerInfo *); static void KillHeroUnlessProtected(int, int); @@ -487,7 +488,7 @@ void DrawGameDoorValues() for (j=0; j<4; j++) if (stored_player[i].key[j]) DrawMiniGraphicExt(drawto, DX_KEYS + j * MINI_TILEX, DY_KEYS, - GFX_SCHLUESSEL1 + j); + IMG_KEY1 + j); DrawText(DX + XX_EMERALDS, DY + YY_EMERALDS, int2str(local_player->gems_still_needed, 3), FS_SMALL, FC_YELLOW); @@ -820,6 +821,8 @@ void InitGame() } } + InitBeltMovement(); + game.emulation = (emulate_bd ? EMU_BOULDERDASH : emulate_sb ? EMU_SOKOBAN : emulate_sp ? EMU_SUPAPLEX : EMU_NONE); @@ -1154,6 +1157,9 @@ void GameWon() if (local_player->MovPos) return; + if (tape.playing && tape.auto_play) + tape.auto_play_level_solved = TRUE; + local_player->LevelSolved = FALSE; PlaySoundStereo(SND_GAME_WINNING, SOUND_MAX_RIGHT); @@ -1879,6 +1885,67 @@ void Blurb(int x, int y) } } +static void InitBeltMovement() +{ + static int belt_base_element[4] = + { + EL_CONVEYOR_BELT1_LEFT, + EL_CONVEYOR_BELT2_LEFT, + EL_CONVEYOR_BELT3_LEFT, + EL_CONVEYOR_BELT4_LEFT + }; + static int belt_base_active_element[4] = + { + EL_CONVEYOR_BELT1_LEFT_ACTIVE, + EL_CONVEYOR_BELT2_LEFT_ACTIVE, + EL_CONVEYOR_BELT3_LEFT_ACTIVE, + EL_CONVEYOR_BELT4_LEFT_ACTIVE + }; + + int x, y, i, j; + + /* set frame order for belt animation graphic according to belt direction */ + for (i=0; i<4; i++) + { + int belt_nr = i; + + for (j=0; j<3; j++) + { + int element = belt_base_active_element[belt_nr] + j; + int graphic = el2img(element); + + if (game.belt_dir[i] == MV_LEFT) + new_graphic_info[graphic].anim_mode &= ~ANIM_REVERSE; + else + new_graphic_info[graphic].anim_mode |= ANIM_REVERSE; + } + } + + for(y=0; ykey[key_nr] = TRUE; RaiseScoreElement(element); DrawMiniGraphicExt(drawto, DX_KEYS + key_nr * MINI_TILEX, DY_KEYS, - GFX_SCHLUESSEL1 + key_nr); + IMG_KEY1 + key_nr); DrawMiniGraphicExt(window, DX_KEYS + key_nr * MINI_TILEX, DY_KEYS, - GFX_SCHLUESSEL1 + key_nr); + IMG_KEY1 + key_nr); PlaySoundLevel(x, y, SND_KEY_COLLECTING); break; } @@ -6116,9 +6183,9 @@ int DigField(struct PlayerInfo *player, player->key[key_nr] = TRUE; RaiseScoreElement(element); DrawMiniGraphicExt(drawto, DX_KEYS + key_nr * MINI_TILEX, DY_KEYS, - GFX_SCHLUESSEL1 + key_nr); + IMG_KEY1 + key_nr); DrawMiniGraphicExt(window, DX_KEYS + key_nr * MINI_TILEX, DY_KEYS, - GFX_SCHLUESSEL1 + key_nr); + IMG_KEY1 + key_nr); PlaySoundLevel(x, y, SND_KEY_COLLECTING); break; } diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 6600dfdf..e439e71d 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -450,6 +450,7 @@ void GetOptions(char *argv[]) options.graphics_directory = RO_BASE_PATH "/" GRAPHICS_DIRECTORY; options.sounds_directory = RO_BASE_PATH "/" SOUNDS_DIRECTORY; options.music_directory = RO_BASE_PATH "/" MUSIC_DIRECTORY; + options.autoplay_leveldir = NULL; options.serveronly = FALSE; options.network = FALSE; options.verbose = FALSE; @@ -500,6 +501,7 @@ void GetOptions(char *argv[]) " -g, --graphics alternative graphics directory\n" " -s, --sounds alternative sounds directory\n" " -m, --music alternative music directory\n" + " -a, --autoplay automatically play level tapes\n" " -n, --network network multiplayer game\n" " --serveronly only start network server\n" " -v, --verbose verbose mode\n" @@ -571,6 +573,15 @@ void GetOptions(char *argv[]) if (option_arg == next_option) options_left++; } + else if (strncmp(option, "-autoplay", option_len) == 0) + { + if (option_arg == NULL) + Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str); + + options.autoplay_leveldir = option_arg; + if (option_arg == next_option) + options_left++; + } else if (strncmp(option, "-network", option_len) == 0) { options.network = TRUE; @@ -1731,7 +1742,7 @@ void FreeCustomArtworkList(struct ArtworkListInfo *artwork_info) { int i; - if (artwork_info->artwork_list == NULL) + if (artwork_info == NULL || artwork_info->artwork_list == NULL) return; #if 0 diff --git a/src/libgame/system.h b/src/libgame/system.h index 463d76fc..a28c0350 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -240,16 +240,20 @@ struct OptionInfo char *display_name; char *server_host; int server_port; + char *ro_base_directory; char *rw_base_directory; char *level_directory; char *graphics_directory; char *sounds_directory; char *music_directory; + char *autoplay_leveldir; + boolean serveronly; boolean network; boolean verbose; boolean debug; + char *debug_command; }; diff --git a/src/main.h b/src/main.h index 6c60f8b9..8b992511 100644 --- a/src/main.h +++ b/src/main.h @@ -1559,6 +1559,8 @@ struct LevelInfo boolean double_speed; boolean gravity; boolean em_slippery_gems; /* EM style "gems slip from wall" behaviour */ + + boolean no_level_file; }; struct TapeInfo @@ -1578,6 +1580,8 @@ struct TapeInfo boolean recording, playing, pausing; boolean fast_forward; boolean index_search; + boolean auto_play; + boolean auto_play_level_solved; boolean quick_resume; boolean single_step; boolean changed; diff --git a/src/screens.c b/src/screens.c index 0532cdd1..ffb15a9f 100644 --- a/src/screens.c +++ b/src/screens.c @@ -235,6 +235,9 @@ void DrawMainMenu() OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2); + if (options.autoplay_leveldir) + AutoPlayTape(); + #if 0 ClearEventQueue(); #endif diff --git a/src/tape.c b/src/tape.c index cc2ad928..8ca52a03 100644 --- a/src/tape.c +++ b/src/tape.c @@ -14,6 +14,7 @@ #include "libgame/libgame.h" #include "tape.h" +#include "init.h" #include "game.h" #include "tools.h" #include "files.h" @@ -325,6 +326,8 @@ static void TapeRewind() tape.playing = FALSE; tape.fast_forward = FALSE; tape.index_search = FALSE; + tape.auto_play = (options.autoplay_leveldir != NULL); + tape.auto_play_level_solved = FALSE; tape.quick_resume = FALSE; tape.single_step = FALSE; @@ -552,7 +555,7 @@ byte *TapePlayAction() if (tape.counter >= tape.length) /* end of tape reached */ { - if (tape.index_search) + if (tape.index_search && !tape.auto_play) TapeTogglePause(TAPE_TOGGLE_MANUAL); else TapeStop(); @@ -584,6 +587,9 @@ void TapeStop() DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date); DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds); } + + if (tape.auto_play) + AutoPlayTape(); /* continue automatically playing next tape */ } unsigned int GetTapeLength() @@ -672,6 +678,74 @@ void TapeQuickLoad() } +/* ------------------------------------------------------------------------- * + * tape autoplay functions + * ------------------------------------------------------------------------- */ + +void AutoPlayTape() +{ + static LevelDirTree *autoplay_leveldir = NULL; + static boolean autoplay_initialized = FALSE; + static int autoplay_level_nr = -1; + + if (autoplay_initialized) + { + /* just finished auto-playing tape */ + printf("%s.\n", tape.auto_play_level_solved ? "solved" : "NOT SOLVED"); + } + else + { + autoplay_leveldir = getTreeInfoFromIdentifier(leveldir_first, + options.autoplay_leveldir); + + if (autoplay_leveldir == NULL) + Error(ERR_EXIT, "no such level identifier: '%s'", + options.autoplay_leveldir); + + leveldir_current = autoplay_leveldir; + + autoplay_level_nr = autoplay_leveldir->first_level; + + printf("Playing tapes of level series '%s'.\n", options.autoplay_leveldir); + + autoplay_initialized = TRUE; + } + + while (autoplay_level_nr <= autoplay_leveldir->last_level) + { + level_nr = autoplay_level_nr++; + + TapeErase(); + + printf("Level %03d: ", level_nr); + + LoadLevel(level_nr); + if (level.no_level_file) + { + printf("(no level file)\n"); + continue; + } + + LoadTape(level_nr); + if (TAPE_IS_EMPTY(tape)) + { + printf("(no tape file)\n"); + continue; + } + + break; + } + + if (autoplay_level_nr >= autoplay_leveldir->last_level) + CloseAllAndExit(0); + + printf("playing tape ... "); + + TapeStartGamePlaying(); + TapeStartIndexSearch(); +} + + /* ---------- new tape button stuff ---------------------------------------- */ /* graphic position values for tape buttons */ diff --git a/src/tape.h b/src/tape.h index 6a41a94d..89c56a63 100644 --- a/src/tape.h +++ b/src/tape.h @@ -98,6 +98,8 @@ unsigned int GetTapeLength(void); void TapeQuickSave(void); void TapeQuickLoad(void); +void AutoPlayTape(void); + void CreateTapeButtons(); void MapTapeEjectButton(); void MapTapeIndexButton(); -- 2.34.1