From e0fa772bd160d45789fd11f9808b8833757b43d9 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sun, 5 Jan 2025 18:13:02 +0100 Subject: [PATCH] added support for restart key when playing BD games with multiple lives --- src/events.c | 10 ++++++++++ src/tape.c | 24 ++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/events.c b/src/events.c index 16a84e92..bdec3b21 100644 --- a/src/events.c +++ b/src/events.c @@ -1409,6 +1409,16 @@ static void HandleButtonOrFinger(int mx, int my, int button) static boolean checkTextInputKey(Key key) { + static int game_status_last_static = -1; + int game_status_last = game_status_last_static; // game status from previous function call + + game_status_last_static = game_status; // set game status for next function call + + // needed after ending game using restart key without asking in BD engine with last life + // (to handle race condition due to handling all key events as key event and text event) + if (game_status_last == GAME_MODE_PLAYING) + return FALSE; + // when playing, only handle raw key events and ignore text input if (game_status == GAME_MODE_PLAYING) return FALSE; diff --git a/src/tape.c b/src/tape.c index 35140ad4..a4b8ed96 100644 --- a/src/tape.c +++ b/src/tape.c @@ -1411,8 +1411,28 @@ void TapeRestartGame(void) return; } - if (!checkRestartGame("Restart game?")) - return; + if (level.game_engine_type == GAME_ENGINE_TYPE_BD && + setup.bd_multiple_lives && game_status == GAME_MODE_PLAYING) + { + if (game_bd.global_lives > 1) + { + if (!checkRestartGame("Restart game?")) + return; + + game_bd.global_lives--; + } + else + { + RequestQuitGame(FALSE); + + return; + } + } + else + { + if (!checkRestartGame("Restart game?")) + return; + } StartGameActions(network.enabled, setup.autorecord, level.random_seed); } -- 2.34.1