diff --git a/src/volcano.c b/src/volcano.c index c8ebc7608..293b98fd5 100644 --- a/src/volcano.c +++ b/src/volcano.c @@ -5,6 +5,7 @@ #include "alchemy.h" /* kernel includes */ +#include #include #include #include @@ -82,6 +83,7 @@ int volcano_damage(unit* u, const char* dice) int ac, i, dead = 0, total = 0; int healings = 0; const struct race* rc_cat = get_race(RC_CAT); + int protect = inside_building(u) ? (building_protection(u->building) + 1) : 0; /* does this unit have any healing potions or effects? */ if (oldpotiontype[P_HEAL]) { @@ -90,7 +92,7 @@ int volcano_damage(unit* u, const char* dice) } for (i = 0; i != u->number; ++i) { - int damage = dice_rand(dice); + int damage = dice_rand(dice) - protect; if (damage > 0) { if (i == 0 || ac > 0) { ac = nb_armor(u, i); diff --git a/src/volcano.test.c b/src/volcano.test.c index 4818e59da..358dccd02 100644 --- a/src/volcano.test.c +++ b/src/volcano.test.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -76,6 +77,41 @@ static void test_volcano_damage_armor(CuTest* tc) { test_teardown(); } +static void test_volcano_damage_buildings(CuTest* tc) { + unit* u; + building_type* btype; + + test_setup(); + u = test_create_unit(test_create_faction(), test_create_plain(0, 0)); + scale_number(u, 100); + btype = test_create_castle(); + u->building = test_create_building(u->region, btype); + u->building->size = 100; /* Turm, 2 Punkte Bonus */ + u->hp = u->number * 10; + CuAssertIntEquals(tc, 0, volcano_damage(u, "10")); + CuAssertIntEquals(tc, 3 * u->number, u->hp); + + scale_number(u, 40); + u->hp = u->number * 10; + u->building->size = 40; /* Befestigung, 1 Punkt Bonus */ + CuAssertIntEquals(tc, 0, volcano_damage(u, "10")); + CuAssertIntEquals(tc, 40, u->number); + CuAssertIntEquals(tc, 2 * u->number, u->hp); + + btype->flags -= BTF_FORTIFICATION; /* regular buildings provide just 1 point total */ + u->hp = u->number * 10; + CuAssertIntEquals(tc, 0, volcano_damage(u, "10")); + CuAssertIntEquals(tc, u->number, u->hp); + + scale_number(u, 100); /* unit is to big for the building, everyone gets hurt */ + u->hp = u->number * 10; + CuAssertIntEquals(tc, 100, volcano_damage(u, "10")); + CuAssertIntEquals(tc, 0, u->number); + CuAssertIntEquals(tc, 0, u->hp); + + test_teardown(); +} + static void test_volcano_damage_cats(CuTest* tc) { unit* u; struct race* rc_cat; @@ -185,6 +221,7 @@ CuSuite *get_volcano_suite(void) 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_damage_buildings); SUITE_ADD_TEST(suite, test_volcano_damage_cats); SUITE_ADD_TEST(suite, test_volcano_outbreak); return suite;