diff --git a/code/__DEFINES/citadel_defines.dm b/code/__DEFINES/citadel_defines.dm index e3cafd4613..f954abf453 100644 --- a/code/__DEFINES/citadel_defines.dm +++ b/code/__DEFINES/citadel_defines.dm @@ -119,3 +119,8 @@ //belly sound pref things #define NORMIE_HEARCHECK 4 + +// Voting stuff (move this somewhere else eventually probs) +#define PLURALITY 0 +#define APPROVAL 1 +#define IRV 2 diff --git a/code/controllers/subsystem/ticker.dm b/code/controllers/subsystem/ticker.dm index baaa78e56f..9ca252b1dc 100755 --- a/code/controllers/subsystem/ticker.dm +++ b/code/controllers/subsystem/ticker.dm @@ -480,7 +480,7 @@ SUBSYSTEM_DEF(ticker) SSticker.timeLeft = 900 SSticker.modevoted = TRUE var/dynamic = CONFIG_GET(flag/dynamic_voting) - SSvote.initiate_vote(dynamic ? "dynamic" : "roundtype","server",TRUE,dynamic) + SSvote.initiate_vote(dynamic ? "dynamic" : "roundtype","server",TRUE,dynamic ? PLURALITY : IRV) /datum/controller/subsystem/ticker/Recover() current_state = SSticker.current_state diff --git a/code/controllers/subsystem/vote.dm b/code/controllers/subsystem/vote.dm index b34713254d..8daf140121 100644 --- a/code/controllers/subsystem/vote.dm +++ b/code/controllers/subsystem/vote.dm @@ -1,6 +1,3 @@ -#define PLURALITY 0 -#define APPROVAL 1 - SUBSYSTEM_DEF(vote) name = "Vote" wait = 10 @@ -89,8 +86,23 @@ SUBSYSTEM_DEF(vote) . += option return . +/datum/controller/subsystem/vote/proc/get_result_runoff() + for(var/i in 1 to choices.len) // if it takes more than this something REALLY wrong happened + for(var/ckey in voted) + choices[voted[ckey][1]]++ + var/least_vote = 100000 + var/least_voted + for(var/option in choices) + if(choices[option] > voted.len/2) + return option + else if(choices[option] < least_vote) + least_vote = choices[option] + least_voted = option + for(var/ckey in voted) + voted[ckey] -= least_voted + /datum/controller/subsystem/vote/proc/announce_result() - var/list/winners = get_result() + var/list/winners = vote_system == IRV ? get_result_runoff() : get_result() var/text var/was_roundtype_vote = mode == "roundtype" || mode == "dynamic" if(winners.len > 0) @@ -214,6 +226,14 @@ SUBSYSTEM_DEF(vote) voted[usr.ckey] = list(vote) choices[choices[vote]]++ return vote + if(IRV) + if(usr.ckey in voted) + if(vote in voted[usr.ckey]) + voted[usr.ckey] -= vote + else + voted += usr.ckey + voted[usr.ckey] = list() + voted[usr.ckey] += vote return 0 /datum/controller/subsystem/vote/proc/initiate_vote(vote_type, initiator_key, hideresults, votesystem = PLURALITY)//CIT CHANGE - adds hideresults argument to votes to allow for obfuscated votes @@ -314,21 +334,42 @@ SUBSYSTEM_DEF(vote) . += "