mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-25 16:45:42 +00:00
Misc: +Fixes unreported issue with initializing lighting on a specific zlevel +Fixes two similar issues with moveElement and moveRange. Where fromIndex or toIndex could be adjusted incorrectly in certain conditions. Potentially causing bad-sorts, or out of bound errors. +Rewrites listclearnulls(list/L) to no longer iterate through L.len elements for every null in the list (plus 1). i.e. went from L.len*(number_of_nulls+1) list-element reads (best-case), to L.len list-element reads (worst-case) +New proc/getElementByVar(list/L, varname, value) which finds the first datum in a list, with a variable named varname, which equals value. You can also feed it atoms instead of lists due to the way the in operator functions. +Fixes an unreported issue with Yota's list2text rewrite. Under certain conditions, the first element would not be converted into a string. Causing type-mismatch runtimes. +New global map_ready variable. This is not fully implemented yet, but will be used to avoid duplicate calls to initialize() for map objects. +All turfs now maintain references to all lights currently illuminating them. This will mean higher memory use unfortunately, due to the huge number of turfs. However, it will speed up updateAffectingLights significantly. I've used list husbandry to reduce baseline memory usage, so it shouldn't be any worse than some past atmos modifications memory-wise. -Removed 'quadratic lighting', can add this back at some point. Sorry. +modified the way lum() works slightly, to allow turfs to have overridden delta-lumen. i.e. space cannot be illuminated more than its default ambiance. This allowed removal of some iffy special-snowflake lighting areas implemented by somebody else. +Lighting images in the dmi can now use arbitrary naming schemes. It is reliant on order now. This allows the dmi to be replaced by simply dropping in a new dmi. -Removed all subtypes of /area/shuttle. Shuttles now create duplicate 'rooms' of /area/shuttle. (More on this later). This will conflict with most maps. Guide on how to fix to follow. +All verbs/tools relating to world.tick_lag were refactored to use world.fps. However old config text for setting tick_lag will still work (it converts the value to fps for you) +MC stats improved using smoothing. They now have their own tab so they dont get in the way when you're playing as an admin. -removed the push_mob_back stuff due to conflicting changes. Sorry Giacom. _OK, NOW THE ACTUAL INTERESTING STUFF_ Following systems moved over to subsystem datums: air_master garbage_manager lighting_controller process_mobs (aka Life()) nanomanager power sun pipenets AFK kick loops shuttle_controller (aka emergency shuttle/pods), supply_shuttle and other shuttles voting bots radio diseases events jobs objects ticker Subsystems hooks and variables should be commented fairly in-depth. If anything isn't particularly clear, please make an issue. Many system-specific global variables have been refactored into All tickers which previously used world.timeofday now use world.time some subsystems can iterate before round start. this resolves the issue with votes not working pregame
258 lines
7.5 KiB
Plaintext
258 lines
7.5 KiB
Plaintext
var/datum/subsystem/vote/SSvote
|
|
|
|
/datum/subsystem/vote
|
|
name = "Vote"
|
|
can_fire = 1
|
|
wait = 10
|
|
priority = -1
|
|
|
|
var/initiator = null
|
|
var/started_time = null
|
|
var/time_remaining = 0
|
|
var/mode = null
|
|
var/question = null
|
|
var/list/choices = list()
|
|
var/list/voted = list()
|
|
var/list/voting = list()
|
|
|
|
/datum/subsystem/vote/New()
|
|
NEW_SS_GLOBAL(SSvote)
|
|
|
|
/datum/subsystem/vote/fire() //called by master_controller
|
|
if(mode)
|
|
time_remaining = round((started_time + config.vote_period - world.time)/10)
|
|
|
|
if(time_remaining < 0)
|
|
result()
|
|
for(var/client/C in voting)
|
|
C << browse(null, "window=vote;can_close=0")
|
|
reset()
|
|
else
|
|
var/datum/browser/client_popup
|
|
for(var/client/C in voting)
|
|
client_popup = new(C, "vote", "Voting Panel")
|
|
client_popup.set_window_options("can_close=0")
|
|
client_popup.set_content(interface(C))
|
|
client_popup.open(0)
|
|
|
|
|
|
/datum/subsystem/vote/proc/reset()
|
|
initiator = null
|
|
time_remaining = 0
|
|
mode = null
|
|
question = null
|
|
choices.Cut()
|
|
voted.Cut()
|
|
voting.Cut()
|
|
|
|
/datum/subsystem/vote/proc/get_result()
|
|
//get the highest number of votes
|
|
var/greatest_votes = 0
|
|
var/total_votes = 0
|
|
for(var/option in choices)
|
|
var/votes = choices[option]
|
|
total_votes += votes
|
|
if(votes > greatest_votes)
|
|
greatest_votes = votes
|
|
//default-vote for everyone who didn't vote
|
|
if(!config.vote_no_default && choices.len)
|
|
var/non_voters = (clients.len - total_votes)
|
|
if(non_voters > 0)
|
|
if(mode == "restart")
|
|
choices["Continue Playing"] += non_voters
|
|
if(choices["Continue Playing"] >= greatest_votes)
|
|
greatest_votes = choices["Continue Playing"]
|
|
else if(mode == "gamemode")
|
|
if(master_mode in choices)
|
|
choices[master_mode] += non_voters
|
|
if(choices[master_mode] >= greatest_votes)
|
|
greatest_votes = choices[master_mode]
|
|
//get all options with that many votes and return them in a list
|
|
. = list()
|
|
if(greatest_votes)
|
|
for(var/option in choices)
|
|
if(choices[option] == greatest_votes)
|
|
. += option
|
|
return .
|
|
|
|
/datum/subsystem/vote/proc/announce_result()
|
|
var/list/winners = get_result()
|
|
var/text
|
|
if(winners.len > 0)
|
|
if(question) text += "<b>[question]</b>"
|
|
else text += "<b>[capitalize(mode)] Vote</b>"
|
|
for(var/i=1,i<=choices.len,i++)
|
|
var/votes = choices[choices[i]]
|
|
if(!votes) votes = 0
|
|
text += "\n<b>[choices[i]]:</b> [votes]"
|
|
if(mode != "custom")
|
|
if(winners.len > 1)
|
|
text = "\n<b>Vote Tied Between:</b>"
|
|
for(var/option in winners)
|
|
text += "\n\t[option]"
|
|
. = pick(winners)
|
|
text += "\n<b>Vote Result: [.]</b>"
|
|
else
|
|
text += "\n<b>Did not vote:</b> [clients.len-voted.len]"
|
|
else
|
|
text += "<b>Vote Result: Inconclusive - No Votes!</b>"
|
|
log_vote(text)
|
|
world << "\n<font color='purple'>[text]</font>"
|
|
return .
|
|
|
|
/datum/subsystem/vote/proc/result()
|
|
. = announce_result()
|
|
var/restart = 0
|
|
if(.)
|
|
switch(mode)
|
|
if("restart")
|
|
if(. == "Restart Round")
|
|
restart = 1
|
|
if("gamemode")
|
|
if(master_mode != .)
|
|
world.save_mode(.)
|
|
if(ticker && ticker.mode)
|
|
restart = 1
|
|
else
|
|
master_mode = .
|
|
|
|
if(restart)
|
|
world << "World restarting due to vote..."
|
|
feedback_set_details("end_error","restart vote")
|
|
if(blackbox) blackbox.save_all_data_to_sql()
|
|
sleep(50)
|
|
log_game("Rebooting due to restart vote")
|
|
world.Reboot()
|
|
|
|
return .
|
|
|
|
/datum/subsystem/vote/proc/submit_vote(var/vote)
|
|
if(mode)
|
|
if(config.vote_no_dead && usr.stat == DEAD && !usr.client.holder)
|
|
return 0
|
|
if(!(usr.ckey in voted))
|
|
if(vote && 1<=vote && vote<=choices.len)
|
|
voted += usr.ckey
|
|
choices[choices[vote]]++ //check this
|
|
return vote
|
|
return 0
|
|
|
|
/datum/subsystem/vote/proc/initiate_vote(var/vote_type, var/initiator_key)
|
|
if(!mode)
|
|
if(started_time != null)
|
|
var/next_allowed_time = (started_time + config.vote_delay)
|
|
if(next_allowed_time > world.time)
|
|
return 0
|
|
|
|
reset()
|
|
switch(vote_type)
|
|
if("restart") choices.Add("Restart Round","Continue Playing")
|
|
if("gamemode") choices.Add(config.votable_modes)
|
|
if("custom")
|
|
question = html_encode(input(usr,"What is the vote for?") as text|null)
|
|
if(!question) return 0
|
|
for(var/i=1,i<=10,i++)
|
|
var/option = capitalize(html_encode(input(usr,"Please enter an option or hit cancel to finish") as text|null))
|
|
if(!option || mode || !usr.client) break
|
|
choices.Add(option)
|
|
else return 0
|
|
mode = vote_type
|
|
initiator = initiator_key
|
|
started_time = world.time
|
|
var/text = "[capitalize(mode)] vote started by [initiator]."
|
|
if(mode == "custom")
|
|
text += "\n[question]"
|
|
log_vote(text)
|
|
world << "\n<font color='purple'><b>[text]</b>\nType <b>vote</b> or click <a href='?src=\ref[src]'>here</a> to place your votes.\nYou have [config.vote_period/10] seconds to vote.</font>"
|
|
time_remaining = round(config.vote_period/10)
|
|
return 1
|
|
return 0
|
|
|
|
/datum/subsystem/vote/proc/interface(var/client/C)
|
|
if(!C) return
|
|
var/admin = 0
|
|
var/trialmin = 0
|
|
if(C.holder)
|
|
admin = 1
|
|
if(check_rights_for(C, R_ADMIN))
|
|
trialmin = 1
|
|
voting |= C
|
|
|
|
if(mode)
|
|
if(question) . += "<h2>Vote: '[question]'</h2>"
|
|
else . += "<h2>Vote: [capitalize(mode)]</h2>"
|
|
. += "Time Left: [time_remaining] s<hr><ul>"
|
|
for(var/i=1,i<=choices.len,i++)
|
|
var/votes = choices[choices[i]]
|
|
if(!votes) votes = 0
|
|
. += "<li><a href='?src=\ref[src];vote=[i]'>[choices[i]]</a> ([votes] votes)</li>"
|
|
. += "</ul><hr>"
|
|
if(admin)
|
|
. += "(<a href='?src=\ref[src];vote=cancel'>Cancel Vote</a>) "
|
|
else
|
|
. += "<h2>Start a vote:</h2><hr><ul><li>"
|
|
//restart
|
|
if(trialmin || config.allow_vote_restart)
|
|
. += "<a href='?src=\ref[src];vote=restart'>Restart</a>"
|
|
else
|
|
. += "<font color='grey'>Restart (Disallowed)</font>"
|
|
if(trialmin)
|
|
. += "\t(<a href='?src=\ref[src];vote=toggle_restart'>[config.allow_vote_restart?"Allowed":"Disallowed"]</a>)"
|
|
. += "</li><li>"
|
|
//gamemode
|
|
if(trialmin || config.allow_vote_mode)
|
|
. += "<a href='?src=\ref[src];vote=gamemode'>GameMode</a>"
|
|
else
|
|
. += "<font color='grey'>GameMode (Disallowed)</font>"
|
|
if(trialmin)
|
|
. += "\t(<a href='?src=\ref[src];vote=toggle_gamemode'>[config.allow_vote_mode?"Allowed":"Disallowed"]</a>)"
|
|
|
|
. += "</li>"
|
|
//custom
|
|
if(trialmin)
|
|
. += "<li><a href='?src=\ref[src];vote=custom'>Custom</a></li>"
|
|
. += "</ul><hr>"
|
|
. += "<a href='?src=\ref[src];vote=close' style='position:absolute;right:50px'>Close</a>"
|
|
return .
|
|
|
|
|
|
/datum/subsystem/vote/Topic(href,href_list[],hsrc)
|
|
if(!usr || !usr.client) return //not necessary but meh...just in-case somebody does something stupid
|
|
switch(href_list["vote"])
|
|
if("close")
|
|
voting -= usr.client
|
|
usr << browse(null, "window=vote")
|
|
return
|
|
if("cancel")
|
|
if(usr.client.holder)
|
|
reset()
|
|
if("toggle_restart")
|
|
if(usr.client.holder)
|
|
config.allow_vote_restart = !config.allow_vote_restart
|
|
if("toggle_gamemode")
|
|
if(usr.client.holder)
|
|
config.allow_vote_mode = !config.allow_vote_mode
|
|
if("restart")
|
|
if(config.allow_vote_restart || usr.client.holder)
|
|
initiate_vote("restart",usr.key)
|
|
if("gamemode")
|
|
if(config.allow_vote_mode || usr.client.holder)
|
|
initiate_vote("gamemode",usr.key)
|
|
if("custom")
|
|
if(usr.client.holder)
|
|
initiate_vote("custom",usr.key)
|
|
else
|
|
submit_vote(round(text2num(href_list["vote"])))
|
|
usr.vote()
|
|
|
|
|
|
/mob/verb/vote()
|
|
set category = "OOC"
|
|
set name = "Vote"
|
|
|
|
var/datum/browser/popup = new(src, "vote", "Voting Panel")
|
|
popup.set_window_options("can_close=0")
|
|
popup.set_content(SSvote.interface(client))
|
|
popup.open(0)
|
|
|