From 9302d02b04c3b3b155188dfd1019ef7aeb5a87df Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 4 Nov 2024 20:37:01 +0100 Subject: [PATCH 1/3] reproduce the bug add an optimization to the spell, too --- src/laws.test.c | 17 +++++++++++++++++ src/spells.c | 4 +++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/laws.test.c b/src/laws.test.c index 2572f0dfb..ef858a81d 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -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)); /* can see even if using spell with no modifier */ + set_level(u, SK_STEALTH, 1); + CuAssertTrue(tc, !cansee(f, u->region, u, 0)); + CuAssertTrue(tc, cansee(f, u->region, u, 1)); + + test_teardown(); +} + /** * Hidden monsters are seen in oceans if they are big enough. @@ -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); diff --git a/src/spells.c b/src/spells.c index 42da7f32d..f1b1fc6ce 100644 --- a/src/spells.c +++ b/src/spells.c @@ -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) { From 8c75d65eff4981fab9ce84de84fb5e4344f223e4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 4 Nov 2024 20:37:40 +0100 Subject: [PATCH 2/3] bugfix seen_spell --- src/laws.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/laws.c b/src/laws.c index 12f06ec0b..2ea6dad9b 100644 --- a/src/laws.c +++ b/src/laws.c @@ -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); @@ -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) { From ffe3aeaa492fc82d68ace4a34728dc93225d34b3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 4 Nov 2024 21:12:29 +0100 Subject: [PATCH 3/3] fix the bad bugfix --- scripts/tests/e2/recruit.lua | 4 ++-- src/laws.c | 2 +- src/laws.test.c | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/tests/e2/recruit.lua b/scripts/tests/e2/recruit.lua index 2766f195b..83c7c09ec 100644 --- a/scripts/tests/e2/recruit.lua +++ b/scripts/tests/e2/recruit.lua @@ -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() @@ -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 diff --git a/src/laws.c b/src/laws.c index 2ea6dad9b..bb32248aa 100644 --- a/src/laws.c +++ b/src/laws.c @@ -3995,7 +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 (stealth <= 0 && rings < u->number) 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) { diff --git a/src/laws.test.c b/src/laws.test.c index ef858a81d..0d33962d1 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -2255,10 +2255,10 @@ static void test_cansee_skillmod(CuTest *tc) { f = test_create_faction(); u = test_create_unit(test_create_faction(), test_create_plain(0, 0)); - CuAssertTrue(tc, cansee(f, u->region, u, 0)); /* can see even if using spell with no modifier */ - set_level(u, SK_STEALTH, 1); CuAssertTrue(tc, !cansee(f, u->region, u, 0)); - CuAssertTrue(tc, cansee(f, u->region, u, 1)); + set_level(u, SK_STEALTH, 1); + CuAssertTrue(tc, !cansee(f, u->region, u, 1)); + CuAssertTrue(tc, cansee(f, u->region, u, 2)); test_teardown(); }