Files
Bubberstation/code/modules/unit_tests/weird_food.dm
T
JacquerelandGitHub 5dddedf340 Collected food fixes (#78190)
I went through the code and tried to find all of the remaining places we
forgot to update the arguments passed into `item/food/Initialize` after
more arguments were added to it, because there were a couple and they
caused things to stop working.
Most notably, golems were unable to eat anything because nothing would
correctly spawn "golem food".

_Additionally_ we were using a bunch of named arguments in new whenever
crafting or cooking food. This runtimed, causing the food not to init
properly.
_On top of that_ a late code review on a recent PR processed a list into
a string_assoc_list twice causing it to become null.

Finally, we were trying to check the food preferences of examining
ghosts or dogs or other non-human mobs. We shouldn't do that.

I also added a unit test for moth and golem food in the hopes that we'll
notice them breaking.
2023-09-09 12:39:42 +00:00

41 lines
2.1 KiB
Plaintext

/// Unit test to ensure that moths can eat t-shirts successfully
/datum/unit_test/moth_food
/datum/unit_test/moth_food/Run()
var/obj/item/clothing/suit/armor/bulletproof/light_snack = allocate(/obj/item/clothing/suit/armor/bulletproof)
light_snack.create_moth_snack()
var/datum/component/edible/eatability = light_snack.moth_snack.GetComponent(/datum/component/edible)
eatability.eat_time = 0
var/mob/living/carbon/human/species/moth/gourmet = allocate(/mob/living/carbon/human/species/moth)
gourmet.nutrition = 0 // We need to be sufficiently hungry
gourmet.put_in_active_hand(light_snack)
var/times_to_bite = round(light_snack.max_integrity / MOTH_EATING_CLOTHING_DAMAGE) + 1
for (var/i in 1 to times_to_bite)
TEST_ASSERT(!QDELETED(light_snack), "Moth finished eating clothes faster than expected.")
light_snack.attack(gourmet, gourmet)
TEST_ASSERT(QDELETED(light_snack), "Moth failed to finish eating clothing.")
/// Unit test to ensure that golems can eat rocks successfully
/datum/unit_test/golem_food
/datum/unit_test/golem_food/Run()
var/obj/item/stack/sheet/mineral/uranium/five/dinner = allocate(/obj/item/stack/sheet/mineral/uranium/five)
var/datum/component/golem_food/golem_food_data = dinner.GetComponent(/datum/component/golem_food)
golem_food_data.create_golem_snack(dinner)
var/datum/component/edible/eatability = golem_food_data.golem_snack.GetComponent(/datum/component/edible)
eatability.eat_time = 0
var/mob/living/carbon/human/species/golem/rock_enjoyer = allocate(/mob/living/carbon/human/species/golem)
rock_enjoyer.nutrition = 0 // We need to be sufficiently hungry
rock_enjoyer.put_in_active_hand(dinner)
var/status_applied = golem_food_data.snack_type.status_effect
var/times_to_bite = dinner.amount
for (var/i in 1 to times_to_bite)
TEST_ASSERT(!QDELETED(dinner), "Golem finished eating rocks faster than expected.")
dinner.attack(rock_enjoyer, rock_enjoyer)
TEST_ASSERT(QDELETED(dinner), "Golem failed to finish eating rocks.")
TEST_ASSERT(rock_enjoyer.has_status_effect(status_applied), "Golem didn't gain a food buff from eating its rocks.")