Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 3050: seen_spell not reporting all units #1097

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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