From 04f82f3153b4eb4f98ed04b28172b50cf9d00314 Mon Sep 17 00:00:00 2001 From: Putnam Date: Tue, 17 Dec 2019 15:48:28 -0800 Subject: [PATCH] it works --- code/__DEFINES/citadel_defines.dm | 6 +-- code/controllers/subsystem/ticker.dm | 5 ++- code/controllers/subsystem/vote.dm | 65 +++++++++++++++------------- 3 files changed, 41 insertions(+), 35 deletions(-) diff --git a/code/__DEFINES/citadel_defines.dm b/code/__DEFINES/citadel_defines.dm index f954abf453..7cad6b5be7 100644 --- a/code/__DEFINES/citadel_defines.dm +++ b/code/__DEFINES/citadel_defines.dm @@ -121,6 +121,6 @@ #define NORMIE_HEARCHECK 4 // Voting stuff (move this somewhere else eventually probs) -#define PLURALITY 0 -#define APPROVAL 1 -#define IRV 2 +#define PLURALITY_VOTING 0 +#define APPROVAL_VOTING 1 +#define INSTANT_RUNOFF_VOTING 2 diff --git a/code/controllers/subsystem/ticker.dm b/code/controllers/subsystem/ticker.dm index d676b2df40..cbd7dfdd52 100755 --- a/code/controllers/subsystem/ticker.dm +++ b/code/controllers/subsystem/ticker.dm @@ -480,7 +480,10 @@ 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 ? PLURALITY : IRV) + if(dynamic) + SSvote.initiate_vote("dynamic","server",TRUE,INSTANT_RUNOFF_VOTING) + else + SSvote.initiate_vote("roundtype","server",TRUE,PLURALITY_VOTING) /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 8daf140121..6ea13c832d 100644 --- a/code/controllers/subsystem/vote.dm +++ b/code/controllers/subsystem/vote.dm @@ -10,7 +10,7 @@ SUBSYSTEM_DEF(vote) var/started_time = null var/time_remaining = 0 var/mode = null - var/vote_system = PLURALITY + var/vote_system = PLURALITY_VOTING var/question = null var/list/choices = list() var/list/choice_descs = list() // optional descriptions @@ -87,22 +87,29 @@ SUBSYSTEM_DEF(vote) 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 + var/already_lost_runoff = list() + for(var/n in 1 to choices.len) // if it takes more than this something REALLY wrong happened for(var/ckey in voted) - choices[voted[ckey][1]]++ + choices[choices[voted[ckey][1]]]++ // jesus christ how horrifying var/least_vote = 100000 var/least_voted - for(var/option in choices) + for(var/i in 1 to choices.len) + var/option = choices[i] if(choices[option] > voted.len/2) - return option - else if(choices[option] < least_vote) + message_admins("[option] has a majority, returning...") + return list(option) + else if(choices[option] < least_vote && !(option in already_lost_runoff)) least_vote = choices[option] - least_voted = option + least_voted = i + message_admins("[choices[least_voted]] lost the runoff, running again...") + already_lost_runoff += choices[least_voted] for(var/ckey in voted) voted[ckey] -= least_voted + for(var/option in choices) + choices[option] = 0 /datum/controller/subsystem/vote/proc/announce_result() - var/list/winners = vote_system == IRV ? get_result_runoff() : get_result() + var/list/winners = vote_system == INSTANT_RUNOFF_VOTING ? get_result_runoff() : get_result() var/text var/was_roundtype_vote = mode == "roundtype" || mode == "dynamic" if(winners.len > 0) @@ -202,7 +209,7 @@ SUBSYSTEM_DEF(vote) return 0 if(vote && vote >= 1 && vote <= choices.len) switch(vote_system) - if(PLURALITY) + if(PLURALITY_VOTING) if(usr.ckey in voted) choices[choices[voted[usr.ckey]]]-- voted[usr.ckey] = vote @@ -213,7 +220,7 @@ SUBSYSTEM_DEF(vote) voted[usr.ckey] = vote choices[choices[vote]]++ //check this return vote - if(APPROVAL) + if(APPROVAL_VOTING) if(usr.ckey in voted) if(vote in voted[usr.ckey]) voted[usr.ckey] -= vote @@ -226,7 +233,7 @@ SUBSYSTEM_DEF(vote) voted[usr.ckey] = list(vote) choices[choices[vote]]++ return vote - if(IRV) + if(INSTANT_RUNOFF_VOTING) if(usr.ckey in voted) if(vote in voted[usr.ckey]) voted[usr.ckey] -= vote @@ -236,7 +243,7 @@ SUBSYSTEM_DEF(vote) 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 +/datum/controller/subsystem/vote/proc/initiate_vote(vote_type, initiator_key, hideresults, votesystem = PLURALITY_VOTING)//CIT CHANGE - adds hideresults argument to votes to allow for obfuscated votes vote_system = votesystem if(!mode) if(started_time) @@ -335,41 +342,37 @@ SUBSYSTEM_DEF(vote) else . += "

Vote: [capitalize(mode)]

" switch(vote_system) - if(PLURALITY) + if(PLURALITY_VOTING) . += "

Vote one.

" - if(APPROVAL) + if(APPROVAL_VOTING) . += "

Vote any number of choices.

" - if(IRV) + if(INSTANT_RUNOFF_VOTING) . += "

Vote by order of preference. Revoting will demote to the bottom.

" . += "Time Left: [time_remaining] s

" if(admin) . += "(Cancel Vote) "