From ca6cbe5906e748572a0eca19f21cc0fc1603113e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 13 Oct 2017 19:07:57 +0200 Subject: [PATCH] fixing commit 1b53128e1a and adding a test for cansee. --- src/laws.c | 2 +- src/laws.test.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/laws.c b/src/laws.c index 71309914a..6b27e7816 100644 --- a/src/laws.c +++ b/src/laws.c @@ -4311,7 +4311,7 @@ cansee(const faction * f, const region * r, const unit * u, int modifier, seen_m stealth = eff_stealth(u, r) - modifier; if (mode > seen_unit) { - return (rings <= 0 || stealth <= 0); + return (rings <= 0 && stealth <= 0); } else { unit *u2; diff --git a/src/laws.test.c b/src/laws.test.c index 537aadd57..87d5838b9 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -1581,6 +1581,7 @@ static void test_demon_hunger(CuTest * tc) static void test_cansee(CuTest *tc) { unit *u, *u2; + test_setup(); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); u2 = test_create_unit(test_create_faction(0), u->region); @@ -1589,9 +1590,45 @@ static void test_cansee(CuTest *tc) { set_level(u2, SK_STEALTH, 1); CuAssertTrue(tc, !cansee(u->faction, u->region, u2, 0, seen_unit)); + CuAssertTrue(tc, !cansee(u->faction, u->region, u2, 0, seen_spell)); + CuAssertTrue(tc, cansee(u->faction, u->region, u2, 1, seen_spell)); set_level(u, SK_PERCEPTION, 1); CuAssertTrue(tc, cansee(u->faction, u->region, u2, 0, seen_unit)); + CuAssertTrue(tc, !cansee(u->faction, u->region, u2, 0, seen_spell)); + + test_cleanup(); +} + +static void test_cansee_items(CuTest *tc) { + unit *u, *u2; + item_type *itype[3]; + + test_setup(); + u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); + u2 = test_create_unit(test_create_faction(0), u->region); + scale_number(u2, 2); + + itype[0] = test_create_itemtype("roi"); + itype[1] = test_create_itemtype("sphereofinv"); + itype[2] = test_create_itemtype("aots"); + CuAssertPtrNotNull(tc, get_resourcetype(R_RING_OF_INVISIBILITY)); + CuAssertPtrNotNull(tc, get_resourcetype(R_SPHERE_OF_INVISIBILITY)); + CuAssertPtrNotNull(tc, get_resourcetype(R_AMULET_OF_TRUE_SEEING)); + + CuAssertTrue(tc, cansee(u->faction, u->region, u2, 0, seen_unit)); + + i_change(&u2->items, itype[0], 1); + CuAssertTrue(tc, cansee(u->faction, u->region, u2, 0, seen_unit)); + CuAssertTrue(tc, !cansee(u->faction, u->region, u2, 0, seen_spell)); + + i_change(&u2->items, itype[0], 1); + CuAssertTrue(tc, !cansee(u->faction, u->region, u2, 0, seen_unit)); + CuAssertTrue(tc, !cansee(u->faction, u->region, u2, 0, seen_spell)); + + i_change(&u->items, itype[2], 1); + CuAssertTrue(tc, cansee(u->faction, u->region, u2, 0, seen_unit)); + CuAssertTrue(tc, !cansee(u->faction, u->region, u2, 0, seen_spell)); test_cleanup(); } @@ -1701,6 +1738,7 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_demon_hunger); SUITE_ADD_TEST(suite, test_armedmen); SUITE_ADD_TEST(suite, test_cansee); + SUITE_ADD_TEST(suite, test_cansee_items); return suite; }