From 0a2ab60458facaffdf9727a64e981274687209fc Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Wed, 19 Oct 2022 22:29:10 +0200 Subject: [PATCH] [MIRROR] End Of Creating Map Votes with One/Zero Options. [MDB IGNORE] (#16977) * End Of Creating Map Votes with One/Zero Options. (#70340) Makes it so you can't call a map vote when there is less than two maps to choose from Co-authored-by: VexingRaven Co-authored-by: Mothblocks <35135081+Mothblocks@ users.noreply.github.com> * End Of Creating Map Votes with One/Zero Options. Co-authored-by: san7890 Co-authored-by: VexingRaven Co-authored-by: Mothblocks <35135081+Mothblocks@ users.noreply.github.com> --- code/datums/votes/map_vote.dm | 40 ++++++++++++++++++++++-------- code/datums/votes/rock_the_vote.dm | 4 +++ 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/code/datums/votes/map_vote.dm b/code/datums/votes/map_vote.dm index 3deab6d1047..5db40806a38 100644 --- a/code/datums/votes/map_vote.dm +++ b/code/datums/votes/map_vote.dm @@ -18,16 +18,14 @@ /datum/vote/map_vote/create_vote() . = ..() - - // Before we create a vote, remove all maps from our choices that are outside of our population range. - // Note that this can result in zero remaining choices for our vote, which is not ideal (but technically fine). - for(var/map in choices) - var/datum/map_config/possible_config = config.maplist[map] - if(possible_config.config_min_users > 0 && GLOB.clients.len < possible_config.config_min_users) - choices -= map - - else if(possible_config.config_max_users > 0 && GLOB.clients.len > possible_config.config_max_users) - choices -= map + check_population(should_key_choices = FALSE) + if((length(choices) == 1) && EMERGENCY_ESCAPED_OR_ENDGAMED) // Only one choice, no need to vote. Let's just auto-rotate it to the only remaining map because it would just happen anyways. + var/de_facto_winner = choices[1] + var/datum/map_config/change_me_out = global.config.maplist[de_facto_winner] + SSmapping.changemap(change_me_out) + to_chat(world, span_boldannounce("The map vote has been skipped because there is only one map left to vote for. The map has been changed to [change_me_out.map_name].")) + SSmapping.map_voted = TRUE // voted by not voting, very sad. + return FALSE /datum/vote/map_vote/toggle_votable(mob/toggler) if(!toggler) @@ -49,6 +47,11 @@ if(forced) return TRUE + var/number_of_choices = length(check_population()) + if(number_of_choices < 2) + message = "There [number_of_choices == 1 ? "is only one map" : "are no maps"] to choose from." + return FALSE + if(SSmapping.map_vote_rocked) return TRUE @@ -63,6 +66,23 @@ message = initial(message) return TRUE +/// Before we create a vote, remove all maps from our choices that are outside of our population range. Note that this can result in zero remaining choices for our vote, which is not ideal (but ultimately okay). +/// Argument should_key_choices is TRUE, pass as FALSE in a context where choices are already keyed in a list. +/datum/vote/map_vote/proc/check_population(should_key_choices = TRUE) + if(should_key_choices) + for(var/key in default_choices) + choices[key] = 0 + + for(var/map in choices) + var/datum/map_config/possible_config = config.maplist[map] + if(possible_config.config_min_users > 0 && GLOB.clients.len < possible_config.config_min_users) + choices -= map + + else if(possible_config.config_max_users > 0 && GLOB.clients.len > possible_config.config_max_users) + choices -= map + + return choices + /datum/vote/map_vote/get_vote_result(list/non_voters) // Even if we have default no vote off, // if our default map is null for some reason, we shouldn't continue diff --git a/code/datums/votes/rock_the_vote.dm b/code/datums/votes/rock_the_vote.dm index 6a2a592dea5..6cffeb5ad67 100644 --- a/code/datums/votes/rock_the_vote.dm +++ b/code/datums/votes/rock_the_vote.dm @@ -56,6 +56,10 @@ message = "Rocking the vote is disabled because an admin has forcibly set the map!" return FALSE + if(EMERGENCY_ESCAPED_OR_ENDGAMED && SSmapping.map_voted) + message = "The emergency shuttle has already left the station and the next map has already been chosen!" + return FALSE + message = initial(message) return TRUE