Skip to content

Commit

Permalink
Fixing power consumption everywhere (#8517)
Browse files Browse the repository at this point in the history
* Turn the lights off

Everybody likes to get taken for turns
To see how bright the fire inside of us burns
And everybody wants to get evil tonight
But all good devils masquerade under the light

* Apply suggestions from code review

Totally forgot about this, thanks!

Co-authored-by: SirRichardFrancis <[email protected]>

---------

Co-authored-by: SirRichardFrancis <[email protected]>
  • Loading branch information
AltHit and SirRichardFrancis authored Sep 14, 2024
1 parent 709521b commit 207d817
Show file tree
Hide file tree
Showing 58 changed files with 179 additions and 134 deletions.
2 changes: 2 additions & 0 deletions code/game/machinery/OpTable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
/obj/machinery/optable/unbuckle_mob()
. = ..()
check_victim()
set_power_use(IDLE_POWER_USE)

/obj/machinery/optable/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)
if(air_group || (height==0)) return 1
Expand Down Expand Up @@ -83,6 +84,7 @@
O.loc = loc
add_fingerprint(user)
buckle_mob(C)
set_power_use(ACTIVE_POWER_USE)


/obj/machinery/optable/MouseDrop_T(mob/target, mob/user)
Expand Down
4 changes: 2 additions & 2 deletions code/game/machinery/Sleeper.dm
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
M.client.perspective = EYE_PERSPECTIVE
M.client.eye = src
M.forceMove(src)
update_use_power(2)
set_power_use(ACTIVE_POWER_USE)
occupant = M
update_icon()

Expand All @@ -205,7 +205,7 @@
if(A == beaker)
continue
A.forceMove(loc)
update_use_power(1)
set_power_use(IDLE_POWER_USE)
update_icon()
toggle_filter()

Expand Down
4 changes: 2 additions & 2 deletions code/game/machinery/adv_med.dm
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
src.occupant.forceMove(loc)
src.occupant.reset_view()
src.occupant = null
update_use_power(1)
set_power_use(IDLE_POWER_USE)
update_icon()

/obj/machinery/bodyscanner/AltClick(mob/user)
Expand All @@ -67,7 +67,7 @@
/obj/machinery/bodyscanner/proc/set_occupant(var/mob/living/L)
L.forceMove(src)
src.occupant = L
update_use_power(2)
set_power_use(ACTIVE_POWER_USE)
update_icon()
src.add_fingerprint(usr)

Expand Down
4 changes: 2 additions & 2 deletions code/game/machinery/alarm.dm
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,14 @@
if (!regulating_temperature)
//check for when we should start adjusting temperature
if(get_danger_level(environment.temperature, TLV["temperature"]) || abs(environment.temperature - target_temperature) > 2)
update_use_power(2)
set_power_use(ACTIVE_POWER_USE)
regulating_temperature = 1
visible_message("\The [src] clicks as it starts up.",\
"You hear a click and a faint electronic hum.")
else
//check for when we should stop adjusting temperature
if (!get_danger_level(environment.temperature, TLV["temperature"]) && abs(environment.temperature - target_temperature) <= 0.5)
update_use_power(1)
set_power_use(IDLE_POWER_USE)
regulating_temperature = 0
visible_message("\The [src] clicks quietly.",\
"You hear a click as a faint electronic humming stops.")
Expand Down
4 changes: 2 additions & 2 deletions code/game/machinery/antigrav.dm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
start_anim()

on = TRUE
use_power = ACTIVE_POWER_USE
set_power_use(ACTIVE_POWER_USE)
update_icon()

/obj/machinery/antigrav/examine(mob/user, extra_description = "")
Expand All @@ -53,7 +53,7 @@
stop_anim()

on = FALSE
use_power = IDLE_POWER_USE
set_power_use(IDLE_POWER_USE)
update_icon()

/obj/machinery/antigrav/Process()
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/atmoalter/scrubber.dm
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@

/obj/machinery/portable_atmospherics/powered/scrubber/huge/Process()
if(!on || (stat & (NOPOWER|BROKEN)))
update_use_power(0)
set_power_use(NO_POWER_USE)
last_flow_rate = 0
last_power_draw = 0
return 0
Expand Down
4 changes: 2 additions & 2 deletions code/game/machinery/autodoc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
occupant.unset_machine()
occupant = null
autodoc_processor.set_patient(null)
update_use_power(1)
set_power_use(IDLE_POWER_USE)
update_icon()

/obj/machinery/autodoc/proc/set_occupant(var/mob/living/L)
Expand All @@ -86,7 +86,7 @@
else
autodoc_processor.set_patient(L)
nano_ui_interact(L)
update_use_power(2)
set_power_use(ACTIVE_POWER_USE)
L.set_machine(src)
update_icon()

Expand Down
4 changes: 2 additions & 2 deletions code/game/machinery/autodoc_excelsior.dm
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
occupant.unset_machine()
occupant = null
autodoc_processor.set_patient(null)
update_use_power(1)
set_power_use(IDLE_POWER_USE)
update_icon()

/obj/machinery/excelsior_autodoc/proc/set_occupant(mob/living/user)
Expand All @@ -116,7 +116,7 @@
user.forceMove(src)
occupant = user
autodoc_processor.set_patient(user)
update_use_power(2)
set_power_use(ACTIVE_POWER_USE)
user.set_machine(src)
cover_state = image(icon, "opened")
cover_state.layer = 4.5
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/autolathe/autolathe.dm
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@
working = FALSE
next_file()

use_power = working ? ACTIVE_POWER_USE : IDLE_POWER_USE
set_power_use(working ? ACTIVE_POWER_USE : IDLE_POWER_USE)

special_process()
update_icon()
Expand Down
2 changes: 2 additions & 0 deletions code/game/machinery/autolathe_disk_cloner.dm
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@

/obj/machinery/autolathe_disk_cloner/proc/copy()
copying = TRUE
set_power_use(ACTIVE_POWER_USE)
SSnano.update_uis(src)
update_icon()
if(original && copy && !copy.used_capacity)
Expand Down Expand Up @@ -226,6 +227,7 @@
sleep(copying_delay)

copying = FALSE
set_power_use(IDLE_POWER_USE)
SSnano.update_uis(src)
update_icon()

Expand Down
4 changes: 2 additions & 2 deletions code/game/machinery/cryo.dm
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@
// occupant.metabslow = 0
occupant = null
current_heat_capacity = initial(current_heat_capacity)
update_use_power(1)
set_power_use(IDLE_POWER_USE)
update_icon()
return

Expand Down Expand Up @@ -310,7 +310,7 @@
to_chat(M, SPAN_NOTICE("<b>You feel a cold liquid surround you. Your skin starts to freeze up.</b>"))
occupant = M
current_heat_capacity = HEAT_CAPACITY_HUMAN
update_use_power(2)
set_power_use(ACTIVE_POWER_USE)
// M.metabslow = 1
add_fingerprint(usr)
update_icon()
Expand Down
29 changes: 21 additions & 8 deletions code/game/machinery/excelsior/boombox.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
icon_state = "boombox_off"
idle_power_usage = 10
active_power_usage = 60
use_power = TRUE
use_power = IDLE_POWER_USE
circuit = /obj/item/electronics/circuitboard/excelsior_boombox
var/active = FALSE
var/update_time = 0 // Made so callbacks can't be spamed
Expand All @@ -31,14 +31,27 @@
else
icon_state = "boombox_on"

/obj/machinery/excelsior_boombox/power_change()
..()
if(active && !powered())
toggle_active()
update_icon()

/obj/machinery/excelsior_boombox/proc/toggle_active()
if (active || (stat & (BROKEN|NOPOWER)))
active = FALSE
else
active = TRUE
if (world.time >= update_time + 30 SECONDS)
send_propaganda()
update_time = world.time
if (stat & (BROKEN|NOPOWER))
active = FALSE
set_power_use(NO_POWER_USE)
return FALSE
else if (active)
active = FALSE
set_power_use(IDLE_POWER_USE)
return FALSE
else
active = TRUE
set_power_use(ACTIVE_POWER_USE)
if (world.time >= update_time + 30 SECONDS)
send_propaganda()
update_time = world.time

/obj/machinery/excelsior_boombox/proc/send_propaganda()
if (active)
Expand Down
9 changes: 5 additions & 4 deletions code/game/machinery/floor_light.dm
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ var/list/floor_light_cache = list()
return

on = !on
if(on) use_power = ACTIVE_POWER_USE
if(on)
set_power_use(ACTIVE_POWER_USE)
visible_message("<span class='notice'>\The [user] turns \the [src] [on ? "on" : "off"].</span>")
update_brightness()
return
Expand All @@ -104,11 +105,11 @@ var/list/floor_light_cache = list()
..()
var/need_update
if((!anchored || broken()) && on)
use_power = NO_POWER_USE
set_power_use(NO_POWER_USE)
on = FALSE
need_update = 1
else if(use_power && !on)
use_power = NO_POWER_USE
set_power_use(NO_POWER_USE)
need_update = 1
if(need_update)
update_brightness()
Expand All @@ -118,7 +119,7 @@ var/list/floor_light_cache = list()
if(light_range != default_light_range || light_power != default_light_power || light_color != default_light_colour)
set_light(default_light_range, default_light_power, default_light_colour)
else
use_power = NO_POWER_USE
set_power_use(NO_POWER_USE)
if(light_range || light_power)
set_light(0)

Expand Down
7 changes: 3 additions & 4 deletions code/game/machinery/gym.dm
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@

/obj/machinery/gym/power_change()
..()
if(stat & BROKEN || stat & NOPOWER)
update_icon()
update_icon()

/obj/machinery/gym/emag_act(remaining_charges, mob/user, emag_source)
emagged = TRUE
Expand Down Expand Up @@ -72,7 +71,7 @@
occupant.unset_machine()
occupant = null

update_use_power(1)
set_power_use(IDLE_POWER_USE)
update_icon()

/obj/machinery/gym/attack_hand(mob/user)
Expand Down Expand Up @@ -100,7 +99,7 @@

user.forceMove(src)
occupant = user
update_use_power(2)
set_power_use(ACTIVE_POWER_USE)
user.set_machine(src)

add_fingerprint(user)
Expand Down
5 changes: 3 additions & 2 deletions code/game/machinery/holosign.dm
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@

/obj/machinery/holosign/proc/toggle()
if (stat & (BROKEN|NOPOWER))
set_power_use(NO_POWER_USE)
return
lit = !lit
use_power = lit ? 2 : 1
set_power_use(lit ? ACTIVE_POWER_USE : IDLE_POWER_USE)
update_icon()

/obj/machinery/holosign/update_icon()
Expand All @@ -41,7 +42,7 @@
/obj/machinery/holosign/power_change()
if (stat & NOPOWER)
lit = 0
use_power = NO_POWER_USE
set_power_use(NO_POWER_USE)
update_icon()

/obj/machinery/holosign/surgery
Expand Down
4 changes: 2 additions & 2 deletions code/game/machinery/jukebox.dm
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@

/obj/machinery/media/jukebox/proc/StopPlaying()
playing = 0
update_use_power(1)
set_power_use(IDLE_POWER_USE)
update_icon()
var/datum/component/atom_sanity/S = GetComponent(/datum/component/atom_sanity)
S.affect = 0
Expand All @@ -330,7 +330,7 @@
playing = 1
var/datum/component/atom_sanity/S = GetComponent(/datum/component/atom_sanity)
S.affect = sanity_value
update_use_power(2)
set_power_use(ACTIVE_POWER_USE)
update_icon()
start_stop_song()
updateDialog()
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/kitchen/microwave.dm
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@
icon = 'icons/obj/kitchen.dmi'
icon_state = "barrelfire"
desc = "A fire in an old barrel. Perfect for campouts in the far corners of the ship."
use_power = FALSE
use_power = NO_POWER_USE
idle_power_usage = 0
active_power_usage = 0
dinger = FALSE
Expand Down
6 changes: 5 additions & 1 deletion code/game/machinery/kitchen/smartfridge.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
anchored = TRUE
use_power = IDLE_POWER_USE
idle_power_usage = 5
active_power_usage = 100
active_power_usage = 250
reagent_flags = NO_REACT
var/global/max_n_of_items = 999 // Sorry but the BYOND infinite loop detector doesn't look things over 1000.
var/icon_on = "smartfridge"
Expand Down Expand Up @@ -292,6 +292,10 @@
/obj/machinery/smartfridge/power_change()
var/old_stat = stat
..()
if(powered())
set_power_use(ACTIVE_POWER_USE)
else
set_power_use(IDLE_POWER_USE)
if(old_stat != stat)
update_icon()

Expand Down
5 changes: 4 additions & 1 deletion code/game/machinery/machinery.dm
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@
set_dir(d)
GLOB.machines += src
InitCircuit()
power_change()
update_power_use()
START_PROCESSING(SSmachines, src)

return INITIALIZE_HINT_LATELOAD
Expand All @@ -142,7 +144,8 @@
return ..()

/obj/machinery/Process()//If you dont use process or power why are you here
return PROCESS_KILL
if(!(use_power || idle_power_usage || active_power_usage))
return PROCESS_KILL

/obj/machinery/emp_act(severity)
if(use_power && !stat)
Expand Down
4 changes: 2 additions & 2 deletions code/game/machinery/magnet.dm
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@

// Update power usage:
if(on)
use_power = ACTIVE_POWER_USE
active_power_usage = electricity_level*15
set_power_use(ACTIVE_POWER_USE)
else
use_power = NO_POWER_USE
set_power_use(NO_POWER_USE)


// Overload conditions:
Expand Down
4 changes: 2 additions & 2 deletions code/game/machinery/recharger.dm
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@

if(cell && !cell.fully_charged())
cell.give((active_power_usage*CELLRATE)*efficiency)
update_use_power(ACTIVE_POWER_USE)
set_power_use(ACTIVE_POWER_USE)
else
update_use_power(IDLE_POWER_USE)
set_power_use(IDLE_POWER_USE)
update_icon()

/obj/machinery/recharger/emp_act(severity)
Expand Down
Loading

0 comments on commit 207d817

Please sign in to comment.