From 8dbe1b6bd3af68b749f69ecbaff481baead77e1a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 12 Mar 2021 19:38:18 +0100 Subject: [PATCH] bring back healing potion effects --- src/volcano.c | 17 +++++++++++++ src/volcano.test.c | 60 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 73 insertions(+), 4 deletions(-) diff --git a/src/volcano.c b/src/volcano.c index 5ce69767c..cc9ba8f19 100644 --- a/src/volcano.c +++ b/src/volcano.c @@ -80,6 +80,13 @@ int volcano_damage(unit* u, const char* dice) int hp = u->hp / u->number; int remain = u->hp % u->number; int ac, i, dead = 0, total = 0; + int healings = 0; + + /* does this unit have any healing potions or effects? */ + if (oldpotiontype[P_HEAL]) { + healings = get_effect(u, oldpotiontype[P_HEAL]); + healings += i_get(u->items, oldpotiontype[P_HEAL]) * 4; + } for (i = 0; i != u->number; ++i) { int damage = dice_rand(dice); @@ -90,7 +97,17 @@ int volcano_damage(unit* u, const char* dice) } if (damage > 0) { int h = hp + ((i < remain) ? 1 : 0); + bool heal = false; + if (damage >= h) { + if (healings > 0) { + --healings; + if (resurrect_unit(u)) { + /* take no damage at all */ + total += h; + continue; + } + } ++dead; } else { diff --git a/src/volcano.test.c b/src/volcano.test.c index aa4edffbf..5b772f9d1 100644 --- a/src/volcano.test.c +++ b/src/volcano.test.c @@ -1,16 +1,20 @@ #include #include #include "volcano.h" +#include "alchemy.h" +#include + +#include #include +#include +#include #include #include #include -#include -#include - -#include +#include +#include #include @@ -55,6 +59,52 @@ static void test_volcano_damage(CuTest* tc) { test_teardown(); } +static void test_volcano_damage_armor(CuTest* tc) { + unit* u; + item_type* itype; + + test_setup(); + u = test_create_unit(test_create_faction(), test_create_plain(0, 0)); + scale_number(u, 100); + itype = test_create_itemtype("plate"); + new_armortype(itype, 0.0, frac_zero, 1, 0); + i_change(&u->items, itype, 50); + u->hp = u->number * 10; + CuAssertIntEquals(tc, 50, volcano_damage(u, "10")); + CuAssertIntEquals(tc, u->number, u->hp); + + test_teardown(); +} + +static void test_volcano_damage_healing_potions(CuTest* tc) { + unit* u; + item_type* itype; + + test_setup(); + u = test_create_unit(test_create_faction(), test_create_plain(0, 0)); + scale_number(u, 100); + itype = test_create_itemtype("healing"); + new_potiontype(itype, 1); + oldpotiontype[P_HEAL] = itype; + i_change(&u->items, itype, 50); /* saves up to 4 dead people each */ + + random_source_inject_constants(0.0, 1); /* potions always work */ + u->hp = u->number * 10; + CuAssertIntEquals(tc, 0, volcano_damage(u, "10")); + CuAssertIntEquals(tc, 100, u->number); + CuAssertIntEquals(tc, 10 * u->number, u->hp); + CuAssertIntEquals(tc, 25, i_get(u->items, itype)); + + random_source_inject_constants(0.0, 0); /* potions never work, everyone dies */ + u->hp = u->number * 10; + CuAssertIntEquals(tc, 100, volcano_damage(u, "10")); + CuAssertIntEquals(tc, 0, u->number); + CuAssertIntEquals(tc, 0, u->hp); + CuAssertIntEquals(tc, 0, i_get(u->items, itype)); + + test_teardown(); +} + static void test_volcano_outbreak(CuTest *tc) { region *r, *rn; unit *u1, *u2; @@ -110,6 +160,8 @@ CuSuite *get_volcano_suite(void) CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_volcano_update); SUITE_ADD_TEST(suite, test_volcano_damage); + SUITE_ADD_TEST(suite, test_volcano_damage_healing_potions); + SUITE_ADD_TEST(suite, test_volcano_damage_armor); SUITE_ADD_TEST(suite, test_volcano_outbreak); return suite; }