diff --git a/code/game/gamemodes/events.dm b/code/game/gamemodes/events.dm index dcd0bd64ff6..ed39dcd3678 100644 --- a/code/game/gamemodes/events.dm +++ b/code/game/gamemodes/events.dm @@ -81,8 +81,8 @@ if(istype(get_area(S), /area/turret_protected) || S.z != 1) continue S.charge = 0 - S.output = 0 - S.online = 0 + S.output_level = 0 + S.outputting = 0 S.updateicon() S.power_change() @@ -133,8 +133,8 @@ if(S.z != 1) continue S.charge = S.capacity - S.output = 200000 - S.online = 1 + S.output_level = 200000 + S.outputting = 1 S.updateicon() S.power_change() for(var/area/A in world) @@ -153,8 +153,8 @@ if(S.z != 1) continue S.charge = S.capacity - S.output = 200000 - S.online = 1 + S.output_level = 200000 + S.outputting = 1 S.updateicon() S.power_change() diff --git a/code/modules/admin/verbs/debug.dm b/code/modules/admin/verbs/debug.dm index ef7fa878bb1..398539f6b4a 100644 --- a/code/modules/admin/verbs/debug.dm +++ b/code/modules/admin/verbs/debug.dm @@ -1087,7 +1087,7 @@ var/global/list/g_fancy_list_of_safe_types = null for(var/obj/machinery/power/smes/SMES in world) if(SMES.anchored) - SMES.chargemode = 1 + SMES.input_attempt = 1 /client/proc/cmd_debug_mob_lists() set category = "Debug" diff --git a/code/modules/client/client procs.dm b/code/modules/client/client procs.dm index 60cac6ac10b..1f8cbdc07b7 100644 --- a/code/modules/client/client procs.dm +++ b/code/modules/client/client procs.dm @@ -236,6 +236,7 @@ var/next_external_rsc = 0 'nano/css/shared.css', 'nano/css/icons.css', 'nano/templates/chem_dispenser.tmpl', + 'nano/templates/smes.tmpl', 'nano/templates/apc.tmpl', 'nano/templates/cryo.tmpl', 'nano/images/uiBackground.png', diff --git a/code/modules/power/smes.dm b/code/modules/power/smes.dm index 706d5fbb2a4..2f7c585d7f6 100644 --- a/code/modules/power/smes.dm +++ b/code/modules/power/smes.dm @@ -1,8 +1,8 @@ // the SMES // stores power -#define SMESMAXCHARGELEVEL 200000 -#define SMESMAXOUTPUT 200000 +#define SMES_MAX_INPUT_LEVEL 200000 +#define SMES_MAX_OUTPUT_LEVEL 200000 /obj/machinery/power/smes name = "power storage unit" @@ -11,17 +11,18 @@ density = 1 anchored = 1 use_power = 0 - var/output = 50000 - var/lastout = 0 - var/loaddemand = 0 - var/capacity = 5e6 - var/charge = 1e6 - var/charging = 0 - var/chargemode = 0 - var/chargecount = 0 - var/chargelevel = 50000 - var/online = 1 - var/n_tag = null + var/capacity = 5e6 // maximum charge + var/charge = 1e6 //actual charge + + var/input_attempt = 0 // 1 = attempting to charge, 0 = not attempting to charge + var/inputting = 0 // 1 = actually inputting, 0 = not inputting + var/input_level = 50000 // amount of power the SMES attempts to charge by + var/input_available = 0 //amount of charge available from input last tick + + var/outputting = 1 //1 = actually outputting, 0 = not outputting + var/output_level = 50000 // amount of power the SMES attempts to output + var/output_used = 0 // amount of power actually outputted. may be less than output_level if the powernet returns excess power + var/obj/machinery/power/terminal/terminal = null @@ -52,12 +53,12 @@ overlays.Cut() if(stat & BROKEN) return - overlays += image('icons/obj/power.dmi', "smes-op[online]") + overlays += image('icons/obj/power.dmi', "smes-op[outputting]") - if(charging) + if(inputting) overlays += image('icons/obj/power.dmi', "smes-oc1") else - if(chargemode) + if(input_attempt) overlays += image('icons/obj/power.dmi', "smes-oc0") var/clevel = chargedisplay() @@ -78,51 +79,42 @@ //store machine state to see if we need to update the icon overlays var/last_disp = chargedisplay() - var/last_chrg = charging - var/last_onln = online + var/last_chrg = inputting + var/last_onln = outputting if(terminal) - var/excess = terminal.surplus() + input_available = terminal.surplus() - if(charging) - if(excess >= 0) // if there's power available, try to charge + if(inputting) + if(input_available > 0 && input_available >= input_level) // if there's power available, try to charge - var/load = min((capacity-charge)/SMESRATE, chargelevel) // charge at set rate, limited to spare capacity + var/load = min((capacity-charge)/SMESRATE, input_level) // charge at set rate, limited to spare capacity charge += load * SMESRATE // increase the charge add_load(load) // add the load to the terminal side network else // if not enough capcity - charging = 0 // stop charging - chargecount = 0 + inputting = 0 // stop inputting - else - if(chargemode) - if(chargecount > rand(3,6)) - charging = 1 - chargecount = 0 + else if(input_attempt) + if(input_available > 0 && input_available >= input_level) + inputting = 1 - if(excess > chargelevel) - chargecount++ - else - chargecount = 0 - else - chargecount = 0 - if(online) // if outputting - lastout = min( charge/SMESRATE, output) //limit output to that stored + if(outputting) + output_used = min( charge/SMESRATE, output_level) //limit output to that stored - charge -= lastout*SMESRATE // reduce the storage (may be recovered in /restore() if excessive) + charge -= output_used*SMESRATE // reduce the storage (may be recovered in /restore() if excessive) - add_avail(lastout) // add output to powernet (smes side) + add_avail(output_used) // add output to powernet (smes side) if(charge < 0.0001) - online = 0 // stop output if charge falls to zero + outputting = 0 investigate_log("lost power and turned off","singulo") // only update icon if state changed - if(last_disp != chargedisplay() || last_chrg != charging || last_onln != online) + if(last_disp != chargedisplay() || last_chrg != inputting || last_onln != outputting) updateicon() updateDialog() @@ -136,13 +128,13 @@ if(stat & BROKEN) return - if(!online) - loaddemand = 0 + if(!outputting) + output_used = 0 return var/excess = powernet.netexcess // this was how much wasn't used on the network last ptick, minus any removed by other SMESes - excess = min(lastout, excess) // clamp it to how much was actually output by this SMES last ptick + excess = min(output_used, excess) // clamp it to how much was actually output by this SMES last ptick excess = min((capacity-charge)/SMESRATE, excess) // for safety, also limit recharge by space capacity of SMES (shouldn't happen) @@ -153,7 +145,7 @@ charge += excess * SMESRATE powernet.netexcess -= excess // remove the excess from the powernet, so later SMESes don't try to use it - loaddemand = lastout-excess + output_used -= excess if(clev != chargedisplay() ) updateicon() @@ -178,37 +170,39 @@ /obj/machinery/power/smes/interact(mob/user) - if(get_dist(src, user) > 1 && !istype(user, /mob/living/silicon/ai)) - user.unset_machine() - user << browse(null, "window=smes") + return ui_interact(user) + +/obj/machinery/power/smes/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null) + if(!user) return - user.set_machine(src) + var/list/data = list( + "capacityPercent" = round(100.0*charge/capacity, 0.1), + "capacity" = capacity, + "charge" = charge, - var/t = "SMES Power Storage Unit [n_tag? "([n_tag])" : null]
"
+		"inputAttempt" = input_attempt,
+		"inputting" = inputting,
+		"inputLevel" = input_level,
+		"inputAvailable" = input_available,
 
-	t += "Stored capacity : [round(100.0*charge/capacity, 0.1)]%

" - - t += "Input: [charging ? "Charging" : "Not Charging"] [chargemode ? "Auto Off" : "Auto Off "]
" - - - t += "Input level: M - - - [add_lspace(chargelevel,5)] + + + M
" - - t += "

" - - t += "Output: [online ? "Online Offline" : "Online Offline "]
" - - t += "Output level: M - - - [add_lspace(output,5)] + + + M
" - - t += "Output load: [round(loaddemand)] W
" - - t += "

Close" - - t += "
" - user << browse(t, "window=smes;size=460x300") - onclose(user, "smes") - return + "outputting" = outputting, + "outputLevel" = output_level, + "outputUsed" = output_used + ) + // update the ui if it exists, returns null if no ui is passed/found + ui = nanomanager.try_update_ui(user, src, ui_key, ui, data) + if (!ui) + // the ui does not exist, so we'll create a new() one + // for a list of parameters and their descriptions see the code docs in \code\modules\nano\nanoui.dm + ui = new(user, src, ui_key, "smes.tmpl", "SMES - [name]", 540, 360) + // when the ui is first opened this is the data it will use + ui.set_initial_data(data) + // open the new ui window + ui.open() + // auto update every Master Controller tick + ui.set_auto_update(1) /obj/machinery/power/smes/Topic(href, href_list) if(..()) @@ -216,82 +210,51 @@ //world << "[href] ; [href_list[href]]" - if( href_list["close"] ) - usr << browse(null, "window=smes") - usr.unset_machine() - return - - else if( href_list["cmode"] ) - chargemode = !chargemode - if(!chargemode) - charging = 0 - investigate_log("input/output; [chargelevel>output?"":""][chargelevel]/[output] | Output-mode: [online?"on":"off"] | Input-mode: [chargemode?"auto":"off"] by [usr.key]","singulo") + else if( href_list["input_attempt"] ) + input_attempt = text2num(href_list["input_attempt"]) + if(!input_attempt) + inputting = 0 + investigate_log("input/output; [input_level>output_level?"":""][input_level]/[output_level] | Output-mode: [outputting?"on":"off"] | Input-mode: [input_attempt?"auto":"off"] by [usr.key]","singulo") updateicon() - else if( href_list["online"] ) - online = !online - investigate_log("input/output; [chargelevel>output?"":""][chargelevel]/[output] | Output-mode: [online?"on":"off"] | Input-mode: [chargemode?"auto":"off"] by [usr.key]","singulo") + else if( href_list["outputting"] ) + outputting = text2num(href_list["outputting"]) + investigate_log("input/output; [input_level>output_level?"":""][input_level]/[output_level] | Output-mode: [outputting?"on":"off"] | Input-mode: [input_attempt?"auto":"off"] by [usr.key]","singulo") updateicon() - else if( href_list["input"] ) + else if( href_list["set_input_level"] ) + switch(href_list["set_input_level"]) + if("max") + input_level = SMES_MAX_INPUT_LEVEL + if("custom") + var/custom = input(usr, "What rate would you like this SMES to attempt to charge at? Max is [SMES_MAX_INPUT_LEVEL].") as null|num + if(isnum(custom)) + input_level = custom + else + var/n = text2num(href_list["set_input_level"]) + if(isnum(n)) + input_level = n - var/i = text2num(href_list["input"]) + input_level = Clamp(input_level, 0, SMES_MAX_INPUT_LEVEL) + investigate_log("input/output; [input_level>output_level?"":""][input_level]/[output_level] | Output-mode: [outputting?"on":"off"] | Input-mode: [input_attempt?"auto":"off"] by [usr.key]","singulo") - var/d = 0 - switch(i) - if(-4) - chargelevel = 0 - if(4) - chargelevel = SMESMAXCHARGELEVEL //30000 + else if(href_list["set_output_level"]) + switch(href_list["set_output_level"]) + if("max") + output_level = SMES_MAX_OUTPUT_LEVEL + if("custom") + var/custom = input(usr, "What rate would you like this SMES to attempt to output at? Max is [SMES_MAX_OUTPUT_LEVEL].") as null|num + if(isnum(custom)) + output_level = custom + else + var/n = text2num(href_list["set_output_level"]) + if(isnum(n)) + output_level = n - if(1) - d = 100 - if(-1) - d = -100 - if(2) - d = 1000 - if(-2) - d = -1000 - if(3) - d = 10000 - if(-3) - d = -10000 - - chargelevel += d - chargelevel = max(0, min(SMESMAXCHARGELEVEL, chargelevel)) // clamp to range - investigate_log("input/output; [chargelevel>output?"":""][chargelevel]/[output] | Output-mode: [online?"on":"off"] | Input-mode: [chargemode?"auto":"off"] by [usr.key]","singulo") - src.updateUsrDialog() - - else if( href_list["output"] ) - - var/i = text2num(href_list["output"]) - - var/d = 0 - switch(i) - if(-4) - output = 0 - if(4) - output = SMESMAXOUTPUT //30000 - - if(1) - d = 100 - if(-1) - d = -100 - if(2) - d = 1000 - if(-2) - d = -1000 - if(3) - d = 10000 - if(-3) - d = -10000 - - output += d - output = max(0, min(SMESMAXOUTPUT, output)) // clamp to range - - investigate_log("input/output; [chargelevel>output?"":""][chargelevel]/[output] | Output-mode: [online?"on":"off"] | Input-mode: [chargemode?"auto":"off"] by [usr.key]","singulo") - src.updateUsrDialog() + output_level = Clamp(output_level, 0, SMES_MAX_OUTPUT_LEVEL) + investigate_log("input/output; [input_level>output_level?"":""][input_level]/[output_level] | Output-mode: [outputting?"on":"off"] | Input-mode: [input_attempt?"auto":"off"] by [usr.key]","singulo") + add_fingerprint(usr) /obj/machinery/power/smes/proc/ion_act() if(src.z == 1) @@ -325,16 +288,16 @@ /obj/machinery/power/smes/emp_act(severity) - online = 0 - charging = 0 - output = 0 + outputting = 0 + inputting = 0 + output_level = 0 charge -= 1e6/severity if (charge < 0) charge = 0 spawn(100) - output = initial(output) - charging = initial(charging) - online = initial(online) + output_level = initial(output_level) + inputting = initial(inputting) + outputting = initial(outputting) ..()