Files
Bubberstation/code/game/objects/structures/railings.dm
LemonInTheDark 6fcbce39cd Makes turfs persist their signals, uses this to optimize connect_loc (#59608)
* Makes turfs persist signals

* Splits connect_loc up into two elements, one for stuff that wishes to connect on behalf of something, and one for stuff that just wants to connect normally. Connecting on behalf of someone has a significant amount of overhead, so let's do this to keep things clear

* Converts all uses of connect_loc over to the new patterns

* Adds some comments, actually makes turfs persist signals

* There's no need to detach connect loc anymore, since all it does is unregister signals. Unregisters a signal from formorly decal'd turfs, and makes the changeturf signal persistance stuff actually work

* bro fuck documentation

* Changes from a var to a proc, prevents admemems and idiots

* Extra detail on why we do the copy post qdel
2021-06-22 23:12:34 -04:00

130 lines
3.9 KiB
Plaintext

/obj/structure/railing
name = "railing"
desc = "Basic railing meant to protect idiots like you from falling."
icon = 'icons/obj/fluff.dmi'
icon_state = "railing"
density = TRUE
anchored = TRUE
var/climbable = TRUE
///Initial direction of the railing.
var/ini_dir
/obj/structure/railing/corner //aesthetic corner sharp edges hurt oof ouch
icon_state = "railing_corner"
density = FALSE
climbable = FALSE
/obj/structure/railing/Initialize()
. = ..()
ini_dir = dir
if(climbable)
AddElement(/datum/element/climbable)
AddComponent(/datum/component/simple_rotation,ROTATION_ALTCLICK | ROTATION_CLOCKWISE | ROTATION_COUNTERCLOCKWISE | ROTATION_VERBS ,null,CALLBACK(src, .proc/can_be_rotated),CALLBACK(src,.proc/after_rotation))
init_connect_loc_element()
/obj/structure/railing/attackby(obj/item/I, mob/living/user, params)
..()
add_fingerprint(user)
if(I.tool_behaviour == TOOL_WELDER && !user.combat_mode)
if(obj_integrity < max_integrity)
if(!I.tool_start_check(user, amount=0))
return
to_chat(user, span_notice("You begin repairing [src]..."))
if(I.use_tool(src, user, 40, volume=50))
obj_integrity = max_integrity
to_chat(user, span_notice("You repair [src]."))
else
to_chat(user, span_warning("[src] is already in good condition!"))
return
/obj/structure/railing/wirecutter_act(mob/living/user, obj/item/I)
. = ..()
if(!anchored)
to_chat(user, span_warning("You cut apart the railing."))
I.play_tool_sound(src, 100)
deconstruct()
return TRUE
/obj/structure/railing/deconstruct(disassembled)
if(!(flags_1 & NODECONSTRUCT_1))
var/obj/item/stack/rods/rod = new /obj/item/stack/rods(drop_location(), 3)
transfer_fingerprints_to(rod)
return ..()
///Implements behaviour that makes it possible to unanchor the railing.
/obj/structure/railing/wrench_act(mob/living/user, obj/item/I)
. = ..()
if(flags_1&NODECONSTRUCT_1)
return
to_chat(user, span_notice("You begin to [anchored ? "unfasten the railing from":"fasten the railing to"] the floor..."))
if(I.use_tool(src, user, volume = 75, extra_checks = CALLBACK(src, .proc/check_anchored, anchored)))
set_anchored(!anchored)
to_chat(user, span_notice("You [anchored ? "fasten the railing to":"unfasten the railing from"] the floor."))
return TRUE
/obj/structure/railing/CanPass(atom/movable/mover, turf/target)
. = ..()
if(get_dir(loc, target) & dir)
var/checking = FLYING | FLOATING
return . || mover.throwing || mover.movement_type & checking
return TRUE
/obj/structure/railing/corner/CanPass()
..()
return TRUE
/obj/structure/railing/proc/init_connect_loc_element()
var/static/list/loc_connections = list(
COMSIG_ATOM_EXIT = .proc/on_exit,
)
AddElement(/datum/element/connect_loc, loc_connections)
/obj/structure/railing/proc/on_exit(datum/source, atom/movable/leaving, direction)
SIGNAL_HANDLER
if(!(direction & dir))
return
if (!density)
return
if (leaving.throwing)
return
if (leaving.movement_type & (PHASING | FLYING | FLOATING))
return
if (leaving.move_force >= MOVE_FORCE_EXTREMELY_STRONG)
return
leaving.Bump(src)
return COMPONENT_ATOM_BLOCK_EXIT
// Corner railings don't block anything, so they don't create the element.
/obj/structure/railing/corner/init_connect_loc_element()
return
/obj/structure/railing/proc/can_be_rotated(mob/user,rotation_type)
if(anchored)
to_chat(user, span_warning("[src] cannot be rotated while it is fastened to the floor!"))
return FALSE
var/target_dir = turn(dir, rotation_type == ROTATION_CLOCKWISE ? -90 : 90)
if(!valid_window_location(loc, target_dir, is_fulltile = FALSE)) //Expanded to include rails, as well!
to_chat(user, span_warning("[src] cannot be rotated in that direction!"))
return FALSE
return TRUE
/obj/structure/railing/proc/check_anchored(checked_anchored)
if(anchored == checked_anchored)
return TRUE
/obj/structure/railing/proc/after_rotation(mob/user,rotation_type)
add_fingerprint(user)