From d9123b44910d80d7014e4e537b7aa0629dc61b1b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 22 Jun 2021 00:36:22 +0200 Subject: [PATCH] additional testing for sea serpent visibility --- src/kernel/unit.c | 4 +++- src/laws.c | 9 +++++++-- src/laws.test.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 64ac33396..d7f14f073 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1218,7 +1218,9 @@ int invisible(const unit * target, const unit * viewer) if (hidden > target->number) hidden = target->number; if (viewer) { 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; diff --git a/src/laws.c b/src/laws.c index 8f30b3416..8ec30f194 100644 --- a/src/laws.c +++ b/src/laws.c @@ -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; if (rings >= target->number) { const resource_type *rtype = get_resourcetype(R_AMULET_OF_TRUE_SEEING); - int amulet = i_get(u->items, rtype->itype); - if (amulet <= 0) { + if (rtype) { + int amulet = i_get(u->items, rtype->itype); + if (amulet <= 0) { + return CANSEE_INVISIBLE; + } + } + else { return CANSEE_INVISIBLE; } } diff --git a/src/laws.test.c b/src/laws.test.c index 67ea499ce..ed66cc941 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -1967,6 +1967,42 @@ static void test_cansee_sphere(CuTest *tc) { 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) { test_setup(); 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_ring); 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_long_orders); SUITE_ADD_TEST(suite, test_long_order_on_ocean);