Files
Bubberstation/code/modules/power/apc/apc_power_proc.dm
SkyratBot 153c5c0ca6 [MIRROR] Terminals will be on the same layer as their APC/SMES by default & Selecting a layer when constructing an APC terminal now works. [MDB IGNORE] (#22591)
* Terminals will be on the same layer as their APC/SMES by default & Selecting a layer when constructing an APC terminal now works. (#76784)

## About The Pull Request

Terminals built on APCs and SMES units using left click will now be on
the same layer as the machine they're being built for, instead of the
first layer.

They can still be built on other layers using right click and that
feature will now work for APCs, not just SMES units (it was seemingly
forgotten to actually use the argument of the make_terminal() function.)
## Why It's Good For The Game

It is far more intuitive this way, and makes building terminals
generally more convenient.
The fix in the case of APCs is good simply by virtue of being a fix.
## Changelog
🆑
qol: terminals built by left-clicking on SMES and APC units will now be
on the same layer as the machine.
fix: constructing a terminal on a specific layer with right-click now
works for APCs, not just SMES units
/🆑

* Terminals will be on the same layer as their APC/SMES by default & Selecting a layer when constructing an APC terminal now works.

---------

Co-authored-by: A miscellaneous Fern <80640114+FernandoJ8@users.noreply.github.com>
2023-07-19 15:29:48 -04:00

146 lines
5.2 KiB
Plaintext

/obj/machinery/power/apc/get_cell()
return cell
/obj/machinery/power/apc/connect_to_network()
//Override because the APC does not directly connect to the network; it goes through a terminal.
//The terminal is what the power computer looks for anyway.
if(terminal)
terminal.connect_to_network()
/obj/machinery/power/apc/proc/make_terminal(terminal_cable_layer = cable_layer)
// create a terminal object at the same position as original turf loc
// wires will attach to this
terminal = new/obj/machinery/power/terminal(loc)
terminal.cable_layer = terminal_cable_layer
terminal.setDir(dir)
terminal.master = src
/obj/machinery/power/apc/proc/toggle_nightshift_lights(mob/user)
if(low_power_nightshift_lights)
balloon_alert(user, "power is too low!")
return
if(last_nightshift_switch > world.time - 10 SECONDS) //~10 seconds between each toggle to prevent spamming
balloon_alert(user, "night breaker is cycling!")
return
last_nightshift_switch = world.time
set_nightshift(!nightshift_lights)
/obj/machinery/power/apc/proc/update()
if(operating && !shorted && !failure_timer)
area.power_light = (lighting > APC_CHANNEL_AUTO_OFF)
area.power_equip = (equipment > APC_CHANNEL_AUTO_OFF)
area.power_environ = (environ > APC_CHANNEL_AUTO_OFF)
playsound(src.loc, 'sound/machines/terminal_on.ogg', 50, FALSE)
else
area.power_light = FALSE
area.power_equip = FALSE
area.power_environ = FALSE
playsound(src.loc, 'sound/machines/terminal_off.ogg', 50, FALSE)
area.power_change()
/obj/machinery/power/apc/proc/toggle_breaker(mob/user)
if(!is_operational || failure_timer)
return
operating = !operating
if (user)
var/enabled_or_disabled = operating ? "enabled" : "disabled"
balloon_alert(user, "power [enabled_or_disabled]")
user.log_message("turned [enabled_or_disabled] the [src]", LOG_GAME)
add_hiddenprint(user)
update()
update_appearance()
/obj/machinery/power/apc/surplus()
if(terminal)
return terminal.surplus()
return 0
/obj/machinery/power/apc/add_load(amount)
if(terminal?.powernet)
terminal.add_load(amount)
/obj/machinery/power/apc/avail(amount)
if(terminal)
return terminal.avail(amount)
return 0
/**
* Returns the new status value for an APC channel.
*
* // val 0=off, 1=off(auto) 2=on 3=on(auto)
* // on 0=off, 1=on, 2=autooff
* TODO: Make this use bitflags instead. It should take at most three lines, but it's out of scope for now.
*
* Arguments:
* - val: The current status of the power channel.
* - [APC_CHANNEL_OFF]: The APCs channel has been manually set to off. This channel will not automatically change.
* - [APC_CHANNEL_AUTO_OFF]: The APCs channel is running on automatic and is currently off. Can be automatically set to [APC_CHANNEL_AUTO_ON].
* - [APC_CHANNEL_ON]: The APCs channel has been manually set to on. This will be automatically changed only if the APC runs completely out of power or is disabled.
* - [APC_CHANNEL_AUTO_ON]: The APCs channel is running on automatic and is currently on. Can be automatically set to [APC_CHANNEL_AUTO_OFF].
* - on: An enum dictating how to change the channel's status.
* - [AUTOSET_FORCE_OFF]: The APC forces the channel to turn off. This includes manually set channels.
* - [AUTOSET_ON]: The APC allows automatic channels to turn back on.
* - [AUTOSET_OFF]: The APC turns automatic channels off.
*/
/obj/machinery/power/apc/proc/autoset(val, on)
switch(on)
if(AUTOSET_FORCE_OFF)
if(val == APC_CHANNEL_ON) // if on, return off
return APC_CHANNEL_OFF
else if(val == APC_CHANNEL_AUTO_ON) // if auto-on, return auto-off
return APC_CHANNEL_AUTO_OFF
if(AUTOSET_ON)
if(val == APC_CHANNEL_AUTO_OFF) // if auto-off, return auto-on
return APC_CHANNEL_AUTO_ON
if(AUTOSET_OFF)
if(val == APC_CHANNEL_AUTO_ON) // if auto-on, return auto-off
return APC_CHANNEL_AUTO_OFF
return val
/**
* Used by external forces to set the APCs channel status's.
*
* Arguments:
* - val: The desired value of the subsystem:
* - 1: Manually sets the APCs channel to be [APC_CHANNEL_OFF].
* - 2: Manually sets the APCs channel to be [APC_CHANNEL_AUTO_ON]. If the APC doesn't have any power this defaults to [APC_CHANNEL_OFF] instead.
* - 3: Sets the APCs channel to be [APC_CHANNEL_AUTO_ON]. If the APC doesn't have enough power this defaults to [APC_CHANNEL_AUTO_OFF] instead.
*/
/obj/machinery/power/apc/proc/setsubsystem(val)
if(cell && cell.charge > 0)
return (val == 1) ? APC_CHANNEL_OFF : val
if(val == 3)
return APC_CHANNEL_AUTO_OFF
return APC_CHANNEL_OFF
/obj/machinery/power/apc/disconnect_terminal()
if(terminal)
terminal.master = null
terminal = null
/obj/machinery/power/apc/proc/energy_fail(duration)
for(var/obj/machinery/failing_machine in area.contents)
if(failing_machine.critical_machine)
return
for(var/mob/living/silicon/ai as anything in GLOB.ai_list)
if(get_area(ai) == area)
return
failure_timer = max(failure_timer, round(duration))
update()
queue_icon_update()
/obj/machinery/power/apc/proc/set_nightshift(on)
set waitfor = FALSE
if(low_power_nightshift_lights && !on)
return
if(nightshift_lights == on)
return //no change
nightshift_lights = on
for(var/obj/machinery/light/night_light in area)
if(night_light.nightshift_allowed)
night_light.nightshift_enabled = nightshift_lights
night_light.update(FALSE)
CHECK_TICK