Files
Bubberstation/code/datums/components/pry_open_door.dm
san7890 a3451b7fe4 Makes "forced" opening and closing of doors way more sane (#73699)
## About The Pull Request

The gist is that people thought that this was a boolean value, which was
fucked up. It's not a boolean value, it accepts anything between 0 and
2. So, let's re-arrange the checks and framework, give it some
descriptive defines, just so people know what the fuck "2" actually
does. `DOOR_DEFAULT_CHECKS` (0) does stuff normally,
`DOOR_FORCED_CHECKS` 1 typically just checking if we aren't emagged shut
or something (i suppose it could happen), and `DOOR_BYPASS_CHECKS` (2)
means that we just get the fucking door open if it isn't physically
sealed shut/open somehow.

I don't know if `forced` has ever _been_ a boolean, but for some reason
people thought it was.

I also enforced boolean returns instead of passing back null. This did
not matter for close() but i think it's silly to have a TRUE/null
dichotomy so that was also touched up.
## Why It's Good For The Game

Much better to read, less confusing, less stupid. It's been irritating
me for a while now, so let's just implement it now. Had to make a few
awkward concessions in order to fit this into the current code
framework, but it should be a lot nicer. I also shuffled the order of
some code around because certain placements didn't make any sense (early
returns not being in the right spot for an early return).
## Changelog
Nothing that should concern players.
2023-03-07 11:24:44 +00:00

53 lines
2.0 KiB
Plaintext

/**
* Attached to a basic mob.
* Causes attacks on doors to attempt to open them.
*/
/datum/component/pry_open_door
/// Odds the attack opens the door
var/open_chance
/// Time it takes to open a door with force
var/force_wait
/datum/component/pry_open_door/Initialize(open_chance = 100, force_wait = 10 SECONDS)
. = ..()
if(!isbasicmob(parent))
return COMPONENT_INCOMPATIBLE
src.open_chance = open_chance
src.force_wait = force_wait
/datum/component/pry_open_door/RegisterWithParent()
RegisterSignal(parent, COMSIG_HOSTILE_POST_ATTACKINGTARGET, PROC_REF(hostile_attackingtarget))
/datum/component/pry_open_door/UnregisterFromParent()
UnregisterSignal(parent, COMSIG_HOSTILE_POST_ATTACKINGTARGET)
/datum/component/pry_open_door/proc/hostile_attackingtarget(mob/living/basic/attacker, atom/target, success)
SIGNAL_HANDLER
if(!success)
return
if(istype(target, /obj/machinery/door/airlock) && prob(open_chance))
var/obj/machinery/door/airlock/airlock_target = target
INVOKE_ASYNC(src, PROC_REF(open_door), attacker, airlock_target)
/datum/component/pry_open_door/proc/open_door(mob/living/basic/attacker, obj/machinery/door/airlock/airlock_target)
if(airlock_target.locked)
to_chat(attacker, span_warning("The airlock's bolts prevent it from being forced!"))
return
else if(!airlock_target.allowed(attacker) && airlock_target.hasPower())
attacker.visible_message(span_warning("We start forcing the [airlock_target] open."), \
span_hear("You hear a metal screeching sound."))
playsound(airlock_target, 'sound/machines/airlock_alien_prying.ogg', 100, TRUE)
if(!do_after(attacker, force_wait, airlock_target))
return
if(airlock_target.locked)
return
attacker.visible_message(span_warning("We force the [airlock_target] to open."))
airlock_target.open(BYPASS_DOOR_CHECKS)
else if(!airlock_target.hasPower())
attacker.visible_message(span_warning("We force the [airlock_target] to open."))
airlock_target.open(FORCING_DOOR_CHECKS)
else
airlock_target.open(DEFAULT_DOOR_CHECKS)