From dfbaf63d71c75eff9dd3c7c491caae7c37694f2b Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Mon, 13 Feb 2023 07:17:07 +0100 Subject: [PATCH] [MIRROR] Fix underlying armor logic and fix bug with constructed ripleys having zero armor [MDB IGNORE] (#19310) * Fix underlying armor logic and fix bug with constructed ripleys having zero armor (#73319) ## About The Pull Request See title ## Why It's Good For The Game Messed up one of the armor procs; it changed the given values but never carried over existing values. So you would end up with an armor of that one specific value and nothing else. This wasn't actually used anywhere other than mecha, lava burning, and sentient viruses, so the issue isn't that bad. It's still an issue however. ## Changelog :cl: fix: Mechs no longer have zero armor when built. /:cl: * Fix underlying armor logic and fix bug with constructed ripleys having zero armor --------- Co-authored-by: Zephyr <12817816+ZephyrTFA@users.noreply.github.com> --- code/datums/armor/_armor.dm | 8 ++--- code/modules/unit_tests/_unit_tests.dm | 1 + code/modules/unit_tests/armor_verification.dm | 33 +++++++++++++++++++ code/modules/vehicles/mecha/_mecha.dm | 2 +- 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 code/modules/unit_tests/armor_verification.dm diff --git a/code/datums/armor/_armor.dm b/code/datums/armor/_armor.dm index 82a882c0527..c6dbf1d5fdd 100644 --- a/code/datums/armor/_armor.dm +++ b/code/datums/armor/_armor.dm @@ -126,11 +126,11 @@ GLOBAL_LIST_INIT(armor_by_type, generate_armor_type_cache()) new_armor.vars[mod] = value_all return new_armor - for(var/value in values) - if(value in all_keys) - new_armor.vars[value] = values[value] + for(var/armor_rating in all_keys) + if(armor_rating in values) + new_armor.vars[armor_rating] = values[armor_rating] else - stack_trace("Attempt to call generate_new_with_specific with illegal value '[value]'! Ignoring it") + new_armor.vars[armor_rating] = vars[armor_rating] return new_armor /datum/armor/immune/generate_new_with_specific(list/values) diff --git a/code/modules/unit_tests/_unit_tests.dm b/code/modules/unit_tests/_unit_tests.dm index 73209b2505f..975c90f893d 100644 --- a/code/modules/unit_tests/_unit_tests.dm +++ b/code/modules/unit_tests/_unit_tests.dm @@ -83,6 +83,7 @@ #include "anchored_mobs.dm" #include "anonymous_themes.dm" #include "area_contents.dm" +#include "armor_verification.dm" #include "autowiki.dm" #include "barsigns.dm" #include "baseturfs.dm" diff --git a/code/modules/unit_tests/armor_verification.dm b/code/modules/unit_tests/armor_verification.dm new file mode 100644 index 00000000000..ef4613e49f1 --- /dev/null +++ b/code/modules/unit_tests/armor_verification.dm @@ -0,0 +1,33 @@ +/// Verifies that armor procs are working as expected +/datum/unit_test/armor_verification + +/datum/unit_test/armor_verification/Run() + var/obj/dummy = allocate(/obj) + + dummy.set_armor(/datum/armor/none) + var/datum/armor/armor = dummy.get_armor() + TEST_ASSERT_NOTNULL(armor, "armor didn't populate correctly when needed") + TEST_ASSERT_EQUAL(armor_totals(armor), 0, "none armor type had armor values") + + armor = armor.generate_new_with_specific(list(FIRE = 20)) + TEST_ASSERT_EQUAL(armor_totals(armor), 20, "modified armor type had incorrect values") + + armor = armor.generate_new_with_specific(list(ACID = 20)) + TEST_ASSERT_EQUAL(armor_totals(armor), 40, "modified armor type had incorrect values") + + armor = get_armor_by_type(/datum/armor/immune) + var/totals = armor_totals(armor) + armor = armor.generate_new_with_multipliers(list(ARMOR_ALL = 0)) + TEST_ASSERT_EQUAL(armor_totals(armor), totals, "modified an immune armor type") + + var/wanted = 40 + dummy.set_armor(/datum/armor/none) + dummy.set_armor_rating(ENERGY, wanted * 0.5) + dummy.set_armor_rating(FIRE, wanted * 0.5) + TEST_ASSERT_EQUAL(armor_totals(dummy.get_armor()), wanted, "modified armor type had incorrect values") + +/datum/unit_test/armor_verification/proc/armor_totals(datum/armor/armor) + var/total = 0 + for(var/key in ARMOR_LIST_ALL()) + total += armor.vars[key] + return total diff --git a/code/modules/vehicles/mecha/_mecha.dm b/code/modules/vehicles/mecha/_mecha.dm index 088dd0cb843..42b1a19879f 100644 --- a/code/modules/vehicles/mecha/_mecha.dm +++ b/code/modules/vehicles/mecha/_mecha.dm @@ -434,7 +434,7 @@ if(capacitor) var/datum/armor/stock_armor = get_armor_by_type(armor_type) var/initial_energy = stock_armor.get_rating(ENERGY) - set_armor_rating(initial_energy + (capacitor.rating * 5)) + set_armor_rating(ENERGY, initial_energy + (capacitor.rating * 5)) /obj/vehicle/sealed/mecha/examine(mob/user) . = ..()