Fixes bodypart movespeed modifiers (#76520)

## About The Pull Request


![image](https://github.com/tgstation/tgstation/assets/82850673/502a195b-b9d6-48fd-92a1-462e74a13ae0)
I am today's big loser

Fixes https://github.com/tgstation/tgstation/issues/76509 (partly)
This was caused by my goofy ass not using the correct proc for the
VARIABLE movespeed modifier that is the bodypart one.

Additionally slightly changes some bodypart code that bothered me by
using signals even though it was just... not really necessary? And kind
of confusing?

## Why It's Good For The Game

Bugs are bad they make you mad

## Changelog

🆑
fix: Bodyparts that should slow you down, will slow you down.
/🆑
This commit is contained in:
ChungusGamer666
2023-07-04 13:43:12 -03:00
committed by GitHub
parent 2aec1bc790
commit b09f982408
4 changed files with 27 additions and 33 deletions
+5 -18
View File
@@ -960,36 +960,23 @@
/// Creates body parts for this carbon completely from scratch.
/// Optionally takes a map of body zones to what type to instantiate instead of them.
/mob/living/carbon/proc/create_bodyparts(list/overrides)
var/l_arm_index_next = -1
var/r_arm_index_next = 0
for(var/obj/item/bodypart/bodypart_path as anything in bodyparts)
var/list/bodyparts_paths = bodyparts.Copy()
bodyparts = list()
for(var/obj/item/bodypart/bodypart_path as anything in bodyparts_paths)
var/real_body_part_path = overrides?[initial(bodypart_path.body_zone)] || bodypart_path
var/obj/item/bodypart/bodypart_instance = new real_body_part_path()
bodypart_instance.set_owner(src)
bodyparts.Remove(bodypart_path)
add_bodypart(bodypart_instance)
switch(bodypart_instance.body_part)
if(ARM_LEFT)
l_arm_index_next += 2
bodypart_instance.held_index = l_arm_index_next //1, 3, 5, 7...
on_added_hand(bodypart_instance, l_arm_index_next)
if(ARM_RIGHT)
r_arm_index_next += 2
bodypart_instance.held_index = r_arm_index_next //2, 4, 6, 8...
on_added_hand(bodypart_instance, r_arm_index_next)
/// Called when a new hand is added
/mob/living/carbon/proc/on_added_hand(obj/item/bodypart/arm/new_hand, hand_index)
if(hand_index > hand_bodyparts.len)
hand_bodyparts.len = hand_index
hand_bodyparts[hand_index] = new_hand
RegisterSignals(new_hand, list(COMSIG_QDELETING, COMSIG_BODYPART_REMOVED), PROC_REF(on_lost_hand))
/// Cleans up references to an arm when it is dismembered or deleted
/// Cleans up references to a hand when it is dismembered or deleted
/mob/living/carbon/proc/on_lost_hand(obj/item/bodypart/arm/lost_hand)
SIGNAL_HANDLER
hand_bodyparts[lost_hand.held_index] = null
UnregisterSignal(lost_hand, list(COMSIG_QDELETING, COMSIG_BODYPART_REMOVED))
///Proc to hook behavior on bodypart additions. Do not directly call. You're looking for [/obj/item/bodypart/proc/try_attach_limb()].
/mob/living/carbon/proc/add_bodypart(obj/item/bodypart/new_bodypart)
@@ -1028,7 +1015,7 @@
var/final_modification = 0
for(var/obj/item/bodypart/bodypart as anything in bodyparts)
final_modification += bodypart.speed_modifier
add_movespeed_modifier(/datum/movespeed_modifier/bodypart, final_modification)
add_or_update_variable_movespeed_modifier(/datum/movespeed_modifier/bodypart, update = TRUE, multiplicative_slowdown = final_modification)
/mob/living/carbon/proc/create_internal_organs()
for(var/obj/item/organ/internal/internal_organ in organs)
@@ -190,7 +190,8 @@ There are several things that need to be remembered:
var/mutable_appearance/gloves_overlay = gloves.build_worn_icon(default_layer = GLOVES_LAYER, default_icon_file = icon_file)
var/feature_y_offset = 0
for (var/obj/item/bodypart/arm/my_hand as anything in hand_bodyparts)
//needs to be typed, hand_bodyparts can have nulls
for (var/obj/item/bodypart/arm/my_hand in hand_bodyparts)
var/list/glove_offset = my_hand.worn_glove_offset?.get_offset()
if (glove_offset && (!feature_y_offset || glove_offset["y"] > feature_y_offset))
feature_y_offset = glove_offset["y"]
@@ -649,6 +649,15 @@
SEND_SIGNAL(src, COMSIG_BODYPART_CHANGED_OWNER, new_owner, old_owner)
var/needs_update_disabled = FALSE //Only really relevant if there's an owner
if(old_owner)
if(held_index)
old_owner.on_lost_hand(src)
if(old_owner.hud_used)
var/atom/movable/screen/inventory/hand/hand = old_owner.hud_used.hand_slots["[held_index]"]
if(hand)
hand.update_appearance()
old_owner.update_worn_gloves()
if(speed_modifier)
old_owner.update_bodypart_speed_modifier()
if(length(bodypart_traits))
old_owner.remove_traits(bodypart_traits, bodypart_trait_source)
if(initial(can_be_disabled))
@@ -664,6 +673,15 @@
))
UnregisterSignal(old_owner, COMSIG_ATOM_RESTYLE)
if(owner)
if(held_index)
owner.on_added_hand(src, held_index)
if(owner.hud_used)
var/atom/movable/screen/inventory/hand/hand = owner.hud_used.hand_slots["[held_index]"]
if(hand)
hand.update_appearance()
owner.update_worn_gloves()
if(speed_modifier)
owner.update_bodypart_speed_modifier()
if(length(bodypart_traits))
owner.add_traits(bodypart_traits, bodypart_trait_source)
if(initial(can_be_disabled))
@@ -92,11 +92,8 @@
SEND_SIGNAL(owner, COMSIG_CARBON_REMOVE_LIMB, src, dismembered)
SEND_SIGNAL(src, COMSIG_BODYPART_REMOVED, owner, dismembered)
update_limb(dropping_limb = TRUE)
//limb is out and about, it can't really be considered an implant
bodypart_flags &= ~BODYPART_IMPLANTED
bodypart_flags &= ~BODYPART_IMPLANTED //limb is out and about, it can't really be considered an implant
owner.remove_bodypart(src)
if(speed_modifier)
owner.update_bodypart_speed_modifier()
for(var/datum/wound/wound as anything in wounds)
wound.remove_wound(TRUE)
@@ -125,7 +122,7 @@
if(!special)
if(phantom_owner.dna)
for(var/datum/mutation/human/mutation as anything in phantom_owner.dna.mutations) //some mutations require having specific limbs to be kept.
if(mutation.limb_req && mutation.limb_req == body_zone)
if(mutation.limb_req && (mutation.limb_req == body_zone))
to_chat(phantom_owner, span_warning("You feel your [mutation] deactivating from the loss of your [body_zone]!"))
phantom_owner.dna.force_lose(mutation)
@@ -331,15 +328,6 @@
moveToNullspace()
set_owner(new_limb_owner)
new_limb_owner.add_bodypart(src)
if(held_index)
new_limb_owner.on_added_hand(src, held_index)
if(new_limb_owner.hud_used)
var/atom/movable/screen/inventory/hand/hand = new_limb_owner.hud_used.hand_slots["[held_index]"]
if(hand)
hand.update_appearance()
new_limb_owner.update_worn_gloves()
if(speed_modifier)
new_limb_owner.update_bodypart_speed_modifier()
if(special) //non conventional limb attachment
for(var/datum/surgery/attach_surgery as anything in new_limb_owner.surgeries) //if we had an ongoing surgery to attach a new limb, we stop it.