additional testing for sea serpent visibility

This commit is contained in:
Enno Rehling 2021-06-22 00:36:22 +02:00
parent 407de0db20
commit d9123b4491
3 changed files with 47 additions and 3 deletions

View File

@ -1218,7 +1218,9 @@ int invisible(const unit * target, const unit * viewer)
if (hidden > target->number) hidden = target->number; if (hidden > target->number) hidden = target->number;
if (viewer) { if (viewer) {
const resource_type *rtype = get_resourcetype(R_AMULET_OF_TRUE_SEEING); const resource_type *rtype = get_resourcetype(R_AMULET_OF_TRUE_SEEING);
hidden -= i_get(viewer->items, rtype->itype); if (rtype) {
hidden -= i_get(viewer->items, rtype->itype);
}
} }
} }
return hidden; return hidden;

View File

@ -4032,8 +4032,13 @@ static enum cansee_t cansee_ex(const unit *u, const region *r, const unit *targe
enum cansee_t result = CANSEE_HIDDEN; enum cansee_t result = CANSEE_HIDDEN;
if (rings >= target->number) { if (rings >= target->number) {
const resource_type *rtype = get_resourcetype(R_AMULET_OF_TRUE_SEEING); const resource_type *rtype = get_resourcetype(R_AMULET_OF_TRUE_SEEING);
int amulet = i_get(u->items, rtype->itype); if (rtype) {
if (amulet <= 0) { int amulet = i_get(u->items, rtype->itype);
if (amulet <= 0) {
return CANSEE_INVISIBLE;
}
}
else {
return CANSEE_INVISIBLE; return CANSEE_INVISIBLE;
} }
} }

View File

@ -1967,6 +1967,42 @@ static void test_cansee_sphere(CuTest *tc) {
test_teardown(); test_teardown();
} }
/**
* Hidden monsters are seen in oceans if they are big enough.
*/
static void test_cansee_monsters(CuTest *tc) {
unit *u, *u2;
race *rc;
const item_type *itype;
test_setup();
itype = test_create_itemtype("roi");
u = test_create_unit(test_create_faction(), test_create_ocean(0, 0));
u2 = test_create_unit(test_create_faction(), u->region);
rc = test_create_race("seaserpent");
rc->weight = 4999;
u_setrace(u2, rc);
CuAssertTrue(tc, cansee(u->faction, u->region, u2, 0));
CuAssertTrue(tc, cansee(u->faction, u->region, u2, 2));
set_level(u2, SK_STEALTH, 1);
CuAssertTrue(tc, !cansee(u->faction, u->region, u2, 0));
CuAssertTrue(tc, cansee(u->faction, u->region, u2, 1));
rc->weight = 5000;
/* no stealth for fatties at sea */
CuAssertTrue(tc, cansee(u->faction, u->region, u2, 0));
CuAssertTrue(tc, cansee(u->faction, u->region, u2, 1));
/* rings still work */
i_change(&u2->items, itype, 1);
CuAssertTrue(tc, !cansee(u->faction, u->region, u2, 0));
CuAssertTrue(tc, !cansee(u->faction, u->region, u2, 2));
test_teardown();
}
static void test_nmr_timeout(CuTest *tc) { static void test_nmr_timeout(CuTest *tc) {
test_setup(); test_setup();
CuAssertIntEquals(tc, 0, NMRTimeout()); CuAssertIntEquals(tc, 0, NMRTimeout());
@ -2439,6 +2475,7 @@ CuSuite *get_laws_suite(void)
SUITE_ADD_TEST(suite, test_cansee); SUITE_ADD_TEST(suite, test_cansee);
SUITE_ADD_TEST(suite, test_cansee_ring); SUITE_ADD_TEST(suite, test_cansee_ring);
SUITE_ADD_TEST(suite, test_cansee_sphere); SUITE_ADD_TEST(suite, test_cansee_sphere);
SUITE_ADD_TEST(suite, test_cansee_monsters);
SUITE_ADD_TEST(suite, test_nmr_timeout); SUITE_ADD_TEST(suite, test_nmr_timeout);
SUITE_ADD_TEST(suite, test_long_orders); SUITE_ADD_TEST(suite, test_long_orders);
SUITE_ADD_TEST(suite, test_long_order_on_ocean); SUITE_ADD_TEST(suite, test_long_order_on_ocean);