From cdc3c940197937b0508a1eb7dcf44874951908b7 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Wed, 23 Nov 2005 00:11:09 +0100 Subject: [PATCH] rnd-20051123-1-src --- src/conftime.h | 2 +- src/editor.c | 7 +++++- src/events.c | 4 ++++ src/game.c | 63 ++++++++++++++++++++++++++++---------------------- src/init.c | 12 ++++++++++ src/main.h | 9 +++++++- src/network.c | 8 +++++-- src/screens.c | 31 +++++++++++++++++++++++++ src/screens.h | 2 ++ src/tape.c | 10 ++++++-- src/tape.h | 2 +- 11 files changed, 115 insertions(+), 35 deletions(-) diff --git a/src/conftime.h b/src/conftime.h index 3352ec2e..ab6708a4 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2005-11-22 02:31]" +#define COMPILE_DATE_STRING "[2005-11-22 23:49]" diff --git a/src/editor.c b/src/editor.c index 4385eb8b..9e3f01e5 100644 --- a/src/editor.c +++ b/src/editor.c @@ -9462,13 +9462,18 @@ static void HandleControlButtons(struct GadgetInfo *gi) DrawCompleteVideoDisplay(); + level_editor_test_game = TRUE; + +#if 1 + StartGameActions(FALSE, setup.autorecord, NEW_RANDOMIZE); +#else if (setup.autorecord) TapeStartRecording(); - level_editor_test_game = TRUE; game_status = GAME_MODE_PLAYING; InitGame(); +#endif } break; diff --git a/src/events.c b/src/events.c index debb368b..8c3be2c4 100644 --- a/src/events.c +++ b/src/events.c @@ -696,6 +696,9 @@ void HandleKey(Key key, int key_status) if (game_status == GAME_MODE_MAIN && key == setup.shortcut.toggle_pause) { +#if 1 + StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE); +#else if (setup.autorecord) TapeStartRecording(); @@ -709,6 +712,7 @@ void HandleKey(Key key, int key_status) StopAnimation(); InitGame(); } +#endif return; } diff --git a/src/game.c b/src/game.c index 78a112f2..d8039785 100644 --- a/src/game.c +++ b/src/game.c @@ -2196,7 +2196,8 @@ void InitGame() #endif } - CloseDoor(DOOR_CLOSE_1); + if (!game.restart_level) + CloseDoor(DOOR_CLOSE_1); /* !!! FIX THIS (START) !!! */ if (level.game_engine_type == GAME_ENGINE_TYPE_EM) @@ -2220,40 +2221,48 @@ void InitGame() } /* !!! FIX THIS (END) !!! */ - /* copy default game door content to main double buffer */ - BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, - DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY); + if (!game.restart_level) + { + /* copy default game door content to main double buffer */ + BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, + DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY); + } DrawGameDoorValues(); - UnmapGameButtons(); - UnmapTapeButtons(); - game_gadget[SOUND_CTRL_ID_MUSIC]->checked = setup.sound_music; - game_gadget[SOUND_CTRL_ID_LOOPS]->checked = setup.sound_loops; - game_gadget[SOUND_CTRL_ID_SIMPLE]->checked = setup.sound_simple; - MapGameButtons(); - MapTapeButtons(); + if (!game.restart_level) + { + UnmapGameButtons(); + UnmapTapeButtons(); + game_gadget[SOUND_CTRL_ID_MUSIC]->checked = setup.sound_music; + game_gadget[SOUND_CTRL_ID_LOOPS]->checked = setup.sound_loops; + game_gadget[SOUND_CTRL_ID_SIMPLE]->checked = setup.sound_simple; + MapGameButtons(); + MapTapeButtons(); - /* copy actual game door content to door double buffer for OpenDoor() */ - BlitBitmap(drawto, bitmap_db_door, - DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1); + /* copy actual game door content to door double buffer for OpenDoor() */ + BlitBitmap(drawto, bitmap_db_door, + DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1); - OpenDoor(DOOR_OPEN_ALL); + OpenDoor(DOOR_OPEN_ALL); - PlaySoundStereo(SND_GAME_STARTING, SOUND_MIDDLE); + PlaySoundStereo(SND_GAME_STARTING, SOUND_MIDDLE); - if (setup.sound_music) - PlayLevelMusic(); + if (setup.sound_music) + PlayLevelMusic(); - KeyboardAutoRepeatOffUnlessAutoplay(); + KeyboardAutoRepeatOffUnlessAutoplay(); - if (options.debug) - { - for (i = 0; i < MAX_PLAYERS; i++) - printf("Player %d %sactive.\n", - i + 1, (stored_player[i].active ? "" : "not ")); + if (options.debug) + { + for (i = 0; i < MAX_PLAYERS; i++) + printf("Player %d %sactive.\n", + i + 1, (stored_player[i].active ? "" : "not ")); + } } + game.restart_level = FALSE; + #if 0 printf("::: starting game [%d]\n", FrameCounter); #endif @@ -7889,7 +7898,7 @@ static int getModifiedActionNumber(int value_old, int value_min, int value_max, value_new); } -static void ExecuteCustomElementAction(int x, int y, int element, int page) +static void ExecuteCustomElementAction(int element, int page) { struct ElementInfo *ei = &element_info[element]; struct ElementChangeInfo *change = &ei->change_page[page]; @@ -7963,7 +7972,7 @@ static void ExecuteCustomElementAction(int x, int y, int element, int page) case CA_RESTART_LEVEL: { - printf("::: CA_RESTART_LEVEL -- not yet implemented\n"); + game.restart_level = TRUE; break; } @@ -8550,7 +8559,7 @@ static void ChangeElement(int x, int y, int page) #if 1 if (change->use_action) - ExecuteCustomElementAction(x, y, element, page); + ExecuteCustomElementAction(element, page); #endif if (ChangeElementNow(x, y, element, page)) diff --git a/src/init.c b/src/init.c index 718f4394..60f11d76 100644 --- a/src/init.c +++ b/src/init.c @@ -3949,6 +3949,12 @@ void InitElementPropertiesEngine(int engine_version) if (element_info[i].change_page[j].can_change) SET_PROPERTY(i, EP_CAN_CHANGE, TRUE); + /* ---------- HAS_ACTION ----------------------------------------------- */ + SET_PROPERTY(i, EP_HAS_ACTION, FALSE); /* default: has no action */ + for (j = 0; j < element_info[i].num_change_pages; j++) + if (element_info[i].change_page[j].use_action) + SET_PROPERTY(i, EP_HAS_ACTION, TRUE); + /* ---------- GFX_CRUMBLED --------------------------------------------- */ #if 1 SET_PROPERTY(i, EP_GFX_CRUMBLED, @@ -4280,6 +4286,11 @@ static void InitSetup() options.verbose = TRUE; } +static void InitGameInfo() +{ + game.restart_level = FALSE; +} + static void InitPlayerInfo() { int i; @@ -4838,6 +4849,7 @@ void OpenAll() InitSetup(); + InitGameInfo(); InitPlayerInfo(); InitArtworkInfo(); /* needed before loading gfx, sound & music */ InitArtworkConfig(); /* needed before forking sound child process */ diff --git a/src/main.h b/src/main.h index a5b300d7..c8aca94a 100644 --- a/src/main.h +++ b/src/main.h @@ -155,7 +155,10 @@ #define EP_WALK_TO_OBJECT 81 #define EP_DEADLY 82 -#define NUM_ELEMENT_PROPERTIES 83 +/* values for internal purpose only (game engine) */ +#define EP_HAS_ACTION 83 + +#define NUM_ELEMENT_PROPERTIES 84 #define NUM_EP_BITFIELDS ((NUM_ELEMENT_PROPERTIES + 31) / 32) #define EP_BITFIELD_BASE 0 @@ -506,6 +509,7 @@ HAS_PROPERTY(e, EP_CAN_EXPLODE_BY_EXPLOSION) #define COULD_MOVE_INTO_ACID(e) HAS_PROPERTY(e, EP_COULD_MOVE_INTO_ACID) #define MAYBE_DONT_COLLIDE_WITH(e) HAS_PROPERTY(e, EP_MAYBE_DONT_COLLIDE_WITH) +#define HAS_ACTION(e) HAS_PROPERTY(e, EP_HAS_ACTION) /* special macros used in game engine */ #define IS_CUSTOM_ELEMENT(e) ((e) >= EL_CUSTOM_START && \ @@ -1862,6 +1866,9 @@ struct GameInfo int player_boring_delay_random; int player_sleeping_delay_fixed; int player_sleeping_delay_random; + + /* values for special game initialization control */ + boolean restart_level; }; struct GlobalInfo diff --git a/src/network.c b/src/network.c index 575e846b..104b83f9 100644 --- a/src/network.c +++ b/src/network.c @@ -500,12 +500,12 @@ static void Handle_OP_START_PLAYING() { LevelDirTree *new_leveldir; int new_level_nr; - int dummy; /* !!! HAS NO MEANING ANYMORE !!! */ + int dummy; unsigned long new_random_seed; char *new_leveldir_identifier; new_level_nr = (buffer[2] << 8) + buffer[3]; - dummy = (buffer[4] << 8) + buffer[5]; + dummy = (buffer[4] << 8) + buffer[5]; /* (obsolete) */ new_random_seed = (buffer[6] << 24) | (buffer[7] << 16) | (buffer[8] << 8) | (buffer[9]); new_leveldir_identifier = (char *)&buffer[10]; @@ -532,6 +532,9 @@ static void Handle_OP_START_PLAYING() LoadTape(level_nr); LoadLevel(level_nr); +#if 1 + StartGameActions(FALSE, setup.autorecord, new_random_seed); +#else if (setup.autorecord) TapeStartRecording(); @@ -542,6 +545,7 @@ static void Handle_OP_START_PLAYING() game_status = GAME_MODE_PLAYING; InitGame(); +#endif } static void Handle_OP_PAUSE_PLAYING() diff --git a/src/screens.c b/src/screens.c index 7d783a9b..c8bcf368 100644 --- a/src/screens.c +++ b/src/screens.c @@ -511,6 +511,9 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) } else if (y == 5) { +#if 1 + StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE); +#else if (setup.autorecord) TapeStartRecording(); @@ -524,6 +527,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) StopAnimation(); InitGame(); } +#endif } else if (y == 6) { @@ -3082,6 +3086,9 @@ void HandleGameActions() } else { + if (game.restart_level) + StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE); + if (local_player->LevelSolved) GameWon(); @@ -3096,6 +3103,30 @@ void HandleGameActions() } } +void StartGameActions(boolean init_network_game, boolean record_tape, + long random_seed) +{ + if (record_tape) + TapeStartRecording(random_seed); + +#if defined(NETWORK_AVALIABLE) + if (init_network_game) + { + SendToServer_StartPlaying(); + + return; + } +#endif + + StopAnimation(); + + game_status = GAME_MODE_PLAYING; + + InitRND(random_seed); + + InitGame(); +} + /* ---------- new screen button stuff -------------------------------------- */ /* graphic position and size values for buttons and scrollbars */ diff --git a/src/screens.h b/src/screens.h index 949267f0..58ea5ddb 100644 --- a/src/screens.h +++ b/src/screens.h @@ -32,6 +32,8 @@ void HandleSetupScreen(int, int, int, int, int); void HandleTypeName(int, Key); void HandleGameActions(void); +void StartGameActions(boolean, boolean, long); + void CreateScreenGadgets(); void FreeScreenGadgets(); diff --git a/src/tape.c b/src/tape.c index 05c6f7c2..44062885 100644 --- a/src/tape.c +++ b/src/tape.c @@ -711,13 +711,19 @@ static void TapeRewind() InitRND(tape.random_seed); } -void TapeStartRecording() +static void TapeSetRandomSeed(long random_seed) +{ + tape.random_seed = InitRND(random_seed); +} + +void TapeStartRecording(long random_seed) { if (!TAPE_IS_STOPPED(tape)) TapeStop(); TapeErase(); TapeRewind(); + TapeSetRandomSeed(random_seed); tape.recording = TRUE; @@ -732,7 +738,7 @@ void TapeStartRecording() static void TapeStartGameRecording() { - TapeStartRecording(); + TapeStartRecording(NEW_RANDOMIZE); #if defined(NETWORK_AVALIABLE) if (options.network) diff --git a/src/tape.h b/src/tape.h index 4bddf23b..3cb2038a 100644 --- a/src/tape.h +++ b/src/tape.h @@ -98,7 +98,7 @@ void DrawCompleteVideoDisplay(void); void TapeDeactivateDisplayOn(); void TapeDeactivateDisplayOff(boolean); -void TapeStartRecording(void); +void TapeStartRecording(long); void TapeHaltRecording(void); void TapeStopRecording(void); void TapeRecordAction(byte *); -- 2.34.1