Files
Bubberstation/code/datums/elements/attack_zone_randomiser.dm
T
SmArtKar 16aef3a2fd Completely refactors HUD element management and datumizes inventory HUDs (#95119)
## About The Pull Request

This is a port/revival of Kapu's
https://github.com/DaedalusDock/daedalusdock/pull/883
By god, please TM this for a while, as HUDs are rather volatile and I
might've missed something (also the original PR had harddel issues, so
we should probably be on the lookout for those)

Instead of being stored in a metric ton of separate variables, all HUD
elements are now kept in a ``key -> element`` assoc list, and separate
category lists have been turned into a single ``group_key -> list of
elements`` assoc list for easier management.
This massively simplifies HUD creation and management, and allows us to
sanely dynamically modify HUDs without having to keep track of our
elements ourselves (harddel fuel)

I've also noticed that plasma vessels had... interesting, to say the
least, way of managing their HUD and in humans were unable to display
it, which I've changed (the element itself is displayed below stamina in
non-aliens, as latter occupies the spot where you'd normally see it)
Also fixes a bunch of minor unlikely to occur issues with HUD not
updating when it should've sometimes.

## Why It's Good For The Game

The two most important results of this is that A) we can fix the issue
with items larger than 32x32 not displaying properly in inventories (in
a separate PR) and B) this paves the way for datumized inventory slots,
although that is a separate nightmare
Some of this code is also actually over a decade old, and is an absolute
nightmare to work with.

## Changelog
🆑
qol: Non-aliens with an implanted plasma vessel now see their plasma
level in their HUD instead of just the stat panel
refactor: Refactored the entirety of HUD management code, report if
anything breaks!
/🆑

---------

Co-authored-by: John Willard <53777086+JohnFulpWillard@users.noreply.github.com>
2026-04-02 15:20:55 -04:00

36 lines
1.6 KiB
Plaintext

/// Pick a random attack zone before you attack something
/datum/element/attack_zone_randomiser
element_flags = ELEMENT_BESPOKE
argument_hash_start_idx = 2
/// List of attack zones you can select, should be a subset of GLOB.all_body_zones
var/list/valid_attack_zones
/datum/element/attack_zone_randomiser/Attach(datum/target, list/valid_attack_zones = GLOB.all_body_zones)
. = ..()
if (!isliving(target))
return ELEMENT_INCOMPATIBLE
RegisterSignals(target, list(COMSIG_HOSTILE_PRE_ATTACKINGTARGET, COMSIG_LIVING_UNARMED_ATTACK), PROC_REF(randomise))
src.valid_attack_zones = valid_attack_zones
/datum/element/attack_zone_randomiser/Detach(datum/source)
UnregisterSignal(source, list (COMSIG_HOSTILE_PRE_ATTACKINGTARGET, COMSIG_LIVING_UNARMED_ATTACK))
return ..()
/// If we're attacking a carbon, pick a random defence zone
/datum/element/attack_zone_randomiser/proc/randomise(mob/living/source, atom/target)
SIGNAL_HANDLER
if (!iscarbon(target))
return
if (!isnull(source.mind) && !isnull(source.hud_used?.screen_objects[HUD_MOB_ZONE_SELECTOR]))
return
var/mob/living/living_target = target
var/list/blacklist_zones = GLOB.all_body_zones - valid_attack_zones
var/new_zone = living_target.get_random_valid_zone(blacklisted_parts = blacklist_zones, bypass_warning = TRUE)
if (isnull(new_zone))
new_zone = BODY_ZONE_CHEST
var/atom/movable/screen/zone_sel/zone_selector = source.hud_used?.screen_objects[HUD_MOB_ZONE_SELECTOR]
if (isnull(zone_selector))
source.zone_selected = new_zone
else
zone_selector.set_selected_zone(new_zone, source, should_log = FALSE)