Skip to content

Commit

Permalink
Allows mobs with no usable legs to walk if holding two canes
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMelbert committed Aug 11, 2024
1 parent e056293 commit 78c3fff
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 52 deletions.
4 changes: 4 additions & 0 deletions code/__DEFINES/dcs/signals/signals_mob/signals_mob_carbon.dm
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,7 @@

/// Sent at the very end of human character setup
#define COMSIG_HUMAN_CHARACTER_SETUP "after_human_setup"

/// from /datum/status_effect/limp/proc/check_step()
#define COMSIG_CARBON_LIMPING "mob_limp_check"
#define COMPONENT_CANCEL_LIMP (1<<0)
5 changes: 5 additions & 0 deletions code/__DEFINES/living.dm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
/// The trait that determines if someone has the robotic limb reattachment quirk.
#define TRAIT_ROBOTIC_LIMBATTACHMENT "trait_robotic_limbattachment"

/// Mob can walk despite having two disabled/missing legs so long as they have two of this trait.
/// Kind of jank, refactor at a later day when I can think of a better solution.
/// Just be sure to call update_limbless_locomotion() after applying / removal
#define TRAIT_NO_LEG_AID "no_leg_aid"

#define COLOR_BLOOD "#c90000"

// Used in ready menu anominity
Expand Down
3 changes: 3 additions & 0 deletions code/datums/status_effects/wound_effects.dm
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
if(!owner.client || owner.body_position == LYING_DOWN || !owner.has_gravity() || (owner.movement_type & (FLYING|FLOATING)) || forced || owner.buckled)
return

if(SEND_SIGNAL(owner, COMSIG_CARBON_LIMPING, (next_leg || right || left)) & COMPONENT_CANCEL_LIMP)
return

// less limping while we have determination still
var/determined_mod = owner.has_status_effect(/datum/status_effect/determined) ? 0.5 : 1

Expand Down
22 changes: 22 additions & 0 deletions code/game/objects/items/weaponry.dm
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,28 @@ for further reading, please see: https://github.com/tgstation/tgstation/pull/301
playsound(src, 'sound/weapons/batonextend.ogg', 50, TRUE)
return COMPONENT_NO_DEFAULT_MESSAGE

/obj/item/cane/crutch
name = "medical crutch"
desc = "A medical crutch used by people missing a leg. Not all that useful if you're missing both of them, though."
icon = 'icons/obj/weapons/staff.dmi'
icon_state = "crutch_med"
inhand_icon_state = "crutch_med"
lefthand_file = 'icons/mob/inhands/weapons/melee_lefthand.dmi'
righthand_file = 'icons/mob/inhands/weapons/melee_righthand.dmi'
force = 12
throwforce = 8
w_class = WEIGHT_CLASS_BULKY
custom_materials = list(/datum/material/iron = SMALL_MATERIAL_AMOUNT * 0.5)
attack_verb_continuous = list("bludgeons", "whacks", "thrashes")
attack_verb_simple = list("bludgeon", "whack", "thrash")

/obj/item/cane/crutch/wood
name = "wooden crutch"
desc = "A handmade crutch. Also makes a decent bludgeon if you need it."
icon_state = "crutch_wood"
inhand_icon_state = "crutch_wood"
custom_materials = list(/datum/material/wood = SMALL_MATERIAL_AMOUNT * 0.5)

/obj/item/staff
name = "wizard staff"
desc = "Apparently a staff used by the wizard."
Expand Down
39 changes: 6 additions & 33 deletions code/modules/mob/living/carbon/carbon_movement.dm
Original file line number Diff line number Diff line change
Expand Up @@ -33,52 +33,25 @@
has_momentum = FALSE
// NON-MODULE CHANGE END

/mob/living/carbon/set_usable_legs(new_value)
. = ..()
if(isnull(.))
return
if(. == 0)
if(usable_legs != 0) //From having no usable legs to having some.
REMOVE_TRAIT(src, TRAIT_FLOORED, LACKING_LOCOMOTION_APPENDAGES_TRAIT)
REMOVE_TRAIT(src, TRAIT_IMMOBILIZED, LACKING_LOCOMOTION_APPENDAGES_TRAIT)
else if(usable_legs == 0 && !(movement_type & (FLYING | FLOATING))) //From having usable legs to no longer having them.
ADD_TRAIT(src, TRAIT_FLOORED, LACKING_LOCOMOTION_APPENDAGES_TRAIT)
if(!usable_hands)
ADD_TRAIT(src, TRAIT_IMMOBILIZED, LACKING_LOCOMOTION_APPENDAGES_TRAIT)


// NON-MODULE CHANGE START
/mob/living/carbon/set_usable_hands(new_value)
. = ..()
if(isnull(.))
return
if(. == 0)
REMOVE_TRAIT(src, TRAIT_HANDS_BLOCKED, LACKING_MANIPULATION_APPENDAGES_TRAIT)
if(usable_hands != 0) //From having no usable hands to having some.
REMOVE_TRAIT(src, TRAIT_IMMOBILIZED, LACKING_LOCOMOTION_APPENDAGES_TRAIT)
else if(usable_hands == 0 && default_num_hands > 0) //From having usable hands to no longer having them.
ADD_TRAIT(src, TRAIT_HANDS_BLOCKED, LACKING_MANIPULATION_APPENDAGES_TRAIT)
if(!usable_legs && !(movement_type & (FLYING | FLOATING)))
ADD_TRAIT(src, TRAIT_IMMOBILIZED, LACKING_LOCOMOTION_APPENDAGES_TRAIT)

/mob/living/carbon/on_movement_type_flag_enabled(datum/source, flag, old_movement_type)
. = ..()
if(movement_type & (FLYING | FLOATING) && !(old_movement_type & (FLYING | FLOATING)))
remove_movespeed_modifier(/datum/movespeed_modifier/limbless)
remove_traits(list(TRAIT_FLOORED, TRAIT_IMMOBILIZED), LACKING_LOCOMOTION_APPENDAGES_TRAIT)
update_limbless_locomotion()
update_limbless_movespeed_mod()

/mob/living/carbon/on_movement_type_flag_disabled(datum/source, flag, old_movement_type)
. = ..()
if(old_movement_type & (FLYING | FLOATING) && !(movement_type & (FLYING | FLOATING)))
var/limbless_slowdown = 0
if(usable_legs < default_num_legs)
limbless_slowdown += (default_num_legs - usable_legs) * 3
if(!usable_legs)
ADD_TRAIT(src, TRAIT_FLOORED, LACKING_LOCOMOTION_APPENDAGES_TRAIT)
if(usable_hands < default_num_hands)
limbless_slowdown += (default_num_hands - usable_hands) * 3
if(!usable_hands)
ADD_TRAIT(src, TRAIT_IMMOBILIZED, LACKING_LOCOMOTION_APPENDAGES_TRAIT)
if(limbless_slowdown)
add_or_update_variable_movespeed_modifier(/datum/movespeed_modifier/limbless, multiplicative_slowdown = limbless_slowdown)
else
remove_movespeed_modifier(/datum/movespeed_modifier/limbless)
update_limbless_locomotion()
update_limbless_movespeed_mod()
// NON-MODULE CHANGE END
2 changes: 1 addition & 1 deletion code/modules/mob/living/carbon/human/examine.dm
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
damage_text = "limp and lifeless"
else
damage_text = (body_part.brute_dam >= body_part.burn_dam) ? body_part.heavy_brute_msg : body_part.heavy_burn_msg
msg += "<B>[capitalize(t_his)] [body_part.name] is [damage_text]!</B>\n"
msg += "<B>[capitalize(t_his)] [body_part.plaintext_zone] is [damage_text]!</B>\n"

//stores missing limbs
var/l_limbs_missing = 0
Expand Down
40 changes: 26 additions & 14 deletions code/modules/mob/living/living.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2269,6 +2269,7 @@ GLOBAL_LIST_EMPTY(fire_appearances)
num_legs = new_value


// NON-MODULE CHANGE START
///Proc to modify the value of usable_legs and hook behavior associated to this event.
/mob/living/proc/set_usable_legs(new_value)
if(usable_legs == new_value)
Expand All @@ -2277,19 +2278,23 @@ GLOBAL_LIST_EMPTY(fire_appearances)
stack_trace("[src] had set_usable_legs() called on them with a negative value!")
new_value = 0

. = usable_legs
var/old_value = usable_legs
usable_legs = new_value

if(new_value > .) // Gained leg usage.
update_limbless_locomotion()
update_limbless_movespeed_mod()

return old_value

/// Updates whether the mob is floored or immobilized based on how many limbs they have or are missing.
/mob/living/proc/update_limbless_locomotion()
if(usable_legs > 0 || (movement_type & (FLYING|FLOATING)) || COUNT_TRAIT_SOURCES(src, TRAIT_NO_LEG_AID) >= 2)
REMOVE_TRAIT(src, TRAIT_FLOORED, LACKING_LOCOMOTION_APPENDAGES_TRAIT)
REMOVE_TRAIT(src, TRAIT_IMMOBILIZED, LACKING_LOCOMOTION_APPENDAGES_TRAIT)
else if(!(movement_type & (FLYING | FLOATING))) //Lost leg usage, not flying.
if(!usable_legs)
ADD_TRAIT(src, TRAIT_FLOORED, LACKING_LOCOMOTION_APPENDAGES_TRAIT)
if(!usable_hands)
ADD_TRAIT(src, TRAIT_IMMOBILIZED, LACKING_LOCOMOTION_APPENDAGES_TRAIT)

update_limbless_movespeed_mod()
return
ADD_TRAIT(src, TRAIT_FLOORED, LACKING_LOCOMOTION_APPENDAGES_TRAIT)
if(usable_hands == 0)
ADD_TRAIT(src, TRAIT_IMMOBILIZED, LACKING_LOCOMOTION_APPENDAGES_TRAIT)

/// Updates the mob's movespeed based on how many limbs they have or are missing.
/mob/living/proc/update_limbless_movespeed_mod()
Expand All @@ -2305,6 +2310,7 @@ GLOBAL_LIST_EMPTY(fire_appearances)
add_or_update_variable_movespeed_modifier(/datum/movespeed_modifier/limbless, multiplicative_slowdown = limbless_slowdown)
else
remove_movespeed_modifier(/datum/movespeed_modifier/limbless)
// NON-MODULE CHANGE END

///Proc to modify the value of num_hands and hook behavior associated to this event.
/mob/living/proc/set_num_hands(new_value)
Expand All @@ -2314,18 +2320,24 @@ GLOBAL_LIST_EMPTY(fire_appearances)
num_hands = new_value


// NON-MODULE CHANGE START
///Proc to modify the value of usable_hands and hook behavior associated to this event.
/mob/living/proc/set_usable_hands(new_value)
if(usable_hands == new_value)
return
. = usable_hands
if(new_value < 0) // Sanity check
stack_trace("[src] had set_usable_hands() called on them with a negative value!")
new_value = 0

var/old_value = usable_hands
usable_hands = new_value

if(new_value > .) // Gained hand usage.
REMOVE_TRAIT(src, TRAIT_IMMOBILIZED, LACKING_LOCOMOTION_APPENDAGES_TRAIT)
else if(!(movement_type & (FLYING | FLOATING)) && !usable_hands && !usable_legs) //Lost a hand, not flying, no hands left, no legs.
ADD_TRAIT(src, TRAIT_IMMOBILIZED, LACKING_LOCOMOTION_APPENDAGES_TRAIT)
if(usable_legs < default_num_legs)
update_limbless_locomotion()
update_limbless_movespeed_mod()

return old_value
// NON-MODULE CHANGE END

/// Whether or not this mob will escape from storages while being picked up/held.
/mob/living/proc/will_escape_storage()
Expand Down
Binary file modified icons/mob/inhands/weapons/melee_lefthand.dmi
Binary file not shown.
Binary file modified icons/mob/inhands/weapons/melee_righthand.dmi
Binary file not shown.
Binary file modified icons/obj/weapons/staff.dmi
Binary file not shown.
35 changes: 31 additions & 4 deletions maplestation_modules/code/datums/components/limbless_aid.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,53 @@

var/obj/item/item_parent = parent
if(isliving(item_parent.loc))
var/mob/living/wearer = item_parent.loc
UnregisterSignal(wearer, COMSIG_LIVING_LIMBLESS_MOVESPEED_UPDATE)
wearer.update_limbless_movespeed_mod()
on_drop(item_parent, item_parent.loc)

/datum/component/limbless_aid/proc/on_equip(obj/item/source, mob/living/user, slot)
SIGNAL_HANDLER

if(!(slot & required_slot))
return

ADD_TRAIT(user, TRAIT_NO_LEG_AID, REF(src))
RegisterSignal(user, COMSIG_LIVING_LIMBLESS_MOVESPEED_UPDATE, PROC_REF(modify_movespeed), override = TRUE)
RegisterSignal(user, COMSIG_CARBON_LIMPING, PROC_REF(limp_check), override = TRUE)
user.update_limbless_locomotion()
user.update_limbless_movespeed_mod()

/datum/component/limbless_aid/proc/on_drop(obj/item/source, mob/living/user)
SIGNAL_HANDLER

REMOVE_TRAIT(user, TRAIT_NO_LEG_AID, REF(src))
UnregisterSignal(user, COMSIG_LIVING_LIMBLESS_MOVESPEED_UPDATE)
UnregisterSignal(user, COMSIG_CARBON_LIMPING)
user.update_limbless_locomotion()
user.update_limbless_movespeed_mod()

/datum/component/limbless_aid/proc/modify_movespeed(mob/living/source, list/modifiers)
SIGNAL_HANDLER

modifiers += movespeed_mod
var/obj/item/bodypart/leg = get_braced_leg(source)
if(isnull(leg) || leg.bodypart_disabled)
modifiers += movespeed_mod

/datum/component/limbless_aid/proc/limp_check(mob/living/source, obj/item/bodypart/next_leg)
SIGNAL_HANDLER

var/obj/item/bodypart/leg = get_braced_leg(source)
if(isnull(leg) || leg == next_leg)
return COMPONENT_CANCEL_LIMP

#define IS_RIGHT_ARM(index) (index % 2 == 0)

/// Checks what side the item is equipped on
/datum/component/limbless_aid/proc/get_braced_leg(mob/living/who)
if(required_slot & ITEM_SLOT_HANDS)
// note this is backwards intentionally:
// right arm braces the left leg, and left arm braces right leg
var/side = IS_RIGHT_ARM(who.get_held_index_of_item(parent)) ? BODY_ZONE_L_LEG : BODY_ZONE_R_LEG
return who.get_bodypart(side)

return null // unimplemented

#undef IS_RIGHT_ARM

0 comments on commit 78c3fff

Please sign in to comment.