fixing commit 1b53128e1a and adding a test for cansee.

This commit is contained in:
Enno Rehling 2017-10-13 19:07:57 +02:00
parent 8246639e57
commit ca6cbe5906
2 changed files with 39 additions and 1 deletions

View File

@ -4311,7 +4311,7 @@ cansee(const faction * f, const region * r, const unit * u, int modifier, seen_m
stealth = eff_stealth(u, r) - modifier; stealth = eff_stealth(u, r) - modifier;
if (mode > seen_unit) { if (mode > seen_unit) {
return (rings <= 0 || stealth <= 0); return (rings <= 0 && stealth <= 0);
} }
else { else {
unit *u2; unit *u2;

View File

@ -1581,6 +1581,7 @@ static void test_demon_hunger(CuTest * tc)
static void test_cansee(CuTest *tc) { static void test_cansee(CuTest *tc) {
unit *u, *u2; unit *u, *u2;
test_setup(); test_setup();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
u2 = test_create_unit(test_create_faction(0), u->region); 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); 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_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); 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_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(); test_cleanup();
} }
@ -1701,6 +1738,7 @@ CuSuite *get_laws_suite(void)
SUITE_ADD_TEST(suite, test_demon_hunger); SUITE_ADD_TEST(suite, test_demon_hunger);
SUITE_ADD_TEST(suite, test_armedmen); SUITE_ADD_TEST(suite, test_armedmen);
SUITE_ADD_TEST(suite, test_cansee); SUITE_ADD_TEST(suite, test_cansee);
SUITE_ADD_TEST(suite, test_cansee_items);
return suite; return suite;
} }