From ad87ac434d87ce663c45557e65016f598ba1e6f0 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 11 Oct 2023 00:29:19 +0300 Subject: [PATCH 26/27] 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 48358a7bdf..6bccd44250 100644 --- a/server/plrhand.c +++ b/server/plrhand.c @@ -402,38 +402,50 @@ void government_change(struct player *pplayer, struct government *gov, /**********************************************************************//** 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; - - if (!untargeted_revolution_allowed() - && gov == game.government_during_revolution) { - /* Targetless revolution not acceptable */ - notify_player(plr, NULL, E_REVOLT_DONE, ftc_server, - _("You can't revolt without selecting target government.")); - return -1; - } + int max_turns; - 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: - turns = game.server.revolution_length - gov->changed_to_times; - turns = MAX(1, turns); + max_turns = game.server.revolution_length - gov->changed_to_times; + 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, NULL, 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