Files
Bubberstation/code/modules/assembly/assembly.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

168 lines
5.3 KiB
Plaintext

/obj/item/assembly
name = "assembly"
desc = "A small electronic device that should never exist."
icon = 'icons/obj/devices/new_assemblies.dmi'
icon_state = ""
obj_flags = CONDUCTS_ELECTRICITY
w_class = WEIGHT_CLASS_SMALL
custom_materials = list(/datum/material/iron=SMALL_MATERIAL_AMOUNT)
throwforce = 2
throw_speed = 3
throw_range = 7
drop_sound = 'sound/items/handling/component_drop.ogg'
pickup_sound = 'sound/items/handling/component_pickup.ogg'
/**
* Set to true if the device has different icons for each position.
* This will prevent things such as visible lasers from facing the incorrect direction when transformed by assembly_holder's update_appearance()
*/
var/is_position_sensitive = FALSE
/// Flags related to this assembly. See [assemblies.dm]
var/assembly_flags = NONE
var/secured = TRUE
var/list/attached_overlays = null
var/obj/item/assembly_holder/holder = null
var/assembly_behavior = ASSEMBLY_FUNCTIONAL_OUTPUT // how does the assembly behave with respect to what it's connected to
var/datum/wires/connected = null
var/next_activate = 0 //When we're next allowed to activate - for spam control
/obj/item/assembly/Destroy()
holder = null
return ..()
/obj/item/assembly/get_part_rating()
return 1
/**
* on_attach: Called when attached to a holder, wiring datum, or other special assembly
*
* Will also be called if the assembly holder is attached to a plasma (internals) tank or welding fuel (dispenser) tank.
*/
/obj/item/assembly/proc/on_attach()
SHOULD_CALL_PARENT(TRUE)
if(!holder && connected)
holder = connected.holder
SEND_SIGNAL(src, COMSIG_ASSEMBLY_ATTACHED, holder)
/**
* on_detach: Called when removed from an assembly holder or wiring datum
*/
/obj/item/assembly/proc/on_detach()
SHOULD_CALL_PARENT(TRUE)
if(connected)
connected = null
if(!holder)
return FALSE
forceMove(holder.drop_location())
SEND_SIGNAL(src, COMSIG_ASSEMBLY_DETACHED, holder)
holder = null
return TRUE
/**
* holder_movement: Called when the assembly's holder detects movement
*/
/obj/item/assembly/proc/holder_movement()
if(!holder)
return FALSE
setDir(holder.dir)
return TRUE
/obj/item/assembly/proc/is_secured(mob/user)
if(!secured)
to_chat(user, span_warning("The [name] is unsecured!"))
return FALSE
return TRUE
/**
* Pulsed: This device was pulsed by another device
*
* * pulser: Who triggered the pulse
*/
/obj/item/assembly/proc/pulsed(mob/pulser)
INVOKE_ASYNC(src, PROC_REF(activate), pulser)
SEND_SIGNAL(src, COMSIG_ASSEMBLY_PULSED)
return TRUE
/**
* Pulse: This device is emitting a pulse to act on another device
*/
/obj/item/assembly/proc/pulse()
// if we have connected wires and are a pulsing assembly, pulse it
if(connected)
connected.pulse_assembly(src)
// otherwise if we're attached to a holder, process the activation of it with our flags
else if(holder)
holder.process_activation(src)
return TRUE
/// What the device does when turned on
/obj/item/assembly/proc/activate(mob/activator)
if(QDELETED(src) || !secured || (next_activate > world.time))
return FALSE
next_activate = world.time + 30
return TRUE
/obj/item/assembly/proc/toggle_secure()
secured = !secured
update_appearance()
return secured
// This is overwritten so that clumsy people can set off mousetraps even when in a holder.
// We are not going deeper than that however (won't set off if in a tank bomb or anything with wires)
// That would need to be added to all parent objects, or a signal created, whatever.
// Anyway this return check prevents you from picking up every assembly inside the holder at once.
/obj/item/assembly/attack_hand(mob/living/user, list/modifiers)
if(holder || connected)
return
. = ..()
/obj/item/assembly/attackby(obj/item/attacking_item, mob/user, params)
if(isassembly(attacking_item))
var/obj/item/assembly/new_assembly = attacking_item
// Check both our's and their's assembly flags to see if either should not duplicate
// If so, and we match types, don't create a holder - block it
if(((new_assembly.assembly_flags|assembly_flags) & ASSEMBLY_NO_DUPLICATES) && istype(new_assembly, type))
balloon_alert(user, "can't attach another of that!")
return
if(new_assembly.secured || secured)
balloon_alert(user, "both devices not assembly_behavior!")
return
holder = new /obj/item/assembly_holder(drop_location())
holder.assemble(src, new_assembly, user)
holder.balloon_alert(user, "parts combined")
return
if(istype(attacking_item, /obj/item/assembly_holder))
var/obj/item/assembly_holder/added_to_holder = attacking_item
added_to_holder.try_add_assembly(src, user)
return
return ..()
/obj/item/assembly/screwdriver_act(mob/living/user, obj/item/I)
if(..())
return TRUE
if(toggle_secure())
to_chat(user, span_notice("\The [src] is ready!"))
else
to_chat(user, span_notice("\The [src] can now be attached!"))
add_fingerprint(user)
return TRUE
/obj/item/assembly/examine(mob/user)
. = ..()
. += span_notice("\The [src] [secured? "is secured and ready to be used!" : "can be attached to other things."]")
/obj/item/assembly/ui_host(mob/user)
// In order, return:
// - The conencted wiring datum's owner, or
// - The thing your assembly holder is attached to, or
// - the assembly holder itself, or
// - us
return connected?.holder || holder?.master || holder || src
/obj/item/assembly/ui_state(mob/user)
return GLOB.hands_state