Files
TimandGitHub 01534749dd Modular computers (PDAs) now shutdown when out of power (#96932)
## About The Pull Request

This PR refactors modular computers (PDAs) so that they actually respect
their power cells and shut down when they hit 0% charge.

Previously, PDA power mechanics were essentially non-functional. While
the flashlight would drain more power, it would never actually turn off
when the battery died. Additionally, there was broken code intended to
make the messenger program immune to power requirements. That immunity
code was so buggy that it made all the power mechanics get ignored.

To fix this, I gutted the broken immunity code. The marginal power draw
of the messenger program is so tiny that it doesn't need exceptions.
Now, when a modular computer runs out of power, everything, including
the flashlight, shuts off completely.

## Why It's Good For The Game

Right now, the power mechanics for modular computers are effectively
LARP that does nothing.

Players now have a tangible reason to conserve power and seek out
upgraded power cells if they plan on heavily utilizing their PDA's
features. It's balanced so that you'd have to be quite careless with the
flashlight to completely drain a standard battery. It adds consequence
without being overly punishing to the average crewmember.

## Changelog

🆑
balance: Modular computers (PDAs) now shutdown when out of power
fix: PDA flashlights now turn off when out of power
sound: Added a terminal off switch sound to PDAs when power runs out
/🆑
2026-07-16 16:04:44 +02:00

64 lines
2.2 KiB
Plaintext

///The multiplier given to the base overtime charge drain value if its flashlight is on.
#define FLASHLIGHT_DRAIN_MULTIPLIER 1.1
///Draws power from its rightful source (area if its a computer, the cell otherwise)
///Takes into account special cases, like silicon PDAs through override, and nopower apps.
/obj/item/modular_computer/proc/use_energy(amount = 0, check_programs = TRUE)
if(check_power_override(amount))
return TRUE
if(!internal_cell)
return FALSE
if(!amount || internal_cell.use(amount))
return TRUE
if(!check_programs)
return FALSE
INVOKE_ASYNC(src, PROC_REF(close_all_programs))
return FALSE
/obj/item/modular_computer/proc/give_power(amount)
if(internal_cell)
return internal_cell.give(amount)
return 0
///Shuts down the computer from powerloss.
/obj/item/modular_computer/proc/power_failure()
if(!enabled)
return
if(active_program)
active_program.event_powerfailure()
if(light_on)
set_light_on(FALSE)
for(var/datum/computer_file/program/programs as anything in idle_threads)
programs.event_powerfailure()
shutdown_computer()
///Takes the charge necessary from the Computer, shutting it off if it's unable to provide it.
///Charge depends on whether the PC is on, and what programs are running/idle on it.
/obj/item/modular_computer/proc/handle_power(seconds_per_tick)
var/power_usage = screen_on ? base_active_power_usage : base_idle_power_usage
if(light_on)
power_usage *= FLASHLIGHT_DRAIN_MULTIPLIER
if(active_program)
power_usage += active_program.power_cell_use
for(var/datum/computer_file/program/open_programs as anything in idle_threads)
if(!open_programs.power_cell_use)
continue
if(open_programs in idle_threads)
power_usage += (open_programs.power_cell_use / 2)
if(use_energy(power_usage * seconds_per_tick))
return TRUE
power_failure()
return FALSE
///Returns TRUE if the PC should not be using any power, FALSE otherwise.
/obj/item/modular_computer/proc/check_power_override(amount)
return !amount && !internal_cell?.charge
//Integrated (Silicon) tablets don't drain power, because the tablet is required to state laws, so it being disabled WILL cause problems.
/obj/item/modular_computer/pda/silicon/check_power_override()
return TRUE
#undef FLASHLIGHT_DRAIN_MULTIPLIER