Removes an unsed proc from smes.dm and cleans up the file (#26314)

* Initial commit

* Additional operator spacing adjustment

* Removes an unused var and autodocs another
This commit is contained in:
Burzah
2024-07-29 15:07:05 +00:00
committed by GitHub
parent 34c3465e0a
commit 6db7449388
+98 -120
View File
@@ -1,35 +1,39 @@
// the SMES
// stores power
#define SMESMAXCHARGELEVEL 200000
#define SMESMAXOUTPUT 200000
#define SMESRATE 0.05 // rate of internal charge to external power
/obj/machinery/power/smes
name = "power storage unit"
desc = "A high-capacity superconducting magnetic energy storage (SMES) unit."
icon_state = "smes"
density = TRUE
var/capacity = 5e6 // maximum charge
var/charge = 0 // actual charge
var/input_attempt = TRUE // 1 = attempting to charge, 0 = not attempting to charge
var/inputting = TRUE // 1 = actually inputting, 0 = not inputting
var/input_level = 50000 // amount of power the SMES attempts to charge by
var/input_level_max = 200000 // cap on input_level
var/input_available = 0 // amount of charge available from input last tick
var/output_attempt = TRUE // 1 = attempting to output, 0 = not attempting to output
var/outputting = TRUE // 1 = actually outputting, 0 = not outputting
var/output_level = 50000 // amount of power the SMES attempts to output
var/output_level_max = 200000 // cap on output_level
var/output_used = 0 // amount of power actually outputted. may be less than output_level if the powernet returns excess power
var/name_tag = null
var/obj/machinery/power/terminal/terminal = null
/// Maximum charge of the SMES
var/capacity = 5e6
/// Current charge level
var/charge = 0
/// Set TRUE if SMES attempting to charge, FALSE if not
var/input_attempt = TRUE
/// Set TRUE if SMES is inputting, FALSE if not
var/inputting = TRUE
/// Amount of power the SMES attempts to charge by
var/input_level = 50000
/// Maximum input level
var/input_level_max = 200000
/// Charge amount available from input last tick
var/input_available = 0
// TRUE = attempting to output, FALSE = not attempting to output
var/output_attempt = TRUE
/// TRUE = actually outputting, FALSE = not outputting
var/outputting = TRUE
/// Amount of power the SMES attempts to output
var/output_level = 50000
/// Cap on output_level
var/output_level_max = 200000
/// Amount of power actually outputted. may be less than output_level if the powernet returns excess power
var/output_used = 0
/// The terminal that is connected to this SMES unit
var/obj/machinery/power/terminal/terminal
/obj/machinery/power/smes/Initialize(mapload)
. = ..()
@@ -48,10 +52,10 @@
connect_to_network()
dir_loop:
for(var/d in GLOB.cardinal)
var/turf/T = get_step(src, d)
for(var/direction in GLOB.cardinal)
var/turf/T = get_step(src, direction)
for(var/obj/machinery/power/terminal/term in T)
if(term && term.dir == turn(d, 180))
if(term && term.dir == turn(direction, 180))
terminal = term
break dir_loop
@@ -90,20 +94,20 @@
if(stat & BROKEN)
return
. += "smes-op[outputting ? 1 : 0]"
. += "smes-oc[inputting ? 1 : 0]"
. += "smes-op[outputting ? TRUE : FALSE]"
. += "smes-oc[inputting ? TRUE : FALSE]"
var/charge_level = chargedisplay()
var/charge_level = charge_display()
if(charge_level > 0)
. += "smes-og[charge_level]"
/obj/machinery/power/smes/attackby(obj/item/I, mob/user, params)
//opening using screwdriver
// Opening using screwdriver
if(default_deconstruction_screwdriver(user, "[initial(icon_state)]-o", initial(icon_state), I))
update_icon()
return
//changing direction using wrench
// Changing direction using wrench
if(default_change_direction_wrench(user, I))
terminal = null
var/turf/T = get_step(src, dir)
@@ -120,22 +124,22 @@
update_icon()
return
//building and linking a terminal
// Building and linking a terminal
if(istype(I, /obj/item/stack/cable_coil))
var/dir = get_dir(user,src)
if(dir & (dir-1))//we don't want diagonal click
var/dir = get_dir(user, src)
if(dir & (dir - 1)) // Checks for diagonal interaction
return
if(terminal) //is there already a terminal ?
if(terminal) // Checks for an existing terminal
to_chat(user, "<span class='alert'>This SMES already has a power terminal!</span>")
return
if(!panel_open) //is the panel open ?
if(!panel_open) // Checks to see if the panel is closed
to_chat(user, "<span class='alert'>You must open the maintenance panel first!</span>")
return
var/turf/T = get_turf(user)
if(T.intact) //is the floor plating removed ?
if(T.intact) // Checks to see if floor plating is present
to_chat(user, "<span class='alert'>You must first remove the floor plating!</span>")
return
@@ -148,31 +152,33 @@
to_chat(user, "<span class='warning'>You must not be on the same tile as [src].</span>")
return
//Direction the terminal will face to
var/tempDir = get_dir(user, src)
switch(tempDir)
// Direction the terminal will face to
var/temporary_direction = get_dir(user, src)
switch(temporary_direction)
if(NORTHEAST, SOUTHEAST)
tempDir = EAST
temporary_direction = EAST
if(NORTHWEST, SOUTHWEST)
tempDir = WEST
var/turf/tempLoc = get_step(src, REVERSE_DIR(tempDir))
if(isspaceturf(tempLoc))
temporary_direction = WEST
var/turf/temporary_location = get_step(src, REVERSE_DIR(temporary_direction))
if(isspaceturf(temporary_location))
to_chat(user, "<span class='warning'>You can't build a terminal on space.</span>")
return
else if(istype(tempLoc))
if(tempLoc.intact)
else if(istype(temporary_location))
if(temporary_location.intact)
to_chat(user, "<span class='warning'>You must remove the floor plating first.</span>")
return
to_chat(user, "<span class='notice'>You start adding cable to [src].</span>")
playsound(loc, C.usesound, 50, 1)
playsound(loc, C.usesound, 50, TRUE)
if(do_after(user, 50, target = src))
if(do_after(user, 5 SECONDS, target = src))
if(!terminal && panel_open)
T = get_turf(user)
var/obj/structure/cable/N = T.get_cable_node() //get the connecting node cable, if there's one
if(prob(50) && electrocute_mob(usr, N, N, 1, TRUE)) //animate the electrocution if uncautious and unlucky
do_sparks(5, 1, src)
do_sparks(5, TRUE, src)
return
C.use(10) // make sure the cable gets used up
@@ -180,11 +186,11 @@
"<span class='notice'>[user.name] adds the cables and connects the power terminal.</span>",\
"<span class='notice'>You add the cables and connect the power terminal.</span>")
make_terminal(user, tempDir, tempLoc)
make_terminal(user, temporary_direction, temporary_location)
terminal.connect_to_network()
return
//disassembling the terminal
// Disassembling the terminal
if(istype(I, /obj/item/wirecutters) && terminal && panel_open)
var/turf/T = get_turf(terminal)
if(T.intact) //is the floor plating removed ?
@@ -192,24 +198,24 @@
return
to_chat(user, "<span class='notice'>You begin to dismantle the power terminal...</span>")
playsound(src.loc, I.usesound, 50, 1)
playsound(src.loc, I.usesound, 50, TRUE)
if(do_after(user, 50 * I.toolspeed, target = src))
if(do_after(user, 5 SECONDS * I.toolspeed, target = src))
if(terminal && panel_open)
if(prob(50) && electrocute_mob(usr, terminal.powernet, terminal, 1, TRUE)) //animate the electrocution if uncautious and unlucky
do_sparks(5, 1, src)
if(prob(50) && electrocute_mob(usr, terminal.powernet, terminal, 1, TRUE)) // Animate the electrocution if uncautious and unlucky
do_sparks(5, TRUE, src)
return
//give the wires back and delete the terminal
new /obj/item/stack/cable_coil(T,10)
// Returns wires on deletion of the terminal
new /obj/item/stack/cable_coil(T, 10)
user.visible_message(\
"<span class='alert'>[user.name] cuts the cables and dismantles the power terminal.</span>",\
"<span class='notice'>You cut the cables and dismantle the power terminal.</span>")
inputting = 0 //stop inputting, since we have don't have a terminal anymore
inputting = FALSE // Set input FALSE when the terminal no longer exists
qdel(terminal)
return
//crowbarring it !
// Crowbarring it !
if(default_deconstruction_crowbar(user, I))
return
@@ -222,51 +228,51 @@
return TRUE
return FALSE
/obj/machinery/power/smes/proc/make_terminal(user, tempDir, tempLoc)
// create a terminal object at the same position as original turf loc
// wires will attach to this
terminal = new /obj/machinery/power/terminal(tempLoc)
terminal.dir = tempDir
/obj/machinery/power/smes/proc/make_terminal(user, temporary_direction, temporary_location)
// Create a terminal object at the same position as original turf loc
// Wires will attach to this
terminal = new /obj/machinery/power/terminal(temporary_location)
terminal.dir = temporary_direction
terminal.master = src
/obj/machinery/power/smes/Destroy()
if(SSticker && SSticker.current_state == GAME_STATE_PLAYING)
var/area/area = get_area(src)
if(area)
message_admins("SMES deleted at (<A href='byond://?_src_=holder;adminplayerobservecoodjump=1;X=[x];Y=[y];Z=[z]'>[area.name]</a>)")
message_admins("SMES deleted at (<a href='byond://?_src_=holder;adminplayerobservecoodjump=1;X=[x];Y=[y];Z=[z]'>[area.name]</a>)")
log_game("SMES deleted at ([area.name])")
investigate_log("<font color='red'>deleted</font> at ([area.name])","singulo")
investigate_log("<font color='red'>deleted</font> at ([area.name])", "singulo")
if(terminal)
disconnect_terminal()
return ..()
/obj/machinery/power/smes/proc/chargedisplay()
/obj/machinery/power/smes/proc/charge_display()
return clamp(round(ceil(charge * 5 / capacity)), 0, 5)
/obj/machinery/power/smes/process()
if(stat & BROKEN)
return
//store machine state to see if we need to update the icon overlays
var/last_disp = chargedisplay()
// Store machine state to see if we need to update the icon overlays
var/last_disp = charge_display()
var/last_chrg = inputting
var/last_onln = outputting
//inputting
// Inputting
if(terminal && input_attempt)
input_available = terminal.get_power_balance()
if(inputting)
if(input_available > 0) // if there's power available, try to charge
if(input_available > 0) // Checks power availability before attempting to charge
var/load = min(min((capacity-charge)/SMESRATE, input_level), input_available) // charge at set rate, limited to spare capacity
var/load = min(min((capacity - charge) / SMESRATE, input_level), input_available) // Charge at set rate, limited to spare capacity
charge += load * SMESRATE // increase the charge
charge += load * SMESRATE // Increase the charge
terminal.consume_direct_power(load) // add the load to the terminal side network
terminal.consume_direct_power(load) // Add the load to the terminal side network
else // if not enough capcity
inputting = FALSE // stop inputting
else
inputting = FALSE // Set inputting FALSE if not enough capacity
else
if(input_attempt && input_available > 0)
@@ -277,13 +283,13 @@
//outputting
if(output_attempt && powernet)
if(outputting)
output_used = min( charge/SMESRATE, output_level) //limit output to that stored
if(produce_direct_power(output_used)) // add output to powernet if it exists (smes side)
charge -= output_used*SMESRATE // reduce the storage (may be recovered in /restore() if excessive)
output_used = min( charge/SMESRATE, output_level) // Limit output to that stored
if(produce_direct_power(output_used)) // Add output to powernet if it exists (smes side)
charge -= output_used * SMESRATE // Reduce the storage (may be recovered in /restore() if excessive)
else
outputting = FALSE
if(output_used < 0.0001) // either from no charge or set to 0
if(output_used < 0.0001) // Either from no charge or set to 0
outputting = FALSE
investigate_log("lost power and turned <font color='red'>off</font>", "singulo")
else if(output_attempt && charge > output_level && output_level > 0)
@@ -293,14 +299,13 @@
else
outputting = FALSE
// only update icon if state changed
if(last_disp != chargedisplay() || last_chrg != inputting || last_onln != outputting)
// Only update icon if state changed
if(last_disp != charge_display() || last_chrg != inputting || last_onln != outputting)
update_icon()
// called after all power processes are finished
// restores charge level to smes if there was excess this ptick
// Called after all power processes are finished
// Restores charge level to smes if there was excess this ptick
/obj/machinery/power/smes/proc/restore()
if(stat & BROKEN)
return
@@ -309,22 +314,22 @@
output_used = 0
return
var/excess = powernet.excess_power // this was how much wasn't used on the network last ptick, minus any removed by other SMESes
var/excess = powernet.excess_power // This was how much wasn't used on the network last ptick, minus any removed by other SMESes
excess = min(output_used, 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)
excess = min((capacity-charge)/SMESRATE, excess) // For safety, also limit recharge by space capacity of SMES (shouldn't happen)
// now recharge this amount
var/clev = chargedisplay()
var/clev = charge_display()
charge += excess * SMESRATE // restore unused power
powernet.excess_power -= excess // remove the excess from the powernet, so later SMESes don't try to use it
charge += excess * SMESRATE // Restore unused power
powernet.excess_power -= excess // Remove the excess from the powernet, so later SMESes don't try to use it
output_used -= excess
if(clev != chargedisplay()) //if needed updates the icons overlay
if(clev != charge_display()) // If needed updates the icons overlay
update_icon()
return
@@ -353,7 +358,7 @@
/obj/machinery/power/smes/ui_data(mob/user)
var/list/data = list(
"capacity" = capacity,
"capacityPercent" = round(100*charge/capacity, 0.1),
"capacityPercent" = round(100 * charge / capacity, 0.1),
"charge" = charge,
"inputAttempt" = input_attempt,
"inputting" = inputting,
@@ -420,32 +425,6 @@
/obj/machinery/power/smes/proc/log_smes(mob/user)
investigate_log("input/output; [input_level>output_level?"<font color='green'>":"<font color='red'>"][input_level]/[output_level]</font> | Charge: [charge] | Output-mode: [output_attempt?"<font color='green'>on</font>":"<font color='red'>off</font>"] | Input-mode: [input_attempt?"<font color='green'>auto</font>":"<font color='red'>off</font>"] by [user ? key_name(user) : "outside forces"]", "singulo")
/obj/machinery/power/smes/proc/ion_act()
if(is_station_level(src.z))
if(prob(1)) //explosion
for(var/mob/M in viewers(src))
M.show_message("<span class='warning'>[src] is making strange noises!</span>", 3, "<span class='warning'>You hear sizzling electronics.</span>", 2)
sleep(10*pick(4,5,6,7,10,14))
var/datum/effect_system/smoke_spread/smoke = new
smoke.set_up(3, FALSE, loc)
smoke.attach(src)
smoke.start()
explosion(src.loc, -1, 0, 1, 3, 1, 0)
qdel(src)
return
if(prob(15)) //Power drain
do_sparks(3, 1, src)
if(prob(50))
emp_act(1)
else
emp_act(2)
if(prob(5)) //smoke only
var/datum/effect_system/smoke_spread/smoke = new
smoke.set_up(3, FALSE, loc)
smoke.attach(src)
smoke.start()
/obj/machinery/power/smes/proc/inputting(do_input)
input_attempt = do_input
if(!input_attempt)
@@ -461,7 +440,7 @@
outputting(rand(0, 1))
output_level = rand(0, output_level_max)
input_level = rand(0, input_level_max)
charge -= 1e6/severity
charge -= 1e6 / severity
if(charge < 0)
charge = 0
update_icon()
@@ -483,6 +462,5 @@
..()
#undef SMESRATE
#undef SMESMAXCHARGELEVEL
#undef SMESMAXOUTPUT