Skip to content

Commit

Permalink
This is bad, this doesn't work, Stop looking at it
Browse files Browse the repository at this point in the history
  • Loading branch information
RemieRichards committed Jun 30, 2016
1 parent f010371 commit 7396eeb
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 2 deletions.
1 change: 1 addition & 0 deletions code/__DEFINES/misc.dm
Expand Up @@ -302,6 +302,7 @@ var/list/bloody_footprints_cache = list()
#define POLLTYPE_TEXT "TEXT"
#define POLLTYPE_RATING "NUMVAL"
#define POLLTYPE_MULTI "MULTICHOICE"
#define POLLTYPE_IRV "INSTANTRUNOFFVOTING"

//lighting area defines
#define DYNAMIC_LIGHTING_DISABLED 0 //dynamic lighting disabled (area stays at full brightness)
Expand Down
5 changes: 5 additions & 0 deletions code/modules/admin/create_poll.dm
Expand Up @@ -48,6 +48,11 @@
choice_amount = input("How many choices should be allowed?","Select choice amount") as num|null
if(!choice_amount)
return
if("Instant Run-off")
polltype = POLLTYPE_IRV
choice_amount = input("How many candidates are running?", "Select number of running candidates") as num|null
if(!choice_amount)
return
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
17 changes: 17 additions & 0 deletions code/modules/mob/new_player/new_player.dm
Expand Up @@ -257,6 +257,23 @@
usr << "<span class='danger'>Maximum replies reached.</span>"
break
usr << "<span class='notice'>Vote successful.</span>"
if(POLLTYPE_IRV)
var/id_max = text2num(href_list["maxoptionid"])
for(var/optionid = 1 to id_max)
if(!isnull(href_list["option_[optionid]"]))
var/i = vote_on_irv_poll(pollid, optionid)
switch(i)
if(0)
continue
if(1)
usr << "<span class='danger'>Vote failed, please try again or contact an administrator.</span>"
return
if(2)
usr << "<span class='danger'>You have voted on all candidates.</span>"
break
if(3)
usr << "<span class='danger'>No fuck you.</span>"
usr << "<span class='notice'>Vote successful.</span>"

/mob/new_player/proc/IsJobAvailable(rank)
var/datum/job/job = SSjob.GetJob(rank)
Expand Down
86 changes: 84 additions & 2 deletions code/modules/mob/new_player/poll.dm
@@ -1,6 +1,7 @@
/datum/polloption
var/optionid
var/optiontext
var/optionrating

/mob/new_player/proc/handle_player_polling()
if(!dbcon.IsConnected())
Expand Down Expand Up @@ -224,7 +225,48 @@
output += "<p><input type='submit' value='Vote'></form>"
output += "</div>"
src << browse(output,"window=playerpoll;size=500x250")
return
if(POLLTYPE_IRV)
var/DBQuery/voted_query = dbcon.NewQuery("SELECT o.id, o.text, v.rating FROM [format_table_name("poll_option")] o, [format_table_name("poll_vote")] v WHERE o.pollid = [pollid] AND v.ckey = '[ckey]' AND o.id = v.optionid")
if(!voted_query.Execute())
var/err = voted_query.ErrorMsg()
log_game("SQL ERROR obtaining o.id, o.text, v.rating from poll_option and poll_vote tables. Error : \[[err]\]\n")
return
var/list/votedfor = list()
while(voted_query.NextRow())
votedfor.Add(text2num(voted_query.item[1]))
var/list/datum/polloption/options = list()
while(voted_query.NextRow())
var/datum/polloption/O = new()
O.optionid = text2num(voted_query.item[1])
O.optiontext = voted_query.item[2] //optiontext stores the Candidate's name
O.optionrating = voted_query.item[3] //how we rate Candidate, 1st, 2nd, 3rd choice etc.
options += O
shuffle(options)
var/output = "<div align='center'><B>Player poll</B><hr>"
output += "<b>Question: [pollquestion]</b><br>"
output += "<font size='2'>Poll runs from <b>[pollstarttime]</b> until <b>[pollendtime]</b></font><p>"
if(!votedfor.len)
output += "<form name = 'cardcomp' action='>src=\ref[src]' method='get'>"
output += "<input type='hidden' name='src' value=\ref[src]'>"
output += "<input type='hidden' name='votepollid' value='[pollid]'>"
output += "<input type='hidden' name='votetype' value=[POLLTYPE_IRV]>"
output += "<input type='hidden' name='maxoptionid' value='[options.len]'>"
output += "<table><tr><td>"
for(var/datum/polloption/O in options)
if(O.optionid && O.optiontext && O.optionrating)
if(votedfor.len)
if(O.optionid in votedfor)
output += "[O.optiontext] - \[<B>[O.optionrating]</B>\]<br>"
else
output += "[O.optiontext] - \[0\]<br>"
else
output += "<input type='number' name='option_[O.optionid]' min='1' max='[options.len]'>[O.optiontext] - \[ \]\<br>"
output += "</td></tr></table>"
if(!votedfor.len)
output += "<p><input type='submit' value='Vote'></form>"
output += "</div>"
src << browse(output,"window=playerpoll;size=500x250")


/mob/new_player/proc/poll_check_voted(pollid, table)
if(!dbcon.IsConnected())
Expand Down Expand Up @@ -338,4 +380,44 @@
log_game("SQL ERROR adding vote to table. Error : \[[err]\]\n")
return 1
usr << browse(null,"window=playerpoll")
return 0
return 0

/mob/new_player/proc/vote_on_irv_poll(pollid, optionid)
if(!pollid || !optionid)
return 1
if(!dbcon.IsConnected())
usr << "<span class='danger'>Failed to establish database connection.</span>"
return 1
var/DBQuery/query_get_candidates = dbcon.NewQuery("SELECT multiplechoiceoptions FROM [format_table_name("poll_question")] WHERE id = [pollid]")
if(!query_get_candidates.Execute())
var/err = query_get_candidates.ErrorMsg()
log_game("SQL ERROR obtaining multiplechoiceoptions from poll_question table. Error : \[[err]\]\n")
return 1
var/i
if(query_get_candidates.NextRow())
i = text2num(query_get_candidates.item[1])
var/DBQuery/query_hasvoted = dbcon.NewQuery("SELECT id FROM [format_table_name("poll_vote")] WHERE pollid = [pollid] AND ckey = '[ckey]'")
if(!query_hasvoted.Execute())
var/err = query_hasvoted.ErrorMsg()
log_game("SQL ERROR obtaining id from poll_vote table. Error : \[[err]\]\n")
return 1
while(i)
if(query_hasvoted.NextRow())
i--
else
break
if(!i)
return 2
var/adminrank = "Player"
if(client.holder)
adminrank = client.holder.rank
var/rating = input(usr, "How preferable is this candidate? Available options are above [WHAT_YOU_VOTED_LAST] (Based on previous votes)", "Preference Number") as num
if(rating <= WHAT_YOU_VOTED_LAST) //I don't want to put this variable on the mob, maybe the DB, idk
return 3
var/DBQuery/query_insert = dbcon.NewQuery("INSERT INTO [format_table_name("poll_vote")] (datetime, pollid, optionid, ckey, ip, adminrank, rating) VALUES (Now(), [pollid], [optionid], '[ckey]', '[client.address]', '[adminrank]', [rating])")
if(!query_insert.Execute())
var/err = query_insert.ErrorMsg()
log_game("SQL ERROR adding vote to table. Error : \[[err]\]\n")
return 1
usr << browse(null,"window=playerpoll")
return 0

0 comments on commit 7396eeb

Please sign in to comment.