///All currently running polls held as datums
GLOBAL_LIST_EMPTY(polls)
GLOBAL_PROTECT(polls)
///All poll option datums of running polls
GLOBAL_LIST_EMPTY(poll_options)
GLOBAL_PROTECT(poll_options)
/**
* Shows a list of currently running polls a player can vote/has voted on
*
*/
/mob/dead/new_player/proc/handle_player_polling()
var/list/output = list("
Player polls
")
var/rs = REF(src)
for(var/p in GLOB.polls)
var/datum/poll_question/poll = p
if((poll.admin_only && !client.holder) || poll.future_poll)
continue
output += "
"
src << browse(jointext(output, ""),"window=playerpolllist;size=500x300")
/**
* Redirects a player to the correct poll window based on poll type.
*
*/
/mob/dead/new_player/proc/poll_player(datum/poll_question/poll)
if(!poll)
return
if(!SSdbcore.Connect())
to_chat(src, span_danger("Failed to establish database connection."))
return
switch(poll.poll_type)
if(POLLTYPE_OPTION)
poll_player_option(poll)
if(POLLTYPE_TEXT)
poll_player_text(poll)
if(POLLTYPE_RATING)
poll_player_rating(poll)
if(POLLTYPE_MULTI)
poll_player_multi(poll)
if(POLLTYPE_IRV)
poll_player_irv(poll)
/**
* Shows voting window for an option type poll, listing its options and relevant details.
*
* If already voted on, the option a player voted for is pre-selected.
*
*/
/mob/dead/new_player/proc/poll_player_option(datum/poll_question/poll)
var/datum/db_query/query_option_get_voted = SSdbcore.NewQuery({"
SELECT optionid FROM [format_table_name("poll_vote")]
WHERE pollid = :pollid AND ckey = :ckey AND deleted = 0
"}, list("pollid" = poll.poll_id, "ckey" = ckey))
if(!query_option_get_voted.warn_execute())
qdel(query_option_get_voted)
return
var/voted_option_id = 0
if(query_option_get_voted.NextRow())
voted_option_id = text2num(query_option_get_voted.item[1])
qdel(query_option_get_voted)
var/list/output = list("
Player pollQuestion: [poll.question] ")
if(poll.subtitle)
output += "[poll.subtitle] "
output += "Poll runs from [poll.start_datetime] until [poll.end_datetime] "
if(poll.allow_revoting)
output += "Revoting is enabled."
if(!voted_option_id || poll.allow_revoting)
output += {""
output += "
"
src << browse(jointext(output, ""),"window=playerpoll;size=500x250")
/**
* Shows voting window for a text response type poll, listing its relevant details.
*
* If already responded to, the saved response of a player is shown.
*
*/
/mob/dead/new_player/proc/poll_player_text(datum/poll_question/poll)
var/datum/db_query/query_text_get_replytext = SSdbcore.NewQuery({"
SELECT replytext FROM [format_table_name("poll_textreply")]
WHERE pollid = :pollid AND ckey = :ckey AND deleted = 0
"}, list("pollid" = poll.poll_id, "ckey" = ckey))
if(!query_text_get_replytext.warn_execute())
qdel(query_text_get_replytext)
return
var/reply_text = ""
if(query_text_get_replytext.NextRow())
reply_text = query_text_get_replytext.item[1]
qdel(query_text_get_replytext)
var/list/output = list("
Player pollQuestion: [poll.question] ")
if(poll.subtitle)
output += "[poll.subtitle] "
output += "Feedback gathering runs from [poll.start_datetime] until [poll.end_datetime] "
if(poll.allow_revoting)
output += "Revoting is enabled."
if(!reply_text || poll.allow_revoting)
output += {"
"}
else
output += "[reply_text]"
output += "
"
src << browse(jointext(output, ""),"window=playerpoll;size=500x500")
/**
* Shows voting window for a rating type poll, listing its options and relevant details.
*
* If already voted on, the options a player voted for are pre-selected.
*
*/
/mob/dead/new_player/proc/poll_player_rating(datum/poll_question/poll)
var/datum/db_query/query_rating_get_votes = SSdbcore.NewQuery({"
SELECT optionid, rating FROM [format_table_name("poll_vote")]
WHERE pollid = :pollid AND ckey = :ckey AND deleted = 0
"}, list("pollid" = poll.poll_id, "ckey" = ckey))
if(!query_rating_get_votes.warn_execute())
qdel(query_rating_get_votes)
return
var/list/voted_ratings = list()
while(query_rating_get_votes.NextRow())
voted_ratings += list("[query_rating_get_votes.item[1]]" = query_rating_get_votes.item[2])
qdel(query_rating_get_votes)
var/list/output = list("
Player pollQuestion: [poll.question] ")
if(poll.subtitle)
output += "[poll.subtitle] "
output += "Poll runs from [poll.start_datetime] until [poll.end_datetime] "
if(poll.allow_revoting)
output += "Revoting is enabled."
if(!length(voted_ratings) || poll.allow_revoting)
output += {""
output += "
"
src << browse(jointext(output, ""),"window=playerpoll;size=500x500")
/**
* Shows voting window for a multiple choice type poll, listing its options and relevant details.
*
* If already voted on, the options a player voted for are pre-selected.
*
*/
/mob/dead/new_player/proc/poll_player_multi(datum/poll_question/poll)
var/datum/db_query/query_multi_get_votes = SSdbcore.NewQuery({"
SELECT optionid FROM [format_table_name("poll_vote")]
WHERE pollid = :pollid AND ckey = :ckey AND deleted = 0
"}, list("pollid" = poll.poll_id, "ckey" = ckey))
if(!query_multi_get_votes.warn_execute())
qdel(query_multi_get_votes)
return
var/list/voted_for = list()
while(query_multi_get_votes.NextRow())
voted_for += text2num(query_multi_get_votes.item[1])
qdel(query_multi_get_votes)
var/list/output = list("
Player pollQuestion: [poll.question] ")
if(poll.subtitle)
output += "[poll.subtitle] "
output += "You can select up to [poll.options_allowed] options. If you select more, the first [poll.options_allowed] will be saved. Poll runs from [poll.start_datetime] until [poll.end_datetime] "
if(poll.allow_revoting)
output += "Revoting is enabled."
if(!length(voted_for) || poll.allow_revoting)
output += {""
output += "
"
src << browse(jointext(output, ""),"window=playerpoll;size=500x300")
/**
* Shows voting window for an IRV type poll, listing its options and relevant details.
*
* If already voted on, the options are sorted how a player voted for them, otherwise they are randomly shuffled.
*
*/
/mob/dead/new_player/proc/poll_player_irv(datum/poll_question/poll)
var/datum/asset/irv_assets = get_asset_datum(/datum/asset/group/irv)
irv_assets.send(src)
var/datum/db_query/query_irv_get_votes = SSdbcore.NewQuery({"
SELECT optionid FROM [format_table_name("poll_vote")]
WHERE pollid = :pollid AND ckey = :ckey AND deleted = 0
"}, list("pollid" = poll.poll_id, "ckey" = ckey))
if(!query_irv_get_votes.warn_execute())
qdel(query_irv_get_votes)
return
var/list/voted_for = list()
while(query_irv_get_votes.NextRow())
voted_for += text2num(query_irv_get_votes.item[1])
qdel(query_irv_get_votes)
var/list/prepared_options = list()
//if they've already voted we use the order they voted in plus a shuffle of any options they haven't voted for, if any
if(length(voted_for))
var/list/option_copy = poll.options.Copy()
for(var/vote_id in voted_for)
for(var/o in option_copy)
var/datum/poll_option/option = o
if(option.option_id == vote_id)
prepared_options += option
option_copy -= option
prepared_options += shuffle(option_copy)
//otherwise just shuffle the options
else
prepared_options = shuffle(poll.options)
var/list/output = list({"
Player pollQuestion: [poll.question] "})
if(poll.subtitle)
output += "[poll.subtitle] "
output += "Poll runs from [poll.start_datetime] until [poll.end_datetime] "
if(poll.allow_revoting)
output += "Revoting is enabled."
output += "Please sort the options in the order of most preferred to least preferred