diff --git a/src/console.c b/src/console.c index 0c0629de8..034dd9994 100644 --- a/src/console.c +++ b/src/console.c @@ -246,15 +246,17 @@ int lua_do(lua_State * L) { int status = loadline(L); if (status != -1) { - if (status == 0) + if (status == 0) { status = docall(L, 0, 0); + } report(L, status); if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */ lua_getglobal(L, "print"); lua_insert(L, 1); - if (lua_pcall(L, lua_gettop(L) - 1, 0, 0) != 0) + if (lua_pcall(L, lua_gettop(L) - 1, 0, 0) != 0) { l_message(NULL, lua_pushfstring(L, "error calling `print' (%s)", - lua_tostring(L, -1))); + lua_tostring(L, -1))); + } } } lua_settop(L, 0); /* clear stack */ diff --git a/src/creport.c b/src/creport.c index 68f634dad..5f34cba54 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1481,7 +1481,7 @@ static void cr_output_region(FILE * F, report_context * ctx, region * r) /* visible units */ for (u = r->units; u; u = u->next) { - if (visible_unit(u, f, stealthmod)) { + if (visible_unit(u, f, stealthmod, r->seen.mode)) { cr_output_unit_compat(F, r, f, u, r->seen.mode); } } diff --git a/src/laws.test.c b/src/laws.test.c index a57b93b9e..c84190688 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -1679,25 +1679,6 @@ static void test_cansee(CuTest *tc) { test_cleanup(); } -static void test_cansee_spell(CuTest *tc) { - unit *u2; - faction *f; - - test_setup(); - f = test_create_faction(0); - u2 = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); - - CuAssertTrue(tc, cansee_ex(f, u2->region, u2, 0, seen_spell)); - CuAssertTrue(tc, cansee_ex(f, u2->region, u2, 0, seen_battle)); - - set_level(u2, SK_STEALTH, 1); - CuAssertTrue(tc, !cansee_ex(f, u2->region, u2, 0, seen_spell)); - CuAssertTrue(tc, cansee_ex(f, u2->region, u2, 1, seen_spell)); - CuAssertTrue(tc, cansee_ex(f, u2->region, u2, 1, seen_battle)); - - test_cleanup(); -} - static void test_cansee_ring(CuTest *tc) { unit *u, *u2; item_type *itype[2]; @@ -1835,7 +1816,6 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_cansee); SUITE_ADD_TEST(suite, test_cansee_ring); SUITE_ADD_TEST(suite, test_cansee_sphere); - SUITE_ADD_TEST(suite, test_cansee_spell); return suite; } diff --git a/src/report.c b/src/report.c index bd884acee..f50ac265c 100644 --- a/src/report.c +++ b/src/report.c @@ -2337,7 +2337,7 @@ report_plaintext(const char *filename, report_context * ctx, } } while (u && !u->ship) { - if (visible_unit(u, f, stealthmod)) { + if (visible_unit(u, f, stealthmod, r->seen.mode)) { nr_unit(out, f, u, 4, r->seen.mode); } assert(!u->building); diff --git a/src/reports.c b/src/reports.c index 67b78850d..bd8153d69 100644 --- a/src/reports.c +++ b/src/reports.c @@ -2225,16 +2225,14 @@ int count_travelthru(struct region *r, const struct faction *f) { return data.n; } -bool visible_unit(const unit *u, const faction *f, int stealthmod) +bool visible_unit(const unit *u, const faction *f, int stealthmod, seen_mode mode) { if (u->faction == f) { return true; } else { - const region *r = u->region; - seen_mode mode = r->seen.mode; if (stealthmod > INT_MIN && mode >= seen_unit) { - return cansee_ex(f, r, u, stealthmod, mode); + return cansee(f, u->region, u, stealthmod); } } return false; diff --git a/src/reports.h b/src/reports.h index 9219e222a..f30dfc051 100644 --- a/src/reports.h +++ b/src/reports.h @@ -137,7 +137,7 @@ extern "C" { int count_travelthru(struct region *r, const struct faction *f); const char *get_mailcmd(const struct locale *loc); - bool visible_unit(const struct unit *u, const struct faction *f, int stealthmod); + bool visible_unit(const struct unit *u, const struct faction *f, int stealthmod, seen_mode mode); #define GR_PLURAL 0x01 /* grammar: plural */ #define MAX_INVENTORY 128 /* maimum number of different items in an inventory */ diff --git a/src/reports.test.c b/src/reports.test.c index 9506a5a0b..f22876c4d 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -4,6 +4,7 @@ #include "calendar.h" #include "keyword.h" #include "lighthouse.h" +#include "laws.h" #include "move.h" #include "spells.h" #include "spy.h" @@ -820,6 +821,27 @@ static void test_newbie_warning(CuTest *tc) { test_cleanup(); } +static void test_cansee_spell(CuTest *tc) { + unit *u2; + faction *f; + + test_setup(); + f = test_create_faction(0); + u2 = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); + + CuAssertTrue(tc, cansee(f, u2->region, u2, 0)); + CuAssertTrue(tc, visible_unit(u2, f, 0, seen_spell)); + CuAssertTrue(tc, visible_unit(u2, f, 0, seen_battle)); + + set_level(u2, SK_STEALTH, 1); + CuAssertTrue(tc, !cansee(f, u2->region, u2, 0)); + CuAssertTrue(tc, cansee(f, u2->region, u2, 1)); + CuAssertTrue(tc, visible_unit(u2, f, 1, seen_spell)); + CuAssertTrue(tc, visible_unit(u2, f, 1, seen_battle)); + + test_cleanup(); +} + CuSuite *get_reports_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -849,5 +871,6 @@ CuSuite *get_reports_suite(void) SUITE_ADD_TEST(suite, test_arg_resources); SUITE_ADD_TEST(suite, test_insect_warnings); SUITE_ADD_TEST(suite, test_newbie_warning); + SUITE_ADD_TEST(suite, test_cansee_spell); return suite; }