From d7995df800c863b7874fc5ec9137f7b8ae0d6759 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 11 Oct 2023 00:35:07 +0300 Subject: [PATCH 42/42] Fix revolution_length() dead "turns" assignment See osdn #48834 Signed-off-by: Marko Lindqvist --- server/plrhand.c | 54 +++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/server/plrhand.c b/server/plrhand.c index 9989e590b0..98aff46cbf 100644 --- a/server/plrhand.c +++ b/server/plrhand.c @@ -507,28 +507,22 @@ void player_loot_player(struct player *pvictor, struct player *pvictim) /**********************************************************************//** Get length of a revolution. + + @param rltype The way to decide revolution length + @param gov Government that the revolution ends to + @return Revolution length in turns **************************************************************************/ -int revolution_length(struct government *gov, struct player *plr) +static int revolentype_length(enum revolen_type rltype, + struct government *gov) { - int turns; + int max_turns; int change_speed; - if (!untargeted_revolution_allowed() - && gov == game.government_during_revolution) { - /* Targetless revolution not acceptable */ - notify_player(plr, nullptr, E_REVOLT_DONE, ftc_server, - _("You can't revolt without selecting target government.")); - return -1; - } - - turns = GAME_DEFAULT_REVOLUTION_LENGTH; /* To avoid compiler warning */ - switch (game.info.revolentype) { + switch (rltype) { case REVOLEN_FIXED: - turns = game.server.revolution_length; - break; + return game.server.revolution_length; case REVOLEN_RANDOM: - turns = fc_rand(game.server.revolution_length) + 1; - break; + return fc_rand(game.server.revolution_length) + 1; case REVOLEN_QUICKENING: case REVOLEN_RANDQUICK: /* If everyone changes to this government once, the last 50% of players doing so @@ -536,15 +530,33 @@ int revolution_length(struct government *gov, struct player *plr) change_speed = (player_count() / 2) / (game.server.revolution_length - 1); /* It never takes zero players to make revlen shorter */ change_speed = MAX(change_speed, 1); - turns = game.server.revolution_length - gov->changed_to_times / change_speed; - turns = MAX(1, turns); + max_turns = game.server.revolution_length - gov->changed_to_times / change_speed; + max_turns = MAX(1, max_turns); if (game.info.revolentype == REVOLEN_RANDQUICK) { - turns = fc_rand(turns) + 1; + return fc_rand(max_turns) + 1; } - break; + return max_turns; + } + + fc_assert(FALSE); + + return GAME_DEFAULT_REVOLUTION_LENGTH; +} + +/**********************************************************************//** + Get length of a revolution. +**************************************************************************/ +int revolution_length(struct government *gov, struct player *plr) +{ + if (!untargeted_revolution_allowed() + && gov == game.government_during_revolution) { + /* Targetless revolution not acceptable */ + notify_player(plr, nullptr, E_REVOLT_DONE, ftc_server, + _("You can't revolt without selecting target government.")); + return -1; } - return turns; + return revolentype_length(game.info.revolentype, gov); } /**********************************************************************//** -- 2.42.0