Files
Bubberstation/code/game/machinery/computer/_computer.dm
T
Tim a1ada2c9ef Refactor, improve, and rename canUseTopic to be can_perform_action (#73434)
This builds on what #69790 did and improved the code even further.
Notable things:
- `Topic()` is a deprecated proc in our codebase (replaced with
Javascript tgui) so it makes sense to rename `canUseTopic` to
`can_perform_action` which is more straightforward in what it does.
- Positional and named arguments have been converted into a easier to
use `action_bitflag`
- The bitflags adds some new checks you can use like: `NEED_GRAVITY |
NEED_LITERACY | NEED_LIGHT` when you want to perform an action.
- Redundant, duplicate, or dead code has been removed.
- Fixes several runtimes where `canUseTopic` was being called without a
proper target (IV drips, gibber, food processor)
- Better documentation for the proc and bitflags with examples
2023-02-16 20:22:14 -05:00

146 lines
4.2 KiB
Plaintext

/obj/machinery/computer
name = "computer"
icon = 'icons/obj/computer.dmi'
icon_state = "computer"
density = TRUE
max_integrity = 200
integrity_failure = 0.5
armor_type = /datum/armor/machinery_computer
interaction_flags_machine = INTERACT_MACHINE_ALLOW_SILICON|INTERACT_MACHINE_SET_MACHINE|INTERACT_MACHINE_REQUIRES_LITERACY
/// How bright we are when turned on.
var/brightness_on = 1
/// Icon_state of the keyboard overlay.
var/icon_keyboard = "generic_key"
/// Should we render an unique icon for the keyboard when off?
var/keyboard_change_icon = TRUE
/// Icon_state of the emissive screen overlay.
var/icon_screen = "generic"
/// Time it takes to deconstruct with a screwdriver.
var/time_to_unscrew = 2 SECONDS
/// Are we authenticated to use this? Used by things like comms console, security and medical data, and apc controller.
var/authenticated = FALSE
/datum/armor/machinery_computer
fire = 40
acid = 20
/obj/machinery/computer/Initialize(mapload, obj/item/circuitboard/C)
. = ..()
power_change()
/obj/machinery/computer/process()
if(machine_stat & (NOPOWER|BROKEN))
return FALSE
return TRUE
/obj/machinery/computer/update_overlays()
. = ..()
if(icon_keyboard)
if(keyboard_change_icon && (machine_stat & NOPOWER))
. += "[icon_keyboard]_off"
else
. += icon_keyboard
if(machine_stat & BROKEN)
. += mutable_appearance(icon, "[icon_state]_broken")
return // If we don't do this broken computers glow in the dark.
if(machine_stat & NOPOWER) // Your screen can't be on if you've got no damn charge
return
// This lets screens ignore lighting and be visible even in the darkest room
if(icon_screen)
. += mutable_appearance(icon, icon_screen)
. += emissive_appearance(icon, icon_screen, src)
/obj/machinery/computer/power_change()
. = ..()
if(machine_stat & NOPOWER)
set_light(0)
else
set_light(brightness_on)
/obj/machinery/computer/screwdriver_act(mob/living/user, obj/item/I)
if(..())
return TRUE
if(circuit && !(flags_1&NODECONSTRUCT_1))
to_chat(user, span_notice("You start to disconnect the monitor..."))
if(I.use_tool(src, user, time_to_unscrew, volume=50))
deconstruct(TRUE, user)
return TRUE
/obj/machinery/computer/play_attack_sound(damage_amount, damage_type = BRUTE, damage_flag = 0)
switch(damage_type)
if(BRUTE)
if(machine_stat & BROKEN)
playsound(src.loc, 'sound/effects/hit_on_shattered_glass.ogg', 70, TRUE)
else
playsound(src.loc, 'sound/effects/glasshit.ogg', 75, TRUE)
if(BURN)
playsound(src.loc, 'sound/items/welder.ogg', 100, TRUE)
/obj/machinery/computer/atom_break(damage_flag)
if(!circuit) //no circuit, no breaking
return
. = ..()
if(.)
playsound(loc, 'sound/effects/glassbr3.ogg', 100, TRUE)
set_light(0)
/obj/machinery/computer/emp_act(severity)
. = ..()
if (!(. & EMP_PROTECT_SELF))
switch(severity)
if(1)
if(prob(50))
atom_break(ENERGY)
if(2)
if(prob(10))
atom_break(ENERGY)
/obj/machinery/computer/deconstruct(disassembled = TRUE, mob/user)
on_deconstruction()
if(!(flags_1 & NODECONSTRUCT_1))
if(circuit) //no circuit, no computer frame
var/obj/structure/frame/computer/A = new /obj/structure/frame/computer(src.loc)
A.setDir(dir)
A.circuit = circuit
// Circuit removal code is handled in /obj/machinery/Exited()
circuit.forceMove(A)
A.set_anchored(TRUE)
if(machine_stat & BROKEN)
if(user)
to_chat(user, span_notice("The broken glass falls out."))
else
playsound(src, 'sound/effects/hit_on_shattered_glass.ogg', 70, TRUE)
new /obj/item/shard(drop_location())
new /obj/item/shard(drop_location())
A.state = 3
A.icon_state = "3"
else
if(user)
to_chat(user, span_notice("You disconnect the monitor."))
A.state = 4
A.icon_state = "4"
for(var/obj/C in src)
C.forceMove(loc)
qdel(src)
/obj/machinery/computer/AltClick(mob/user)
. = ..()
if(!can_interact(user))
return
if(!user.can_perform_action(src, ALLOW_SILICON_REACH) || !is_operational)
return
/obj/machinery/computer/ui_interact(mob/user, datum/tgui/ui)
SHOULD_CALL_PARENT(TRUE)
. = ..()
update_use_power(ACTIVE_POWER_USE)
/obj/machinery/computer/ui_close(mob/user)
SHOULD_CALL_PARENT(TRUE)
. = ..()
update_use_power(IDLE_POWER_USE)