var/datum/controller/subsystem/vote/SSvote /datum/controller/subsystem/vote name = "Voting" wait = 1 SECOND flags = SS_KEEP_TIMING | SS_FIRE_IN_LOBBY | SS_NO_TICK_CHECK priority = SS_PRIORITY_VOTE var/next_transfer_time var/initiator = null var/started_time = null var/time_remaining = 0 var/mode = null var/question = null var/list/choices = list() var/list/gamemode_names = list() var/list/voted = list() var/list/voting = list() var/list/current_votes = list() var/list/additional_text = list() var/auto_muted = 0 var/last_transfer_vote = null var/list/round_voters = list() /datum/controller/subsystem/vote/New() NEW_SS_GLOBAL(SSvote) /datum/controller/subsystem/vote/Initialize(timeofday) next_transfer_time = config.vote_autotransfer_initial /datum/controller/subsystem/vote/fire(resumed = FALSE) if (mode) // No more change mode votes after the game has started. if(mode == "gamemode" && ROUND_IS_STARTED) world << "Voting aborted due to game start." src.reset() return // Calculate how much time is remaining by comparing current time, to time of vote start, // plus vote duration time_remaining = round((started_time + config.vote_period - world.time)/10) if(time_remaining < 0) result() for(var/client/C in voting) if(C) if (C.vote_window) C.vote_window.close() else log_debug("SSvote: Client [C] had no vote_window but was in voting list!") reset() else for(var/client/C in voting) if(C) if (C.vote_window) C.vote_window.open() else log_debug("SSvote: Client [C]'s vote_window was missing!") setup_vote_window(C) C.vote_window.open() voting.Cut() if (world.time >= next_transfer_time - 600) autotransfer() next_transfer_time += config.vote_autotransfer_interval /datum/controller/subsystem/vote/proc/autotransfer() initiate_vote("crew_transfer","the server", 1) log_debug("The server has called a crew transfer vote") /datum/controller/subsystem/vote/proc/autogamemode() initiate_vote("gamemode","the server", 1) log_debug("The server has called a gamemode vote") /datum/controller/subsystem/vote/proc/reset() initiator = null time_remaining = 0 mode = null question = null choices.Cut() voted.Cut() voting.Cut() current_votes.Cut() additional_text.Cut() /datum/controller/subsystem/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 //default-vote for everyone who didn't vote if(!config.vote_no_default && choices.len) var/non_voters = (clients.len - total_votes) if(non_voters > 0) if(mode == "restart") choices["Continue Playing"] += non_voters if(choices["Continue Playing"] >= greatest_votes) greatest_votes = choices["Continue Playing"] else if(mode == "gamemode") if(master_mode in choices) choices[master_mode] += non_voters if(choices[master_mode] >= greatest_votes) greatest_votes = choices[master_mode] else if(mode == "crew_transfer") var/factor = 0.5 switch(world.time / (10 * 60)) // minutes if(0 to 60) factor = 0.5 if(61 to 120) factor = 0.8 if(121 to 240) factor = 1 if(241 to 300) factor = 1.2 else factor = 1.4 choices["Initiate Crew Transfer"] = round(choices["Initiate Crew Transfer"] * factor) world << "Crew Transfer Factor: [factor]" greatest_votes = max(choices["Initiate Crew Transfer"], choices["Continue The Round"]) if(mode == "crew_transfer") if(round(world.time / 36000)+12 <= 14) // Credit to Scopes @ oldcode. world << "Majority voting rule in effect. 2/3rds majority needed to initiate transfer." choices["Initiate Crew Transfer"] = round(choices["Initiate Crew Transfer"] - round(total_votes / 3)) greatest_votes = max(choices["Initiate Crew Transfer"], choices["Continue The Round"]) //get all options with that many votes and return them in a list . = list() if(greatest_votes) for(var/option in choices) if(choices[option] == greatest_votes) . += option /datum/controller/subsystem/vote/proc/announce_result() var/list/winners = get_result() var/text if(winners.len > 0) if(winners.len > 1) if(mode != "gamemode" || SSticker.hide_mode == 0) // Here we are making sure we don't announce potential game modes text = "Vote Tied Between:\n" for(var/option in winners) text += "\t[option]\n" . = pick(winners) 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") || SSticker.hide_mode == 0) // Announce Extended gamemode, but not other gamemodes text += "Vote Result: [.]" else if(mode != "gamemode") text += "Vote Result: [.]" else text += "The vote has ended." // What will be shown if it is a gamemode vote that isn't extended else text += "Vote Result: Inconclusive - No Votes!" if(mode == "add_antagonist") antag_add_failed = 1 log_vote(text) world << "[text]" /datum/controller/subsystem/vote/proc/result() . = announce_result() var/restart = 0 if(.) switch(mode) if("restart") if(. == "Restart Round") restart = 1 if("gamemode") if(master_mode != .) world.save_mode(.) if(SSticker.mode) restart = 1 else master_mode = . if("crew_transfer") if(. == "Initiate Crew Transfer") init_shift_change(null, 1) last_transfer_vote = world.time if("add_antagonist") if(isnull(.) || . == "None") antag_add_failed = 1 else additional_antag_types |= antag_names_to_ids[.] if(mode == "gamemode") //fire this even if the vote fails. if(!round_progressing) round_progressing = 1 world << "The round will start soon." if(restart) world << "World restarting due to vote..." feedback_set_details("end_error","restart vote") sleep(50) log_game("Rebooting due to restart vote") world.Reboot() /datum/controller/subsystem/vote/proc/submit_vote(ckey, vote) if(mode) if (mode == "crew_transfer") if(config.vote_no_dead && usr && !usr.client.holder) if (isnewplayer(usr)) usr << "You must be playing or have been playing to start a vote." return 0 else if (isobserver(usr)) var/mob/dead/observer/O = usr if (O.started_as_observer) usr << "You must be playing or have been playing to start a vote." return 0 if(vote && vote >= 1 && vote <= choices.len) if(current_votes[ckey]) choices[choices[current_votes[ckey]]]-- voted += usr.ckey choices[choices[vote]]++ //check this current_votes[ckey] = vote return vote return 0 /datum/controller/subsystem/vote/proc/initiate_vote(vote_type, initiator_key, automatic = FALSE) if(!mode) if(started_time != null && !(check_rights(R_ADMIN|R_MOD) || automatic)) // Transfer votes are their own little special snowflake var/next_allowed_time = 0 if (vote_type == "crew_transfer") if (config.vote_no_dead && !usr.client.holder) if (isnewplayer(usr)) usr << "You must be playing or have been playing to start a vote." return 0 else if (isobserver(usr)) var/mob/dead/observer/O = usr if (O.started_as_observer) usr << "You must be playing or have been playing to start a vote." return 0 if (last_transfer_vote) next_allowed_time = (last_transfer_vote + config.vote_delay) else next_allowed_time = config.transfer_timeout else next_allowed_time = (started_time + config.vote_delay) if(next_allowed_time > world.time) return 0 reset() switch(vote_type) if("restart") choices.Add("Restart Round","Continue Playing") if("gamemode") if(SSticker.current_state >= 2) return 0 choices.Add(config.votable_modes) for (var/F in choices) var/datum/game_mode/M = gamemode_cache[F] if(!M) continue gamemode_names[M.config_tag] = capitalize(M.name) //It's ugly to put this here but it works additional_text.Add("
| Choices | Votes | " if(capitalize(mode) == "Gamemode") .+= "Minimum Players | |||||
| [gamemode_names[choices[i]]] | [votes] | " else . += "[gamemode_names[choices[i]]] | [votes] | " else if(current_votes[C.ckey] == i) . += "[choices[i]] | [votes] | " else . += "[choices[i]] | [votes] | " if (additional_text.len >= i) . += additional_text[i] . += "