Skip to content

Commit

Permalink
replaces auto_use_power() with static power calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Thera-Pissed committed Jan 12, 2024
1 parent 0e3d7bf commit 891e457
Show file tree
Hide file tree
Showing 23 changed files with 96 additions and 49 deletions.
4 changes: 2 additions & 2 deletions code/controllers/subsystem/machines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ SUBSYSTEM_DEF(machines)
var/obj/machinery/thing = currentrun[currentrun.len]
currentrun.len--
if(!QDELETED(thing) && thing.process(seconds) != PROCESS_KILL)
if(thing.use_power)
thing.auto_use_power() //add back the power state
//if(thing.use_power)
//thing.auto_use_power() //add back the power state
else
processing -= thing
if (!QDELETED(thing))
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 @@ -102,7 +102,7 @@
playsound(src, 'sound/machines/synth_yes.ogg', 50, TRUE, frequency = rand(5120, 8800))
target.apply_status_effect(STATUS_EFFECT_STASIS, STASIS_MACHINE_EFFECT)
target.ExtinguishMob()
use_power = ACTIVE_POWER_USE
set_active_power()

/obj/machinery/sleeper/proc/thaw_them(mob/living/target)
if(IS_IN_STASIS(target))
Expand All @@ -111,7 +111,7 @@

/obj/machinery/sleeper/process()
if(!occupant || !isliving(occupant))
use_power = IDLE_POWER_USE
set_idle_power()
return
var/mob/living/L_occupant = occupant
if(stasis_running())
Expand Down
30 changes: 29 additions & 1 deletion code/game/machinery/_machinery.dm
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Class Procs:
//0 = dont run the auto
//1 = run auto, use idle
//2 = run auto, use active
var/use_static_power = NO_POWER_USE
var/idle_power_usage = 0
var/active_power_usage = 0
var/power_channel = AREA_USAGE_EQUIP
Expand Down Expand Up @@ -151,7 +152,11 @@ Class Procs:

if(occupant_typecache)
occupant_typecache = typecacheof(occupant_typecache)

switch(use_power)
if(IDLE_POWER_USE)
set_idle_power()
if(ACTIVE_POWER_USE)
set_active_power()
return INITIALIZE_HINT_LATELOAD

/// Helper proc for telling a machine to start processing with the subsystem type that is located in its `subsystem_type` var.
Expand All @@ -175,6 +180,7 @@ Class Procs:
dropContents()
QDEL_NULL(circuit)
QDEL_LIST(component_parts)
set_no_power()
return ..()

/obj/machinery/proc/locate_machinery()
Expand Down Expand Up @@ -616,6 +622,7 @@ Class Procs:

//called on deconstruction before the final deletion
/obj/machinery/proc/on_deconstruction()
set_no_power()
return

/obj/machinery/proc/can_be_overridden()
Expand Down Expand Up @@ -651,3 +658,24 @@ Class Procs:
else if(clicksound)
playsound(src, clicksound, clickvol)
return

/obj/machinery/powertest
name = "powertest"
desc = "test."
icon = 'icons/obj/machines/autolathe.dmi'
icon_state = "autolathe"
use_power = IDLE_POWER_USE
idle_power_usage = IDLE_DRAW_LOW
active_power_usage = ACTIVE_DRAW_HIGH
power_channel = AREA_USAGE_EQUIP
var/on = FALSE

/obj/machinery/powertest/CtrlClick(mob/user)
if(can_interact(user))
on = !on
to_chat(usr, "<span class=\"alert\">[src] has changed setting!</span>")
if(on)
set_active_power()
else
set_idle_power()
return ..()
4 changes: 2 additions & 2 deletions code/game/machinery/autolathe.dm
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
use_power(power)
icon_state = "autolathe_n"
var/time = is_stack ? 32 : (32 * coeff * multiplier) ** 0.8
use_power = ACTIVE_POWER_USE
set_active_power()
addtimer(CALLBACK(src, PROC_REF(make_item), power, materials_used, custom_materials, multiplier, coeff, is_stack, usr), time)
. = TRUE
else
Expand Down Expand Up @@ -334,7 +334,7 @@
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
var/atom/A = drop_location()
use_power(power)
use_power = IDLE_POWER_USE
set_idle_power()

materials.use_materials(materials_used)

Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/porta_turret/portable_turret.dm
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ DEFINE_BITFIELD(turret_flags, list(
installation = null
max_integrity = 300
always_up = 1
use_power = ACTIVE_POWER_USE
set_active_power()

Check warning on line 797 in code/game/machinery/porta_turret/portable_turret.dm

View workflow job for this annotation

GitHub Actions / Run Linters

relatively pathed proc defined here
active_power_usage = 300
has_cover = 0
scan_range = 9
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 @@ -50,11 +50,11 @@
if (new_charging)
START_PROCESSING(SSmachines, src)
finished_recharging = FALSE
use_power = ACTIVE_POWER_USE
set_active_power()
using_power = TRUE
update_appearance()
else
use_power = IDLE_POWER_USE
set_idle_power()
using_power = FALSE
update_appearance()

Expand Down
4 changes: 2 additions & 2 deletions code/game/machinery/rechargestation.dm
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@

/obj/machinery/recharge_station/open_machine()
. = ..()
use_power = IDLE_POWER_USE
set_idle_power()

/obj/machinery/recharge_station/close_machine()
. = ..()
if(occupant)
use_power = ACTIVE_POWER_USE //It always tries to charge, even if it can't.
set_active_power() //It always tries to charge, even if it can't.
add_fingerprint(occupant)

/obj/machinery/recharge_station/update_icon_state()
Expand Down
4 changes: 2 additions & 2 deletions code/game/machinery/stasis.dm
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@
playsound(src, 'sound/effects/spray.ogg', 5, TRUE, 2, frequency = freq)
target.apply_status_effect(STATUS_EFFECT_STASIS, STASIS_MACHINE_EFFECT)
target.ExtinguishMob()
use_power = ACTIVE_POWER_USE
set_active_power()

/obj/machinery/stasis/proc/thaw_them(mob/living/target)
target.remove_status_effect(STATUS_EFFECT_STASIS, STASIS_MACHINE_EFFECT)
if(target == occupant)
use_power = IDLE_POWER_USE
set_idle_power()

/obj/machinery/stasis/post_buckle_mob(mob/living/L)
if(!can_be_occupant(L))
Expand Down
4 changes: 2 additions & 2 deletions code/game/mecha/mech_fabricator.dm
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@
rmat.silo_log(src, "built", -1, "[D.name]", res_coef)

add_overlay("fab-active")
use_power = ACTIVE_POWER_USE
set_active_power()
updateUsrDialog()
sleep(get_construction_time_w_coeff(D))
use_power = IDLE_POWER_USE
set_idle_power()
cut_overlay("fab-active")
desc = initial(desc)

Expand Down
4 changes: 2 additions & 2 deletions code/modules/NTNet/relays.dm
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@

/obj/machinery/ntnet_relay/process()
if(is_operational)
use_power = ACTIVE_POWER_USE
set_active_power()
else
use_power = IDLE_POWER_USE
set_idle_power()

update_appearance()

Expand Down
4 changes: 2 additions & 2 deletions code/modules/atmospherics/machinery/airalarm.dm
Original file line number Diff line number Diff line change
Expand Up @@ -753,14 +753,14 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/airalarm, 27)
visible_message("<span class='notice'>The air alarm makes a quiet click as it stops heating the area</span>")
playsound(src, 'sound/machines/terminal_off.ogg', 40)
heating_current_mode = "Idle"
use_power = IDLE_POWER_USE
set_idle_power()
return

if(wanted_mode == "Heat" & heating_current_mode == "Idle")
visible_message("<span class='notice'>The air alarm makes a quiet click as it starts heating the area</span>")
playsound(src, 'sound/machines/terminal_on.ogg', 40)
heating_current_mode = "Heat"
use_power = ACTIVE_POWER_USE
set_active_power()

if(heating_current_mode == "Heat")
var/temperature = environment.return_temperature()
Expand Down
4 changes: 2 additions & 2 deletions code/modules/awaymissions/gateway.dm
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ GLOBAL_LIST_EMPTY(gateway_destinations)
target = null
dest.deactivate(src)
QDEL_NULL(portal)
use_power = IDLE_POWER_USE
set_idle_power()
update_appearance()
portal_visuals.reset_visuals()

Expand All @@ -221,7 +221,7 @@ GLOBAL_LIST_EMPTY(gateway_destinations)
target.activate(destination)
portal_visuals.setup_visuals(target)
generate_bumper()
use_power = ACTIVE_POWER_USE
set_active_power()
update_appearance()

/obj/machinery/gateway/proc/Transfer(atom/movable/AM)
Expand Down
4 changes: 2 additions & 2 deletions code/modules/fishing/fishing_portal_machine.dm
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@

/obj/machinery/fishing_portal_generator/proc/activate()
active = AddComponent(/datum/component/fishing_spot, fishing_source)
use_power = ACTIVE_POWER_USE
set_active_power()
update_appearance()

/obj/machinery/fishing_portal_generator/proc/deactivate()
QDEL_NULL(active)
use_power = IDLE_POWER_USE
set_idle_power()
update_appearance()

/obj/machinery/fishing_portal_generator/on_set_is_operational(old_value)
Expand Down
4 changes: 2 additions & 2 deletions code/modules/food_and_drinks/kitchen_machinery/smartfridge.dm
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,10 @@
/obj/machinery/smartfridge/drying_rack/proc/toggle_drying(forceoff)
if(drying || forceoff)
drying = FALSE
use_power = IDLE_POWER_USE
set_idle_power()
else
drying = TRUE
use_power = ACTIVE_POWER_USE
set_active_power()
update_appearance()

/obj/machinery/smartfridge/drying_rack/proc/rack_dry()
Expand Down
8 changes: 4 additions & 4 deletions code/modules/hydroponics/hydroponics.dm
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@

if(!powered() && self_sustaining)
visible_message("<span class='warning'>[name]'s auto-grow functionality shuts off!</span>")
use_power = IDLE_POWER_USE
set_idle_power()
self_sustaining = FALSE
update_appearance()

Expand Down Expand Up @@ -685,9 +685,9 @@
return
self_sustaining = !self_sustaining
if(self_sustaining)
use_power = ACTIVE_POWER_USE
set_active_power()
else
use_power = IDLE_POWER_USE
set_idle_power()
to_chat(user, "<span class='notice'>You [self_sustaining ? "activate" : "deactivated"] [src]'s autogrow function[self_sustaining ? ", maintaining the tray's health while using high amounts of power" : ""].")
update_appearance()

Expand Down Expand Up @@ -718,7 +718,7 @@
desc = initial(desc)
TRAY_NAME_UPDATE
if(self_sustaining) //No reason to pay for an empty tray.
use_power = IDLE_POWER_USE
set_idle_power()
self_sustaining = FALSE
update_appearance()

Expand Down
2 changes: 1 addition & 1 deletion code/modules/overmap/missions/research_mission.dm
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
if(anchorvalue)
set_is_operational(TRUE)
START_PROCESSING(SSmachines, src)
use_power = IDLE_POWER_USE
set_idle_power()
else
set_is_operational(FALSE)
STOP_PROCESSING(SSmachines, src)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/power/lighting.dm
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/light/small/built, 28)
if(trigger)
burn_out()
else
use_power = ACTIVE_POWER_USE
set_active_power()
set_light(BR, PO, CO)
else if(has_emergency_power(LIGHT_EMERGENCY_POWER_USE) && !turned_off())
use_power = IDLE_POWER_USE
Expand Down
4 changes: 2 additions & 2 deletions code/modules/power/monitor.dm
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@

/obj/machinery/computer/monitor/process()
if(!get_powernet())
use_power = IDLE_POWER_USE
set_idle_power()
search()
else
use_power = ACTIVE_POWER_USE
set_active_power()
record()

/obj/machinery/computer/monitor/proc/search() //keep in sync with /datum/computer_file/program/power_monitor's version
Expand Down
19 changes: 19 additions & 0 deletions code/modules/power/power.dm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

/obj/machinery/power/Destroy()
disconnect_from_network()
set_no_power()
return ..()

///////////////////////////////
Expand Down Expand Up @@ -105,6 +106,24 @@
/obj/machinery/proc/removeStaticPower(value, powerchannel)
addStaticPower(-value, powerchannel)

/obj/machinery/proc/set_idle_power()
set_no_power()
use_static_power = IDLE_POWER_USE
addStaticPower(idle_power_usage, power_channel + 3)

/obj/machinery/proc/set_active_power()
set_no_power()
use_static_power = ACTIVE_POWER_USE
addStaticPower(active_power_usage, power_channel + 3)

/obj/machinery/proc/set_no_power()
switch(use_static_power)
if(IDLE_POWER_USE)
removeStaticPower(idle_power_usage, power_channel + 3)
if(ACTIVE_POWER_USE)
removeStaticPower(active_power_usage, power_channel + 3)
use_static_power = NO_POWER_USE

/**
* Called whenever the power settings of the containing area change
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
connected_parts.Cut()
return
if(!part_scan())
use_power = IDLE_POWER_USE
set_idle_power()
active = FALSE
connected_parts.Cut()

Expand Down Expand Up @@ -106,7 +106,7 @@
active = FALSE
use_power = NO_POWER_USE
else if(!machine_stat && construction_state == PA_CONSTRUCTION_COMPLETE)
use_power = IDLE_POWER_USE
set_idle_power()

/obj/machinery/particle_accelerator/control_box/process()
if(active)
Expand Down Expand Up @@ -175,14 +175,14 @@
message_admins("PA Control Computer turned [active ?"ON":"OFF"] by [usr ? ADMIN_LOOKUPFLW(usr) : "outside forces"] in [ADMIN_VERBOSEJMP(src)]")
log_game("PA Control Computer turned [active ?"ON":"OFF"] by [usr ? "[key_name(usr)]" : "outside forces"] at [AREACOORD(src)]")
if(active)
use_power = ACTIVE_POWER_USE
set_active_power()
for(var/CP in connected_parts)
var/obj/structure/particle_accelerator/part = CP
part.strength = strength
part.powered = TRUE
part.update_appearance()
else
use_power = IDLE_POWER_USE
set_idle_power()
for(var/CP in connected_parts)
var/obj/structure/particle_accelerator/part = CP
part.strength = null
Expand Down
Loading

0 comments on commit 891e457

Please sign in to comment.