Skip to content

Commit

Permalink
Merge pull request #1097 from eressea/cansee-3050
Browse files Browse the repository at this point in the history
Bug 3050: seen_spell not reporting all units
  • Loading branch information
ennorehling authored Nov 4, 2024
2 parents d657dfb + ffe3aea commit 2d34f16
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
4 changes: 2 additions & 2 deletions scripts/tests/e2/recruit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function test_guarded_temp_cannot_recruit()
count = count + 1
end
assert_equal(0, zero)
assert_equal(1, count)
assert_equal(2, count)
end

function test_recruit_empty()
Expand Down Expand Up @@ -171,5 +171,5 @@ function test_recruit_empty()
count = count +1
end
assert_equal(0, zero)
assert_equal(1, count)
assert_equal(2, count)
end
8 changes: 2 additions & 6 deletions src/laws.c
Original file line number Diff line number Diff line change
Expand Up @@ -3889,7 +3889,7 @@ typedef enum cansee_t {
static enum cansee_t cansee_ex(const unit *u, const region *r, const unit *target, int stealth, int rings)
{
enum cansee_t result = CANSEE_HIDDEN;
if (rings > 0 && rings >= target->number) {
if (rings >= target->number) {
const resource_type *rtype = get_resourcetype(R_AMULET_OF_TRUE_SEEING);
if (rtype) {
int amulet = i_get(u->items, rtype->itype);
Expand Down Expand Up @@ -3995,11 +3995,7 @@ bool cansee(const faction *f, const region *r, const unit *u, int modifier)

rings = invisible(u, NULL);
stealth = eff_stealth(u, r) - modifier;

if (rings > 0 && rings < u->number && stealth <= 0) {
return true;
}

if (stealth < 0 && rings < u->number) return true;
result = bsm = big_sea_monster(u, r);
for (u2 = r->units; u2; u2 = u2->next) {
if (u2->faction == f) {
Expand Down
17 changes: 17 additions & 0 deletions src/laws.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2247,6 +2247,22 @@ static void test_cansee_empty(CuTest *tc) {
test_teardown();
}

static void test_cansee_skillmod(CuTest *tc) {
unit *u;
faction *f;

test_setup();
f = test_create_faction();
u = test_create_unit(test_create_faction(), test_create_plain(0, 0));

CuAssertTrue(tc, !cansee(f, u->region, u, 0));
set_level(u, SK_STEALTH, 1);
CuAssertTrue(tc, !cansee(f, u->region, u, 1));
CuAssertTrue(tc, cansee(f, u->region, u, 2));

test_teardown();
}


/**
* Hidden monsters are seen in oceans if they are big enough.
Expand Down Expand Up @@ -3008,6 +3024,7 @@ CuSuite *get_laws_suite(void)
SUITE_ADD_TEST(suite, test_cansee_guard);
SUITE_ADD_TEST(suite, test_cansee_temp);
SUITE_ADD_TEST(suite, test_cansee_empty);
SUITE_ADD_TEST(suite, test_cansee_skillmod);
SUITE_ADD_TEST(suite, test_nmr_timeout);
SUITE_ADD_TEST(suite, test_long_orders);
SUITE_ADD_TEST(suite, test_long_order_on_ocean);
Expand Down
4 changes: 3 additions & 1 deletion src/spells.c
Original file line number Diff line number Diff line change
Expand Up @@ -4042,8 +4042,10 @@ int sp_pump(castorder * co)
}

for (u = rt->units; u; u = u->next) {
if (u->faction == target->faction)
if (u->faction == target->faction) {
see = true;
break;
}
}

if (see) {
Expand Down

0 comments on commit 2d34f16

Please sign in to comment.