Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instant Runoff Voting! #19153

Merged
merged 6 commits into from Jul 6, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions code/__DEFINES/misc.dm
Expand Up @@ -310,6 +310,9 @@ var/list/bloody_footprints_cache = list()
#define POLLTYPE_TEXT "TEXT"
#define POLLTYPE_RATING "NUMVAL"
#define POLLTYPE_MULTI "MULTICHOICE"
#define POLLTYPE_IRV "IRV"



//lighting area defines
#define DYNAMIC_LIGHTING_DISABLED 0 //dynamic lighting disabled (area stays at full brightness)
Expand Down
27 changes: 17 additions & 10 deletions code/modules/admin/create_poll.dm
Expand Up @@ -34,7 +34,7 @@
return

/client/proc/create_poll_function()
var/polltype = input("Choose poll type.","Poll Type") in list("Single Option","Text Reply","Rating","Multiple Choice")
var/polltype = input("Choose poll type.","Poll Type") in null|list("Single Option","Text Reply","Rating","Multiple Choice", "Instant Runoff Voting")
var/choice_amount = 0
switch(polltype)
if("Single Option")
Expand All @@ -48,6 +48,10 @@
choice_amount = input("How many choices should be allowed?","Select choice amount") as num|null
if(!choice_amount)
return
if ("Instant Runoff Voting")
polltype = POLLTYPE_IRV
else
return 0
var/starttime = SQLtime()
var/endtime = input("Set end time for poll as format YYYY-MM-DD HH:MM:SS. All times in server time. HH:MM:SS is optional and 24-hour. Must be later than starting time for obvious reasons.", "Set end time", SQLtime()) as text
if(!endtime)
Expand Down Expand Up @@ -117,14 +121,15 @@
if(!option)
return pollid
option = sanitizeSQL(option)
var/percentagecalc
switch(alert("Calculate option results as percentage?",,"Yes","No","Cancel"))
if("Yes")
percentagecalc = 1
if("No")
percentagecalc = 0
else
return pollid
var/percentagecalc = 1
if (polltype != POLLTYPE_IRV)
switch(alert("Calculate option results as percentage?",,"Yes","No","Cancel"))
if("Yes")
percentagecalc = 1
if("No")
percentagecalc = 0
else
return pollid
var/minval = 0
var/maxval = 0
var/descmin = ""
Expand Down Expand Up @@ -160,9 +165,11 @@
var/err = query_polladd_option.ErrorMsg()
log_game("SQL ERROR adding new poll option to table. Error : \[[err]\]\n")
return pollid
switch(alert(" ",,"Add option","Finish"))
switch(alert(" ",,"Add option","Finish", "Cancel"))
if("Add option")
add_option = 1
if("Finish")
add_option = 0
else
return 0
return pollid
5 changes: 5 additions & 0 deletions code/modules/client/asset_cache.dm
Expand Up @@ -224,6 +224,11 @@ You can set verify to TRUE if you want send() to sleep until the client has the
"large_stamp-law.png" = 'icons/stamp_icons/large_stamp-law.png'
)

/datum/asset/simple/IRV
assets = list(
"jquery-ui.custom-core-widgit-mouse-sortable-min.js" = 'html/IRV/jquery-ui.custom-core-widgit-mouse-sortable-min.js',
"jquery-1.10.2.min.js" = 'html/IRV/jquery-1.10.2.min.js'
)

//Registers HTML Interface assets.
/datum/asset/HTML_interface/register()
Expand Down
11 changes: 11 additions & 0 deletions code/modules/mob/new_player/new_player.dm
Expand Up @@ -201,6 +201,8 @@
if(href_list["votepollid"] && href_list["votetype"])
var/pollid = text2num(href_list["votepollid"])
var/votetype = href_list["votetype"]
//lets take data from the user to decide what kind of poll this is, without validating it
//what could go wrong
switch(votetype)
if(POLLTYPE_OPTION)
var/optionid = text2num(href_list["voteoptionid"])
Expand All @@ -219,6 +221,7 @@
var/id_max = text2num(href_list["maxid"])

if( (id_max - id_min) > 100 ) //Basic exploit prevention
//(protip, this stops no exploits)
usr << "The option ID difference is too big. Please contact administration or the database admin."
return

Expand Down Expand Up @@ -257,6 +260,14 @@
usr << "<span class='danger'>Maximum replies reached.</span>"
break
usr << "<span class='notice'>Vote successful.</span>"
if(POLLTYPE_IRV)
if (!href_list["IRVdata"])
src << "<span class='danger'>No ordering data found. Please try again or contact an administrator.</span>"
var/list/votelist = splittext(href_list["IRVdata"], ",")
if (!vote_on_irv_poll(pollid, votelist))
src << "<span class='danger'>Vote failed, please try again or contact an administrator.</span>"
return
src << "<span class='notice'>Vote successful.</span>"

/mob/new_player/proc/IsJobAvailable(rank)
var/datum/job/job = SSjob.GetJob(rank)
Expand Down