Files
Bubberstation/code/modules/assembly/timer.dm
Y0SH1M4S73R 90b67b0541 A Small Circuit Expansion: Wallmounts, Undertiles, and Wire Bundles (#89122)
## About The Pull Request

This PR adds several circuit features, and changes several
assembly-related features to make them a bit more logical in how they
work. Included are the following changes/additions:

- Assemblies and wires have been refactored with vars that describe
their behavior:
- Assemblies have an `assembly_behavior` bitflag instead of a
`attachable` var. This var has 3 flags:
- `ASSEMBLY_INPUT`: The assembly is able to pulse the wire it is
attached to.
- `ASSEMBLY_TOGGLE_ARMED`: On activation, the assembly toggles whether
it can pulse the wire it is attached to.
- `ASSEMBLY_FUNCTIONAL_OUTPUT`: On activation, the assembly does
something other than just toggling whether it's armed.
  - Wires have a `wires_behavior` bitflag with 3 flags:
- `WIRES_INPUT`: The object the wires are attached to does something
when the wires are pulsed.
- `WIRES_TOGGLE_ARMED`: The object the wires are attached to can
activate assemblies attached to those wires, and is fine if all that
activating that assembly does is toggle whether it's armed.
- `WIRES_FUNCTIONAL_OUTPUT`: The object the wires are attached to
expects that assemblies attached to its wires do something other than
toggling themselves when activated.
- Buttons can only accept assemblies with `ASSEMBLY_FUNCTIONAL_OUTPUT`.
- Pressure plates can now accept any assembly with
`ASSEMBLY_FUNCTIONAL_OUTPUT`, not just signalers. Assembly shells
attached to pressure plates will draw power from the powernet if the
pressure plate is under a tile.
- Adds a new circuit component - the wire bundle.
- This component gives the circuit a number of wires corresponding to
the size of the shell.
- Each wire has a corresponding port on the component that can pulse,
and receive pulses from, that wire.
  - A circuit can only have one wire bundle component.
- Assembly shells cannot be attached to these wires, and no wires will
be created if the component is added to an assembly shell.
  - Available with roundstart tech.
- Adds two new shells.
- The wallmounted shell is a large shell that can be hung on walls, and
uses power from the area it's placed in.
    - Frame icon:

![image](https://github.com/user-attachments/assets/2fe9297d-44a9-4ceb-b803-a758e59b807d)
    - Constructed icon:

![image](https://github.com/user-attachments/assets/34c3ffcb-53cb-415f-952f-aec5de63cf17)
- The undertile shell is a small shell that only works when fit under a
floor tile, but uses power from the area it's placed in.

![image](https://github.com/user-attachments/assets/11ea150d-08be-4ce9-bf44-35a9d6e2d94f)
  - Both shells support usb cables.
- The above shells are available with the Advanced Shells techweb node.

## Why It's Good For The Game

The wire bundle component complements the functionality of the assembly
shell by allowing circuits to use assemblies directly in their logic.

The wallmounted and undertile shells provide ways of placing circuits
that don't necessarily take up space for machines. The undertile shell
is particularly useful for relaying usb component data over wirenets.

Pressure plates being able to accept assemblies other than signalers
expands their uses significantly.

## Changelog

🆑
refactor: Wires and assemblies have been refactored to have
directionality to them. This mostly makes it so that assemblies can only
be attached to wires it would make sense for them to be attached to.
qol: Pressure plates can now also accept igniters, condensers, flashes,
assembly shells, and door controllers.
add: Undertile circuit shells. They only work when placed under floor
tiles, but support USB cables and use APC power instead of cell power.
add: Wallmounted circuit shells. Large shells that support USB cables
and use APC power instead of cell power.
add: Wire bundle component. Adds a number of wires to the circuit
proportional to the capacity of the shell, allowing you to use
assemblies in circuit logic.
/🆑
2025-01-19 18:40:23 +00:00

135 lines
3.9 KiB
Plaintext

/obj/item/assembly/timer
name = "timer"
desc = "Used to time things. Works well with contraptions which has to count down. Tick tock."
icon_state = "timer"
custom_materials = list(/datum/material/iron=SMALL_MATERIAL_AMOUNT*5, /datum/material/glass=SMALL_MATERIAL_AMOUNT*0.5)
assembly_behavior = ASSEMBLY_TOGGLEABLE_INPUT
drop_sound = 'sound/items/handling/component_drop.ogg'
pickup_sound = 'sound/items/handling/component_pickup.ogg'
var/timing = FALSE
var/time = 10
var/saved_time = 10
var/loop = FALSE
var/hearing_range = 3
/obj/item/assembly/timer/suicide_act(mob/living/user)
user.visible_message(span_suicide("[user] looks at the timer and decides [user.p_their()] fate! It looks like [user.p_theyre()] going to commit suicide!"))
activate()//doesnt rely on timer_end to prevent weird metas where one person can control the timer and therefore someone's life. (maybe that should be how it works...)
addtimer(CALLBACK(src, PROC_REF(manual_suicide), user), time SECONDS)//kill yourself once the time runs out
return MANUAL_SUICIDE
/obj/item/assembly/timer/proc/manual_suicide(mob/living/user)
user.visible_message(span_suicide("[user]'s time is up!"))
user.adjustOxyLoss(200)
user.death(FALSE)
/obj/item/assembly/timer/Initialize(mapload)
. = ..()
START_PROCESSING(SSobj, src)
/obj/item/assembly/timer/Destroy()
STOP_PROCESSING(SSobj, src)
. = ..()
/obj/item/assembly/timer/examine(mob/user)
. = ..()
. += span_notice("The timer is [timing ? "counting down from [time]":"set for [time] seconds"].")
/obj/item/assembly/timer/activate()
if(!..())
return FALSE//Cooldown check
timing = !timing
update_appearance()
return TRUE
/obj/item/assembly/timer/toggle_secure()
secured = !secured
if(secured)
START_PROCESSING(SSobj, src)
else
timing = FALSE
STOP_PROCESSING(SSobj, src)
update_appearance()
return secured
/obj/item/assembly/timer/proc/timer_end()
if(secured && next_activate <= world.time)
pulse()
audible_message(span_infoplain("[icon2html(src, hearers(src))] *beep* *beep* *beep*"), null, hearing_range)
for(var/mob/hearing_mob in get_hearers_in_view(hearing_range, src))
hearing_mob.playsound_local(get_turf(src), 'sound/machines/beep/triple_beep.ogg', ASSEMBLY_BEEP_VOLUME, TRUE)
if(loop)
timing = TRUE
update_appearance()
/obj/item/assembly/timer/process(seconds_per_tick)
if(!timing)
return
time -= seconds_per_tick
if (time == 9 || time == 19 || time == 29)
update_appearance()
if(time <= 0)
timing = FALSE
timer_end()
time = saved_time
/obj/item/assembly/timer/update_appearance()
. = ..()
holder?.update_appearance()
/obj/item/assembly/timer/update_overlays()
. = ..()
attached_overlays = list()
if(!timing)
return
attached_overlays += "timer_timing"
for (var/i in 1 to clamp(ceil(time / 10), 1, 3))
var/mutable_appearance/timer_light = mutable_appearance(icon, "timer_light", layer, src)
timer_light.pixel_x = (i - 1) * 2
. += timer_light
/obj/item/assembly/timer/ui_status(mob/user, datum/ui_state/state)
if(is_secured(user))
return ..()
return UI_CLOSE
/obj/item/assembly/timer/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "Timer", name)
ui.open()
/obj/item/assembly/timer/ui_data(mob/user)
var/list/data = list()
data["seconds"] = round(time % 60)
data["minutes"] = round((time - data["seconds"]) / 60)
data["timing"] = timing
data["loop"] = loop
return data
/obj/item/assembly/timer/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()
if(.)
return
switch(action)
if("time")
timing = !timing
if(timing && istype(holder, /obj/item/transfer_valve))
log_bomber(usr, "activated a", src, "attachment on [holder]")
update_appearance()
. = TRUE
if("repeat")
loop = !loop
. = TRUE
if("input")
var/value = text2num(params["adjust"])
if(value)
value = round(time + value)
time = clamp(value, 1, 600)
saved_time = time
. = TRUE