bring back healing potion effects

This commit is contained in:
Enno Rehling 2021-03-12 19:38:18 +01:00
parent b288a62542
commit 8dbe1b6bd3
2 changed files with 73 additions and 4 deletions

View File

@ -80,6 +80,13 @@ int volcano_damage(unit* u, const char* dice)
int hp = u->hp / u->number; int hp = u->hp / u->number;
int remain = u->hp % u->number; int remain = u->hp % u->number;
int ac, i, dead = 0, total = 0; 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) { for (i = 0; i != u->number; ++i) {
int damage = dice_rand(dice); int damage = dice_rand(dice);
@ -90,7 +97,17 @@ int volcano_damage(unit* u, const char* dice)
} }
if (damage > 0) { if (damage > 0) {
int h = hp + ((i < remain) ? 1 : 0); int h = hp + ((i < remain) ? 1 : 0);
bool heal = false;
if (damage >= h) { if (damage >= h) {
if (healings > 0) {
--healings;
if (resurrect_unit(u)) {
/* take no damage at all */
total += h;
continue;
}
}
++dead; ++dead;
} }
else { else {

View File

@ -1,16 +1,20 @@
#include <platform.h> #include <platform.h>
#include <tests.h> #include <tests.h>
#include "volcano.h" #include "volcano.h"
#include "alchemy.h"
#include <attributes/reduceproduction.h>
#include <kernel/attrib.h>
#include <kernel/faction.h> #include <kernel/faction.h>
#include <kernel/item.h>
#include <kernel/messages.h>
#include <kernel/region.h> #include <kernel/region.h>
#include <kernel/terrain.h> #include <kernel/terrain.h>
#include <kernel/unit.h> #include <kernel/unit.h>
#include <kernel/messages.h>
#include <kernel/attrib.h> #include <util/rand.h>
#include <util/rng.h>
#include <attributes/reduceproduction.h>
#include <CuTest.h> #include <CuTest.h>
@ -55,6 +59,52 @@ static void test_volcano_damage(CuTest* tc) {
test_teardown(); 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) { static void test_volcano_outbreak(CuTest *tc) {
region *r, *rn; region *r, *rn;
unit *u1, *u2; unit *u1, *u2;
@ -110,6 +160,8 @@ CuSuite *get_volcano_suite(void)
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_volcano_update); SUITE_ADD_TEST(suite, test_volcano_update);
SUITE_ADD_TEST(suite, test_volcano_damage); 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); SUITE_ADD_TEST(suite, test_volcano_outbreak);
return suite; return suite;
} }