Persistent Map Vote Tallies (#86788)

## About The Pull Request

Changes map votes to be based on a persistent tally count.
Tallies for maps are cached between rounds and are added to by map
votes.
When a map is chosen, and it wasn't the only valid one, the tallies for
said chosen map will be reset.

Refactors map vote handling and moves it from SSmapping to SSmap_vote.
Rock the Vote has been removed as a result of this refactor.

## Why It's Good For The Game

Makes it more likely that all maps will be played over the course of a
server instead of always being truly random.
Removes some clutter off of SSmapping.

🆑
refactor: Map Votes are now carried over between rounds. When a map vote
is actually a contest, the winning map will have its votes reset.
/🆑
This commit is contained in:
Zephyr
2024-09-30 13:09:08 +13:00
committed by GitHub
parent ee5911b6d1
commit 0ef5c3d049
33 changed files with 291 additions and 303 deletions
+8 -54
View File
@@ -2,29 +2,18 @@
name = "Map"
default_message = "Vote for next round's map!"
count_method = VOTE_COUNT_METHOD_SINGLE
winner_method = VOTE_WINNER_METHOD_WEIGHTED_RANDOM
winner_method = VOTE_WINNER_METHOD_NONE
display_statistics = FALSE
/datum/vote/map_vote/New()
. = ..()
default_choices = 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
default_choices += possible_config.map_name
default_choices = SSmap_vote.get_valid_map_vote_choices()
/datum/vote/map_vote/create_vote()
. = ..()
if(!.)
return FALSE
choices -= get_choices_invalid_for_population()
if(length(choices) == 1) // 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/datum/map_config/change_me_out = global.config.maplist[choices[1]]
finalize_vote(choices[1])// voted by not voting, very sad.
@@ -48,35 +37,16 @@
. = ..()
if(. != VOTE_AVAILABLE)
return .
if(forced)
return VOTE_AVAILABLE
var/num_choices = length(default_choices - get_choices_invalid_for_population())
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(SSmapping.map_vote_rocked)
return VOTE_AVAILABLE
if(SSmapping.map_voted)
if(SSmap_vote.next_map_config)
return "The next map has already been selected."
return VOTE_AVAILABLE
/// Returns a list of all map options that are invalid for the current population.
/datum/vote/map_vote/proc/get_choices_invalid_for_population()
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 = GLOB.clients.len
var/list/invalid_choices = list()
for(var/map in default_choices)
var/datum/map_config/possible_config = config.maplist[map]
if(possible_config.config_min_users > 0 && filter_threshold < possible_config.config_min_users)
invalid_choices += map
else if(possible_config.config_max_users > 0 && filter_threshold > possible_config.config_max_users)
invalid_choices += map
return invalid_choices
/datum/vote/map_vote/get_result_text(list/all_winners, real_winner, list/non_voters)
return null
/datum/vote/map_vote/get_vote_result(list/non_voters)
// Even if we have default no vote off,
@@ -97,20 +67,4 @@
return ..()
/datum/vote/map_vote/finalize_vote(winning_option)
var/datum/map_config/winning_map = global.config.maplist[winning_option]
if(!istype(winning_map))
CRASH("[type] wasn't passed a valid winning map choice. (Got: [winning_option || "null"] - [winning_map || "null"])")
SSmapping.changemap(winning_map)
SSmapping.map_voted = TRUE
if(SSmapping.map_vote_rocked)
SSmapping.map_vote_rocked = FALSE
/proc/revert_map_vote()
var/datum/map_config/override_map = SSmapping.config
if(isnull(override_map))
return
SSmapping.changemap(override_map)
log_game("The next map has been reset to [override_map.map_name].")
send_to_playing_players(span_boldannounce("The next map is: [override_map.map_name]."))
SSmap_vote.finalize_map_vote(src)
+2 -2
View File
@@ -57,10 +57,10 @@
return
// If there was a previous map vote, we revert the change.
if(!isnull(SSmapping.next_map_config))
if(!isnull(SSmap_vote.next_map_config))
log_game("The next map has been reset due to successful restart vote.")
send_to_playing_players(span_boldannounce("The next map has been reset due to successful restart vote."))
revert_map_vote()
SSmap_vote.revert_next_map()
SSticker.force_ending = FORCE_END_ROUND
log_game("End round forced by successful restart vote.")
-62
View File
@@ -1,62 +0,0 @@
#define CHOICE_TO_ROCK "Yes, re-do the map vote."
#define CHOICE_NOT_TO_ROCK "No, keep the currently selected map."
/// If a map vote is called before the emergency shuttle leaves the station, the players can call another vote to re-run the vote on the shuttle leaving.
/datum/vote/rock_the_vote
name = "Rock the Vote"
override_question = "Rock the Vote?"
contains_vote_in_name = TRUE //lol
default_choices = list(
CHOICE_TO_ROCK,
CHOICE_NOT_TO_ROCK,
)
default_message = "Override the current map vote."
/// The number of times we have rocked the vote thus far.
var/rocking_votes = 0
/datum/vote/rock_the_vote/toggle_votable()
CONFIG_SET(flag/allow_rock_the_vote, !CONFIG_GET(flag/allow_rock_the_vote))
/datum/vote/rock_the_vote/is_config_enabled()
return CONFIG_GET(flag/allow_rock_the_vote)
/datum/vote/rock_the_vote/can_be_initiated(forced)
. = ..()
if(. != VOTE_AVAILABLE)
return .
if(SSticker.current_state == GAME_STATE_FINISHED)
return "The game is finished, no map votes can be initiated."
if(rocking_votes >= CONFIG_GET(number/max_rocking_votes))
return "The maximum number of times to rock the vote has been reached."
if(SSmapping.map_vote_rocked)
return "The vote has already been rocked! Initiate a map vote!"
if(!SSmapping.map_voted)
return "Rocking the vote is disabled because no map has been voted on yet!"
if(SSmapping.map_force_chosen)
return "Rocking the vote is disabled because an admin has forcibly set the map!"
if(EMERGENCY_ESCAPED_OR_ENDGAMED && SSmapping.map_voted)
return "The emergency shuttle has already left the station and the next map has already been chosen!"
return VOTE_AVAILABLE
/datum/vote/rock_the_vote/finalize_vote(winning_option)
rocking_votes++
if(winning_option == CHOICE_NOT_TO_ROCK)
return
if(winning_option == CHOICE_TO_ROCK)
to_chat(world, span_boldannounce("The vote has been rocked! Players are now able to re-run the map vote once more."))
message_admins("The players have successfully rocked the vote.")
SSmapping.map_vote_rocked = TRUE
return
CRASH("[type] wasn't passed a valid winning choice. (Got: [winning_option || "null"])")
#undef CHOICE_TO_ROCK
#undef CHOICE_NOT_TO_ROCK