forked from github/server
lucky cats can survive a volcano
This commit is contained in:
parent
154e610423
commit
f9346f4332
|
@ -81,6 +81,7 @@ int volcano_damage(unit* u, const char* dice)
|
||||||
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;
|
int healings = 0;
|
||||||
|
const struct race* rc_cat = get_race(RC_CAT);
|
||||||
|
|
||||||
/* does this unit have any healing potions or effects? */
|
/* does this unit have any healing potions or effects? */
|
||||||
if (oldpotiontype[P_HEAL]) {
|
if (oldpotiontype[P_HEAL]) {
|
||||||
|
@ -99,7 +100,12 @@ int volcano_damage(unit* u, const char* dice)
|
||||||
int h = hp + ((i < remain) ? 1 : 0);
|
int h = hp + ((i < remain) ? 1 : 0);
|
||||||
|
|
||||||
if (damage >= h) {
|
if (damage >= h) {
|
||||||
if (healings > 0) {
|
if (rc_cat && u_race(u) == rc_cat && ((rng_int() % 7) == 0)) {
|
||||||
|
/* cats have nine lives */
|
||||||
|
total += h;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (healings > 0) {
|
||||||
--healings;
|
--healings;
|
||||||
if (resurrect_unit(u)) {
|
if (resurrect_unit(u)) {
|
||||||
/* take no damage at all */
|
/* take no damage at all */
|
||||||
|
|
|
@ -76,6 +76,29 @@ static void test_volcano_damage_armor(CuTest* tc) {
|
||||||
test_teardown();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_volcano_damage_cats(CuTest* tc) {
|
||||||
|
unit* u;
|
||||||
|
struct race* rc_cat;
|
||||||
|
|
||||||
|
test_setup();
|
||||||
|
rc_cat = test_create_race("cat");
|
||||||
|
u = test_create_unit(test_create_faction_ex(rc_cat, NULL), test_create_plain(0, 0));
|
||||||
|
scale_number(u, 100);
|
||||||
|
|
||||||
|
random_source_inject_constants(0.0, 0); /* cats are always lucky */
|
||||||
|
u->hp = u->number * 10;
|
||||||
|
CuAssertIntEquals(tc, 0, volcano_damage(u, "10"));
|
||||||
|
CuAssertIntEquals(tc, 100, u->number);
|
||||||
|
CuAssertIntEquals(tc, 10 * u->number, u->hp);
|
||||||
|
|
||||||
|
random_source_inject_constants(0.0, 1); /* cats are never lucky */
|
||||||
|
CuAssertIntEquals(tc, 100, volcano_damage(u, "10"));
|
||||||
|
CuAssertIntEquals(tc, 0, u->number);
|
||||||
|
CuAssertIntEquals(tc, 0, u->hp);
|
||||||
|
|
||||||
|
test_teardown();
|
||||||
|
}
|
||||||
|
|
||||||
static void test_volcano_damage_healing_potions(CuTest* tc) {
|
static void test_volcano_damage_healing_potions(CuTest* tc) {
|
||||||
unit* u;
|
unit* u;
|
||||||
item_type* itype;
|
item_type* itype;
|
||||||
|
@ -162,6 +185,7 @@ CuSuite *get_volcano_suite(void)
|
||||||
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_healing_potions);
|
||||||
SUITE_ADD_TEST(suite, test_volcano_damage_armor);
|
SUITE_ADD_TEST(suite, test_volcano_damage_armor);
|
||||||
|
SUITE_ADD_TEST(suite, test_volcano_damage_cats);
|
||||||
SUITE_ADD_TEST(suite, test_volcano_outbreak);
|
SUITE_ADD_TEST(suite, test_volcano_outbreak);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue