From 8e554e846d1fb1f2306d871f5ca67a0eb838cdaa Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Sat, 21 Nov 2020 07:31:04 +0100 Subject: [PATCH] [MIRROR] Unit tests for heretic knowledge (#1751) * Unit tests for heretic knowledge (#55022) * Unit tests for heretic knowledge Co-authored-by: EdgeLordExe <42111655+EdgeLordExe@users.noreply.github.com> --- code/__DEFINES/antagonists.dm | 3 +++ .../eldritch_cult/eldritch_antag.dm | 5 ++--- code/modules/unit_tests/_unit_tests.dm | 1 + code/modules/unit_tests/heretic_knowledge.dm | 21 +++++++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 code/modules/unit_tests/heretic_knowledge.dm diff --git a/code/__DEFINES/antagonists.dm b/code/__DEFINES/antagonists.dm index 7a92f6af2de..5a063b883a8 100644 --- a/code/__DEFINES/antagonists.dm +++ b/code/__DEFINES/antagonists.dm @@ -75,6 +75,9 @@ #define IS_HERETIC(mob) (mob.mind?.has_antag_datum(/datum/antagonist/heretic)) #define IS_HERETIC_MONSTER(mob) (mob.mind?.has_antag_datum(/datum/antagonist/heretic_monster)) +GLOBAL_LIST_INIT(heretic_start_knowledge,list(/datum/eldritch_knowledge/spell/basic,/datum/eldritch_knowledge/living_heart,/datum/eldritch_knowledge/codex_cicatrix)) + + #define PATH_SIDE "Side" #define PATH_ASH "Ash" diff --git a/code/modules/antagonists/eldritch_cult/eldritch_antag.dm b/code/modules/antagonists/eldritch_cult/eldritch_antag.dm index 811f92d4089..55aa959e843 100644 --- a/code/modules/antagonists/eldritch_cult/eldritch_antag.dm +++ b/code/modules/antagonists/eldritch_cult/eldritch_antag.dm @@ -32,9 +32,8 @@ var/mob/living/current = owner.current if(ishuman(current)) forge_primary_objectives() - gain_knowledge(/datum/eldritch_knowledge/spell/basic) - gain_knowledge(/datum/eldritch_knowledge/living_heart) - gain_knowledge(/datum/eldritch_knowledge/codex_cicatrix) + for(var/eldritch_knowledge in GLOB.heretic_start_knowledge) + gain_knowledge(eldritch_knowledge) current.log_message("has been converted to the cult of the forgotten ones!", LOG_ATTACK, color="#960000") GLOB.reality_smash_track.Generate() START_PROCESSING(SSprocessing,src) diff --git a/code/modules/unit_tests/_unit_tests.dm b/code/modules/unit_tests/_unit_tests.dm index a204fe67ccd..7d1e6ad37c6 100644 --- a/code/modules/unit_tests/_unit_tests.dm +++ b/code/modules/unit_tests/_unit_tests.dm @@ -29,6 +29,7 @@ #include "component_tests.dm" #include "confusion.dm" #include "emoting.dm" +#include "heretic_knowledge.dm" #include "keybinding_init.dm" #include "machine_disassembly.dm" #include "medical_wounds.dm" diff --git a/code/modules/unit_tests/heretic_knowledge.dm b/code/modules/unit_tests/heretic_knowledge.dm new file mode 100644 index 00000000000..a433bce1ec9 --- /dev/null +++ b/code/modules/unit_tests/heretic_knowledge.dm @@ -0,0 +1,21 @@ +/// This test checks all heretic knowledge nodes - excluding the ones which are unreachable on purpose - and ensures players can reach them in game. +/// If it finds a node that is unreachable, it throws an error. +/datum/unit_test/heretic_knowledge/Run() + ///List of all knowledge excluding the unreachable base types. + var/list/blacklist = list(/datum/eldritch_knowledge/spell,/datum/eldritch_knowledge/curse,/datum/eldritch_knowledge/final,/datum/eldritch_knowledge/summon) + var/list/all_possible_knowledge = subtypesof(/datum/eldritch_knowledge) - blacklist + + var/list/list_to_check = GLOB.heretic_start_knowledge.Copy() + var/i = 0 + while(i < length(list_to_check)) + var/datum/eldritch_knowledge/eldritch_knowledge = allocate(list_to_check[++i]) + for(var/next_knowledge in eldritch_knowledge.next_knowledge) + if(next_knowledge in list_to_check) + continue + list_to_check += next_knowledge + + if(length(all_possible_knowledge) != length(all_possible_knowledge & list_to_check)) + var/list/unreachables = all_possible_knowledge - list_to_check + for(var/X in unreachables) + var/datum/eldritch_knowledge/eldritch_knowledge = X + Fail("[initial(eldritch_knowledge.name)] is unreachable by players! Add it to the blacklist in /code/modules/unit_tests/heretic_knowledge.dm if it is purposeful!")