Files
Bubberstation/code/modules/modular_computers/computers/machinery/modular_computer.dm
John Willard aaff861c90 pdas now use their cells more (#78580)
## About The Pull Request

So one aspect of PDAs that I quite liked previously was managing and
upgrading your power.
This was lost when all cell parts got removed, mostly, and now I'd like
to re-add it.
PDAs and Tablets now use more power each second it's on
Programs being active/idle now take charge too.
And all this now takes ``seconds_per_tick`` into account.

Screenshots of APC use before and after having 6 programs open at once

![image](https://github.com/tgstation/tgstation/assets/53777086/14699ae7-19a7-4eb6-a211-5944cc1867d0)

![image](https://github.com/tgstation/tgstation/assets/53777086/804fedde-0d5a-43a9-9e61-34139257a16f)

PDA default power cells have a max charge of 1000, each cell use is
around ``1.00970340315`` power, which is ``1.01013789399`` w/ 2 programs
in idle and 1 active program (which is what PDAs are capable of). This
means it takes about 990 ticks to fully drain your power, or about 50
minutes, at max use.

This is completely blasted away the moment you put anything beyond a t1
cell inside of it, which is unfortunate but what can you do about tiered
parts being so poor.

The problem of no public PDA chargers are alleviated by
https://github.com/tgstation/tgstation/pull/78600

### Update

The PDA flashlight being on now also drains the battery 25% times
faster. PDA running out of charge now also turns the flashlight off.

## Why It's Good For The Game

You may or may not have to actually charge your PDA once in a round now,
maybe. I liked this part of tablets and would like to see it brought
back, managing your power to use your apps is important to ensure you're
not just using all apps 24/7

Because this also adds the functionality to add/remove power cells
again, it opens up to some minor little pranks/messing with people that
isn't completely destroying their tools, as well as some minor
upgradeability.

## Changelog

🆑
balance: You can now remove and replace power cells from PDAs (with
screwdriver).
balance: PDAs now drain their power cells harder, and also take into
account active programs & their flashlight being on.
balance: PDAs running out of charge now turn their flashlights off.
/🆑
2023-09-27 21:15:19 -04:00

176 lines
5.4 KiB
Plaintext

// Modular Computer - A machinery that is mostly just a host to the Modular Computer item.
/obj/machinery/modular_computer
name = "modular computer"
desc = "You shouldn't see this. If you do, report it." //they should be examining the processor instead
icon = 'icons/obj/machines/modular_console.dmi'
icon_state = "console"
idle_power_usage = BASE_MACHINE_IDLE_CONSUMPTION * 0.05
density = TRUE
max_integrity = 300
integrity_failure = 0.5
///The power cell, null by default as we use the APC we're in
var/internal_cell = null
///A flag that describes this device type
var/hardware_flag = PROGRAM_CONSOLE
/// Amount of programs that can be ran at once
var/max_idle_programs = 4
///Icon state when the computer is turned off.
var/icon_state_unpowered = "console-off"
///Icon state when the computer is turned on.
var/icon_state_powered = "console"
///Icon state overlay when the computer is turned on, but no program is loaded that would override the screen.
var/screen_icon_state_menu = "menu"
///Icon state overlay when the computer is powered, but not 'switched on'.
var/screen_icon_screensaver = "standby"
///Amount of steel sheets refunded when disassembling an empty frame of this computer.
var/steel_sheet_cost = 10
///Light luminosity when turned on
var/light_strength = 2
///Power usage when the computer is open (screen is active) and can be interacted with.
var/base_active_power_usage = 500
///Power usage when the computer is idle and screen is off (currently only applies to laptops)
var/base_idle_power_usage = 100
///CPU that handles most logic while this type only handles power and other specific things.
var/obj/item/modular_computer/processor/cpu
/obj/machinery/modular_computer/Initialize(mapload)
. = ..()
cpu = new(src)
cpu.screen_on = TRUE
update_appearance()
/obj/machinery/modular_computer/Destroy()
QDEL_NULL(cpu)
return ..()
/obj/machinery/modular_computer/examine(mob/user)
if(cpu)
return cpu.examine(user)
return ..()
/obj/machinery/modular_computer/attack_ghost(mob/dead/observer/user)
. = ..()
if(.)
return
if(cpu)
cpu.attack_ghost(user)
/obj/machinery/modular_computer/emag_act(mob/user, obj/item/card/emag/emag_card)
if(!cpu)
balloon_alert(user, "turn it on first!")
return FALSE
return cpu.emag_act(user)
/obj/machinery/modular_computer/update_appearance(updates)
. = ..()
set_light(cpu?.enabled ? light_strength : 0)
/obj/machinery/modular_computer/update_icon_state()
if(!cpu || !cpu.enabled || (machine_stat & NOPOWER))
icon_state = icon_state_unpowered
else
icon_state = icon_state_powered
return ..()
/obj/machinery/modular_computer/update_overlays()
. = ..()
if(!cpu)
return .
if(cpu.enabled)
. += cpu.active_program?.program_icon_state || screen_icon_state_menu
else if(!(machine_stat & NOPOWER))
. += screen_icon_screensaver
if(cpu.get_integrity() <= cpu.integrity_failure * cpu.max_integrity)
. += "bsod"
. += "broken"
return .
/// Eats the "source" arg because update_icon actually expects args now.
/obj/machinery/modular_computer/proc/relay_icon_update(datum/source, updates, updated)
SIGNAL_HANDLER
return update_icon(updates)
/obj/machinery/modular_computer/AltClick(mob/user)
. = ..()
if(!can_interact(user))
return
if(cpu)
cpu.AltClick(user)
//ATTACK HAND IGNORING PARENT RETURN VALUE
// On-click handling. Turns on the computer if it's off and opens the GUI.
/obj/machinery/modular_computer/interact(mob/user)
if(cpu)
return cpu.interact(user)
return ..()
// Modular computers can have battery in them, we handle power in previous proc, so prevent this from messing it up for us.
/obj/machinery/modular_computer/power_change()
if(cpu?.use_power()) // If it still has a power source, PC wouldn't go offline.
set_machine_stat(machine_stat & ~NOPOWER)
update_appearance()
return
return ..()
/obj/machinery/modular_computer/screwdriver_act(mob/user, obj/item/tool)
if(cpu)
return cpu.screwdriver_act(user, tool)
return ..()
/obj/machinery/modular_computer/wrench_act_secondary(mob/user, obj/item/tool)
if(cpu)
return cpu.wrench_act_secondary(user, tool)
return ..()
/obj/machinery/modular_computer/welder_act(mob/user, obj/item/tool)
if(cpu)
return cpu.welder_act(user, tool)
return ..()
/obj/machinery/modular_computer/attackby(obj/item/W as obj, mob/living/user)
if (cpu && !user.combat_mode && !(flags_1 & NODECONSTRUCT_1))
return cpu.attackby(W, user)
return ..()
/obj/machinery/modular_computer/attacked_by(obj/item/attacking_item, mob/living/user)
if (cpu)
return cpu.attacked_by(attacking_item, user)
return ..()
// Stronger explosions cause serious damage to internal components
// Minor explosions are mostly mitigitated by casing.
/obj/machinery/modular_computer/ex_act(severity)
if(!cpu)
return ..()
switch(severity)
if(EXPLODE_DEVASTATE)
SSexplosions.high_mov_atom += cpu
if(EXPLODE_HEAVY)
SSexplosions.med_mov_atom += cpu
if(EXPLODE_LIGHT)
SSexplosions.low_mov_atom += cpu
return ..()
// EMPs are similar to explosions, but don't cause physical damage to the casing. Instead they screw up the components
/obj/machinery/modular_computer/emp_act(severity)
. = ..()
if(. & EMP_PROTECT_CONTENTS)
return
if(cpu)
cpu.emp_act(severity)
// "Stun" weapons can cause minor damage to components (short-circuits?)
// "Burn" damage is equally strong against internal components and exterior casing
// "Brute" damage mostly damages the casing.
/obj/machinery/modular_computer/bullet_act(obj/projectile/Proj)
if(cpu)
return cpu.bullet_act(Proj)
return ..()