forked from github/server
buildings offer protection from volcano damage
This commit is contained in:
parent
5876c1a011
commit
5b7a3cba32
2 changed files with 40 additions and 1 deletions
|
@ -5,6 +5,7 @@
|
|||
#include "alchemy.h"
|
||||
|
||||
/* kernel includes */
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/messages.h>
|
||||
|
@ -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);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <attributes/reduceproduction.h>
|
||||
|
||||
#include <kernel/attrib.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/messages.h>
|
||||
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue