From 629ec38e4ee74ce98afbd3816f4e84840799bd80 Mon Sep 17 00:00:00 2001 From: SmArtKar <44720187+SmArtKar@users.noreply.github.com> Date: Sun, 16 Feb 2025 12:29:00 +0100 Subject: [PATCH] Fixes map votes not refreshing the amount of possible choices (#89404) ## About The Pull Request Closes #89235 ## Changelog :cl: fix: Fixed map votes not refreshing the amount of possible choices /:cl: --------- Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> --- code/__HELPERS/game.dm | 13 +++++----- code/controllers/subsystem/map_vote.dm | 34 ++++++++++++++------------ code/datums/votes/map_vote.dm | 8 +++--- code/modules/admin/chat_commands.dm | 2 +- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/code/__HELPERS/game.dm b/code/__HELPERS/game.dm index 44a94a93f7c..b9af3204238 100644 --- a/code/__HELPERS/game.dm +++ b/code/__HELPERS/game.dm @@ -155,19 +155,18 @@ ///Get active players who are playing in the round /proc/get_active_player_count(alive_check = FALSE, afk_check = FALSE, human_check = FALSE) var/active_players = 0 - for(var/i = 1; i <= GLOB.player_list.len; i++) - var/mob/player_mob = GLOB.player_list[i] + for(var/mob/player_mob as anything in GLOB.player_list) if(!player_mob?.client) continue - if(alive_check && player_mob.stat) + if(alive_check && player_mob.stat == DEAD) continue - else if(afk_check && player_mob.client.is_afk()) + if(afk_check && player_mob.client.is_afk()) continue - else if(human_check && !ishuman(player_mob)) + if(human_check && !ishuman(player_mob)) continue - else if(isnewplayer(player_mob)) // exclude people in the lobby + if(isnewplayer(player_mob)) // exclude people in the lobby continue - else if(isobserver(player_mob)) // Ghosts are fine if they were playing once (didn't start as observers) + if(isobserver(player_mob)) // Ghosts are fine if they were playing once (didn't start as observers) var/mob/dead/observer/ghost_player = player_mob if(ghost_player.started_as_observer) // Exclude people who started as observers continue diff --git a/code/controllers/subsystem/map_vote.dm b/code/controllers/subsystem/map_vote.dm index d8a05cb9a81..9d139dfd74a 100644 --- a/code/controllers/subsystem/map_vote.dm +++ b/code/controllers/subsystem/map_vote.dm @@ -19,6 +19,9 @@ SUBSYSTEM_DEF(map_vote) /// Stores the previous map vote cache, used when a map vote is reverted. var/list/previous_cache + /// Stores the last amount of potential players to compare next time we're called + var/player_cache = -1 + /// Stores a formatted html string of the tally counts var/tally_printout = span_red("Loading...") @@ -104,29 +107,28 @@ SUBSYSTEM_DEF(map_vote) /// Returns a list of all map options that are invalid for the current population. /datum/controller/subsystem/map_vote/proc/get_valid_map_vote_choices() - var/list/valid_maps = list() - - // Fill in our default choices with all of the maps in our map config, if they are votable and not blocked. - var/list/maps = shuffle(global.config.maplist) - for(var/map in maps) - var/datum/map_config/possible_config = config.maplist[map] - if(!possible_config.votable || (possible_config.map_name in SSpersistence.blocked_maps)) - continue - valid_maps += possible_config.map_name - var/filter_threshold = 0 if(SSticker.HasRoundStarted()) filter_threshold = get_active_player_count(alive_check = FALSE, afk_check = TRUE, human_check = FALSE) else filter_threshold = length(GLOB.clients) - for(var/map in valid_maps) - var/datum/map_config/possible_config = config.maplist[map] - if(possible_config.config_min_users > 0 && filter_threshold < possible_config.config_min_users) - valid_maps -= map + if(filter_threshold == player_cache) + return - else if(possible_config.config_max_users > 0 && filter_threshold > possible_config.config_max_users) - valid_maps -= map + player_cache = filter_threshold + var/list/valid_maps = list() + // Fill in our default choices with all of the maps in our map config, if they are votable and not blocked. + var/list/maps = shuffle(global.config.maplist) + for(var/map in maps) + var/datum/map_config/possible_config = config.maplist[map] + if(!possible_config.votable || (possible_config.map_name in SSpersistence.blocked_maps)) + continue + if(possible_config.config_min_users > 0 && filter_threshold < possible_config.config_min_users) + continue + if(possible_config.config_max_users > 0 && filter_threshold > possible_config.config_max_users) + continue + valid_maps += possible_config.map_name return valid_maps diff --git a/code/datums/votes/map_vote.dm b/code/datums/votes/map_vote.dm index c5f90f16d13..2dba69d42a9 100644 --- a/code/datums/votes/map_vote.dm +++ b/code/datums/votes/map_vote.dm @@ -4,7 +4,6 @@ count_method = VOTE_COUNT_METHOD_SINGLE winner_method = VOTE_WINNER_METHOD_NONE display_statistics = FALSE - /datum/vote/map_vote/New() . = ..() default_choices = SSmap_vote.get_valid_map_vote_choices() @@ -39,11 +38,14 @@ if(. != VOTE_AVAILABLE) return . + if(SSmap_vote.next_map_config) + return "The next map has already been selected." + + default_choices = SSmap_vote.get_valid_map_vote_choices() var/num_choices = length(default_choices) if(num_choices <= 1) return "There [num_choices == 1 ? "is only one map" : "are no maps"] to choose from." - if(SSmap_vote.next_map_config) - return "The next map has already been selected." + return VOTE_AVAILABLE /datum/vote/map_vote/get_result_text(list/all_winners, real_winner, list/non_voters) diff --git a/code/modules/admin/chat_commands.dm b/code/modules/admin/chat_commands.dm index db72b7a4864..3397f7570c1 100644 --- a/code/modules/admin/chat_commands.dm +++ b/code/modules/admin/chat_commands.dm @@ -120,5 +120,5 @@ var/list/adm = get_admin_counts() var/list/allmins = adm["total"] var/status = "Admins: [allmins.len] (Active: [english_list(adm["present"])] AFK: [english_list(adm["afk"])] Stealth: [english_list(adm["stealth"])] Skipped: [english_list(adm["noflags"])]). " - status += "Players: [GLOB.clients.len] (Active: [get_active_player_count(0,1,0)]). Round has [SSticker.HasRoundStarted() ? "" : "not "]started." + status += "Players: [GLOB.clients.len] (Active: [get_active_player_count(FALSE, TRUE, FALSE)]). Round has [SSticker.HasRoundStarted() ? "" : "not "]started." return new /datum/tgs_message_content(status)