diff --git a/code/controllers/Processes/vote.dm b/code/controllers/Processes/vote.dm deleted file mode 100644 index 47cf079eeba..00000000000 --- a/code/controllers/Processes/vote.dm +++ /dev/null @@ -1,7 +0,0 @@ -/datum/controller/process/vote/setup() - name = "vote" - schedule_interval = 10 // every second - log_startup_progress("Voting ticker starting up.") - -/datum/controller/process/vote/doWork() - vote.process() diff --git a/code/controllers/voting.dm b/code/controllers/voting.dm index 842de2e2a03..5b152b8a4db 100644 --- a/code/controllers/voting.dm +++ b/code/controllers/voting.dm @@ -19,14 +19,17 @@ var/global/list/round_voters = list() //Keeps track of the individuals voting fo if(istype(vote)) qdel(vote) vote = src + spawn(0) + while(TRUE) + process() + sleep(10) -/datum/controller/vote/proc/process() //called by master_controller +/datum/controller/vote/proc/process() if(mode) // No more change mode votes after the game has started. - // 3 is GAME_STATE_PLAYING, but that #define is undefined for some reason - if(mode == "gamemode" && ticker.current_state >= 2) + if(mode == "gamemode" && ticker.current_state >= GAME_STATE_SETTING_UP) to_chat(world, "Voting aborted due to game start.") - src.reset() + reset() return // Calculate how much time is remaining by comparing current time, to time of vote start, @@ -37,14 +40,10 @@ var/global/list/round_voters = list() //Keeps track of the individuals voting fo result() for(var/client/C in voting) if(C) - C << browse(null,"window=vote;can_close=0") + C << browse(null,"window=vote") reset() else - for(var/client/C in voting) - if(C) - C << browse(vote.interface(C),"window=vote;can_close=0") - - voting.Cut() + update_panel() /datum/controller/vote/proc/autotransfer() initiate_vote("crew_transfer","the server") @@ -68,14 +67,26 @@ var/global/list/round_voters = list() //Keeps track of the individuals voting fo /datum/controller/vote/proc/get_result() - //get the highest number of votes var/greatest_votes = 0 var/total_votes = 0 - for(var/option in choices) - var/votes = choices[option] - total_votes += votes - if(votes > greatest_votes) - greatest_votes = votes + var/list/sorted_choices = list() + var/sorted_highest + var/sorted_votes = -1 + //get the highest number of votes, while also sorting the list + while(choices.len) + // This is a very inefficient sorting method, but that's okay + for(var/option in choices) + var/votes = choices[option] + if(sorted_votes < votes) + sorted_highest = option + sorted_votes = votes + if(votes > greatest_votes) + greatest_votes = votes + sorted_votes = -1 + total_votes += choices[sorted_highest] + sorted_choices[sorted_highest] = choices[sorted_highest] || 0 + choices -= sorted_highest + choices = sorted_choices //default-vote for everyone who didn't vote if(!config.vote_no_default && choices.len) var/non_voters = (clients.len - total_votes) @@ -129,11 +140,18 @@ var/global/list/round_voters = list() //Keeps track of the individuals voting fo for(var/key in current_votes) if(choices[current_votes[key]] == .) round_voters += key // Keep track of who voted for the winning round. - if((mode == "gamemode" && . == "extended") || ticker.hide_mode == 0) // Announce Extended gamemode, but not other gamemodes - text += "Vote Result: [.]" + if(mode == "gamemode" && (. == "extended" || ticker.hide_mode == 0)) // Announce Extended gamemode, but not other gamemodes + text += "Vote Result: [.] ([choices[.]] vote\s)" else - if(mode != "gamemode") - text += "Vote Result: [.]" + if(mode == "custom") + // Completely replace text to show all results in custom votes + text = "[question]\n" + for(var/option in winners) + text += "\t[option]: [choices[option]] vote\s\n" + for(var/option in (choices-winners)) + text += "\t[option]: [choices[option]] vote\s\n" + else if(mode != "gamemode") + text += "Vote Result: [.] ([choices[.]] vote\s)" else text += "The vote has ended." // What will be shown if it is a gamemode vote that isn't extended @@ -217,7 +235,8 @@ var/global/list/round_voters = list() //Keeps track of the individuals voting fo var/option = capitalize(html_encode(input(usr,"Please enter an option or hit cancel to finish") as text|null)) if(!option || mode || !usr.client) break choices.Add(option) - else return 0 + else + return 0 mode = vote_type initiator = initiator_key started_time = world.time @@ -226,7 +245,9 @@ var/global/list/round_voters = list() //Keeps track of the individuals voting fo text += "\n[question]" log_vote(text) - to_chat(world, "[text]\nType vote to place your votes.\nYou have [config.vote_period/10] seconds to vote.") + to_chat(world, {"[text] + Click here or type vote to place your vote. + You have [config.vote_period/10] seconds to vote."}) switch(vote_type) if("crew_transfer") world << sound('sound/ambience/alarm4.ogg') @@ -256,74 +277,92 @@ var/global/list/round_voters = list() //Keeps track of the individuals voting fo log_admin("OOC was toggled automatically due to custom vote.") message_admins("OOC has been toggled off automatically.") - - - time_remaining = round(config.vote_period/10) return 1 return 0 -/datum/controller/vote/proc/interface(var/client/C) - if(!C) return - var/admin = check_rights(R_ADMIN,0) +/datum/controller/vote/proc/browse_to(var/client/C) + if(!C) + return + var/admin = check_rights(R_ADMIN, 0, user = C.mob) voting |= C - . = "