From fedd35a58f4e4041319b40fb3123cb2c9b7e86ab Mon Sep 17 00:00:00 2001 From: Leshana Date: Fri, 16 Jun 2017 16:29:09 -0400 Subject: [PATCH] Adds a unit test to make sure prey can breathe inside pred bellies. --- code/unit_tests/unit_test_vr.dm | 26 ++++++++++++++++ code/unit_tests/vore_tests_vr.dm | 51 ++++++++++++++++++++++++++++++++ vorestation.dme | 2 ++ 3 files changed, 79 insertions(+) create mode 100644 code/unit_tests/unit_test_vr.dm create mode 100644 code/unit_tests/vore_tests_vr.dm diff --git a/code/unit_tests/unit_test_vr.dm b/code/unit_tests/unit_test_vr.dm new file mode 100644 index 0000000000..ea4023d7b2 --- /dev/null +++ b/code/unit_tests/unit_test_vr.dm @@ -0,0 +1,26 @@ +// +// VOREStation extensions to unit test framework. +// + +/datum/unit_test + var/static/default_mobloc = null + +/datum/unit_test/proc/create_test_mob(var/turf/mobloc = null, var/mobtype = /mob/living/carbon/human, var/with_mind = FALSE) + if(isnull(mobloc)) + if(!default_mobloc) + for(var/turf/simulated/floor/tiled/T in world) + var/pressure = T.zone.air.return_pressure() + if(90 < pressure && pressure < 120) // Find a turf between 90 and 120 + default_mobloc = T + break + mobloc = default_mobloc + if(!mobloc) + fail("Unable to find a location to create test mob") + return 0 + + var/mob/living/carbon/human/H = new mobtype(mobloc) + + if(with_mind) + H.mind_initialize("TestKey[rand(0,10000)]") + + return H diff --git a/code/unit_tests/vore_tests_vr.dm b/code/unit_tests/vore_tests_vr.dm new file mode 100644 index 0000000000..e50c50b2fa --- /dev/null +++ b/code/unit_tests/vore_tests_vr.dm @@ -0,0 +1,51 @@ +/datum/unit_test/belly_nonsuffocation + name = "MOB: human mob does not suffocate in a belly" + var/startLifeTick + var/startOxyloss + var/endOxyloss + var/mob/living/carbon/human/pred + var/mob/living/carbon/human/prey + async = 1 + +/datum/unit_test/belly_nonsuffocation/start_test() + pred = create_test_mob() + if(!istype(pred)) + return 0 + prey = create_test_mob(pred.loc) + if(!istype(prey)) + return 0 + + return 1 + +/datum/unit_test/belly_nonsuffocation/check_result() + // Unfortuantely we need to wait for the pred's belly to initialize. (Currently after a spawn()) + if(!pred.vore_organs || !pred.vore_organs.len) + return 0 + // Now that pred belly exists, we can eat the prey. + if(prey.loc != pred) + if(!pred.vore_selected) + fail("[pred] has no vore_selected.") + return 1 + var/datum/belly/TB = pred.vore_organs[pred.vore_selected] + TB.nom_mob(prey) + if(prey.loc != pred) + fail("[TB].nom_mob([prey]) did not put prey inside [pred]") + return 1 + // Okay, we succeeded in eating them, now lets wait a bit + startLifeTick = pred.life_tick + startOxyloss = prey.getOxyLoss() + return 0 + + if(pred.life_tick < (startLifeTick + 10)) + return 0 // Wait for them to breathe a few times + + // Alright lets check it! + endOxyloss = prey.getOxyLoss() + if(startOxyloss < endOxyloss) + fail("Prey takes oxygen damage in a pred's belly! (Before: [startOxyloss]; after: [endOxyloss])") + else + pass("Prey is not taking oxygen damage in pred's belly. (Before: [startOxyloss]; after: [endOxyloss])") + + qdel(prey) + qdel(pred) + return 1 diff --git a/vorestation.dme b/vorestation.dme index 40a1283418..4acbdf4aa8 100644 --- a/vorestation.dme +++ b/vorestation.dme @@ -2496,6 +2496,8 @@ #include "code\unit_tests\mob_tests.dm" #include "code\unit_tests\research_tests.dm" #include "code\unit_tests\unit_test.dm" +#include "code\unit_tests\unit_test_vr.dm" +#include "code\unit_tests\vore_tests_vr.dm" #include "code\unit_tests\zas_tests.dm" #include "code\unit_tests\integrated_circuits\arithmetic.dm" #include "code\unit_tests\integrated_circuits\circuits.dm"