diff --git a/code/modules/unit_tests/_unit_tests.dm b/code/modules/unit_tests/_unit_tests.dm index 1ec215745cc..4d44b9ae0f0 100644 --- a/code/modules/unit_tests/_unit_tests.dm +++ b/code/modules/unit_tests/_unit_tests.dm @@ -127,6 +127,7 @@ #include "dcs_check_list_arguments.dm" #include "dcs_get_id_from_elements.dm" #include "designs.dm" +#include "dismemberment.dm" #include "door_access.dm" #include "dragon_expiration.dm" #include "drink_icons.dm" diff --git a/code/modules/unit_tests/dismemberment.dm b/code/modules/unit_tests/dismemberment.dm new file mode 100644 index 00000000000..d8ce43b960e --- /dev/null +++ b/code/modules/unit_tests/dismemberment.dm @@ -0,0 +1,38 @@ +/** + * Unit test to check that held items are dropped correctly when we are dismembered. + * + * Also tests for edge cases such as undroppable items. + */ +/datum/unit_test/dismemberment/Run() + var/mob/living/carbon/human/dummy = allocate(/mob/living/carbon/human/consistent) + + var/obj/item/testing_item = allocate(/obj/item/analyzer) + testing_item.name = "testing item" + + // Standard situation: We're holding a normal item and get dismembered. + test_item(dummy, testing_item) + + // Abnormal situation: We're holding an undroppable item and get dismembered. + ADD_TRAIT(testing_item, TRAIT_NODROP, TRAIT_GENERIC) + test_item(dummy, testing_item, status_text = "after applying TRAIT_NODROP to the testing item") + + +/datum/unit_test/dismemberment/proc/test_item(mob/living/carbon/human/dummy, obj/item/testing_item, status_text = "") + //Check both to make sure being the active hand doesn't make a difference. + dummy.put_in_l_hand(testing_item) + check_dismember(dummy, BODY_ZONE_L_ARM, status_text) + + dummy.put_in_r_hand(testing_item) + check_dismember(dummy, BODY_ZONE_R_ARM, status_text) + + +/datum/unit_test/dismemberment/proc/check_dismember(mob/living/carbon/human/dummy, which_arm, status_text) + var/obj/item/bodypart/dismembered_limb = dummy.get_bodypart(which_arm) + var/obj/item/held_item = dummy.get_item_for_held_index(dismembered_limb.held_index) + + dismembered_limb.dismember() + TEST_ASSERT(held_item in dummy.loc, "Dummy did not drop [held_item] when [dismembered_limb] was dismembered [status_text].") + // Clean up after ourselves + qdel(dismembered_limb) + dummy.fully_heal(HEAL_ALL) +