diff --git a/code/modules/mob/living/carbon/human/inventory.dm b/code/modules/mob/living/carbon/human/inventory.dm index e717b93623a..83cc98ceec8 100644 --- a/code/modules/mob/living/carbon/human/inventory.dm +++ b/code/modules/mob/living/carbon/human/inventory.dm @@ -136,7 +136,15 @@ if (wear_suit && swap) wear_suit.dropped(src, TRUE) current_equip = wear_suit + wear_suit = I + + if (s_store && swap) + var/obj/item/s_store_backup = s_store + dropItemToGround(s_store_backup) + put_in_inactive_hand(s_store_backup) + equip_to_slot_if_possible(s_store_backup, ITEM_SLOT_SUITSTORE) + if(I.flags_inv & HIDEJUMPSUIT) update_inv_w_uniform() if(wear_suit.breakouttime) //when equipping a straightjacket diff --git a/code/modules/unit_tests/_unit_tests.dm b/code/modules/unit_tests/_unit_tests.dm index 3cd8587d99e..318d9f1bae3 100644 --- a/code/modules/unit_tests/_unit_tests.dm +++ b/code/modules/unit_tests/_unit_tests.dm @@ -8,7 +8,7 @@ /// Asserts that the two parameters passed are equal, fails otherwise /// Optionally allows an additional message in the case of a failure -#define TEST_ASSERT_EQUAL(a, b, message) if ((a) != (b)) { return Fail("Expected [a] to be equal to [b].[message ? " [message]" : ""]") } +#define TEST_ASSERT_EQUAL(a, b, message) if ((a) != (b)) { return Fail("Expected [isnull(a) ? "null" : a] to be equal to [isnull(b) ? "null" : b].[message ? " [message]" : ""]") } #include "anchored_mobs.dm" #include "bespoke_id.dm" @@ -23,6 +23,7 @@ #include "metabolizing.dm" #include "outfit_sanity.dm" #include "plantgrowth_tests.dm" +#include "quick_swap_sanity.dm" #include "reagent_id_typos.dm" #include "reagent_recipe_collisions.dm" #include "resist.dm" diff --git a/code/modules/unit_tests/quick_swap_sanity.dm b/code/modules/unit_tests/quick_swap_sanity.dm new file mode 100644 index 00000000000..85e73f9b6ae --- /dev/null +++ b/code/modules/unit_tests/quick_swap_sanity.dm @@ -0,0 +1,31 @@ +/// Test that quick swap correctly swaps items and invalidates suit storage +/datum/unit_test/quick_swap_sanity/Run() + // Create a human with a medical winter coat and a health analyzer in suit storage + var/mob/living/carbon/human/human = allocate(/mob/living/carbon/human) + + var/obj/item/coat = allocate(/obj/item/clothing/suit/hooded/wintercoat/medical) + TEST_ASSERT(human.equip_to_slot_if_possible(coat, ITEM_SLOT_OCLOTHING), "Couldn't equip winter coat") + + var/obj/item/analyzer = allocate(/obj/item/healthanalyzer) + TEST_ASSERT(human.equip_to_slot_if_possible(analyzer, ITEM_SLOT_SUITSTORE), "Couldn't equip health analyzer") + + // Then, have them quick swap between the coat and a space suit + var/obj/item/hardsuit = allocate(/obj/item/clothing/suit/space/hardsuit) + TEST_ASSERT(human.equip_to_appropriate_slot(hardsuit, swap = TRUE), "Couldn't quick swap to hardsuit") + + // Check if the human has the hardsuit on + TEST_ASSERT_EQUAL(human.wear_suit, hardsuit, "Human didn't equip the hardsuit") + + // Make sure the health analyzer was dropped as part of the swap + // Since health analyzers are an invalid suit storage item + TEST_ASSERT_EQUAL(human.s_store, null, "Human didn't drop the health analyzer") + + // Give the human an emergency oxygen tank + // This is valid suit storage for both the winter coat AND the hardsuit + var/obj/item/tank = allocate(/obj/item/tank/internals/emergency_oxygen) + TEST_ASSERT(human.equip_to_slot_if_possible(tank, ITEM_SLOT_SUITSTORE), "Couldn't equip emergency oxygen tank") + + // Now, quick swap back to the coat + // Since the tank is a valid suit storage item, it should not be dropped + TEST_ASSERT(human.equip_to_appropriate_slot(coat, swap = TRUE), "Couldn't quick swap to coat") + TEST_ASSERT_EQUAL(human.s_store, tank, "Human dropped the oxygen tank, when it was a valid item to keep in suit storage")