From 82feec9ebb89b42e54a4ae9fd36ca496104a8b3a Mon Sep 17 00:00:00 2001 From: franck Date: Mon, 14 Jan 2019 09:11:32 +0100 Subject: [PATCH] SDL2: Fixes in the "end of game" turboMode --- ai/MrboomHelper.cpp | 22 +++++++++++++++++++++- ai/MrboomHelper.hpp | 1 + sdl2/sdl2.cpp | 4 ++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ai/MrboomHelper.cpp b/ai/MrboomHelper.cpp index 17d10aea..a167adf9 100644 --- a/ai/MrboomHelper.cpp +++ b/ai/MrboomHelper.cpp @@ -107,6 +107,11 @@ int nbLives(int player) } } +bool isDead(int player) +{ + return(m.vie[player] == 16); +} + bool isAlive(int player) { return(m.vie[player] == 1); @@ -531,7 +536,7 @@ bool isSuicideOK(int player) return((nbLivesFriends > 1) && (nbLivesEnemies == 1)); } -bool someHumanPlayersAlive() +bool someHumanPlayersAlive() // About to die players are considered dead { for (int i = 0; i < numberOfPlayers(); i++) { @@ -545,3 +550,18 @@ bool someHumanPlayersAlive() } return(false); } + +bool someHumanPlayersNotDead() // About to die players are considered alive +{ + for (int i = 0; i < numberOfPlayers(); i++) + { + if (isAIActiveForPlayer(i) == false) + { + if (!isDead(i)) + { + return(true); + } + } + } + return(false); +} diff --git a/ai/MrboomHelper.hpp b/ai/MrboomHelper.hpp index f49818ce..15389c40 100644 --- a/ai/MrboomHelper.hpp +++ b/ai/MrboomHelper.hpp @@ -47,6 +47,7 @@ enum Bonus }; bool someHumanPlayersAlive(); +bool someHumanPlayersNotDead(); bool isInTheApocalypse(); bool isAlive(int player); bool isAIActiveForPlayer(int player); diff --git a/sdl2/sdl2.cpp b/sdl2/sdl2.cpp index b07810bc..05162db1 100644 --- a/sdl2/sdl2.cpp +++ b/sdl2/sdl2.cpp @@ -778,13 +778,13 @@ loop() { anyButtonPushedMaskSave = 0; } - if (someHumanPlayersAlive()) + if (someHumanPlayersNotDead()) { anyButtonPushedMaskSave = anyButtonPushedMask; } else { - if (isGameActive()) + if (!isAboutToWin() && isGameActive()) { if (anyButtonPushedMaskSave != anyButtonPushedMask) // to avoid speeding straight away when still holding current keys {