diff --git a/src/creport.c b/src/creport.c index 9b97d8920..bba824538 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1471,7 +1471,7 @@ static void cr_output_region(FILE * F, report_context * ctx, region * r) } cr_output_travelthru(F, r, f); - if (r->seen.mode >= seen_travel) { + if (see_region_details(r)) { message_list *mlist = r_getmessages(r, f); cr_output_messages(F, r->msgs, f); if (mlist) { @@ -1503,7 +1503,6 @@ 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, r->seen.mode)) { cr_output_unit_compat(F, f, u, r->seen.mode); } diff --git a/src/report.c b/src/report.c index f84f4a3c8..319203e3b 100644 --- a/src/report.c +++ b/src/report.c @@ -688,7 +688,7 @@ nr_unit(struct stream *out, const faction * f, const unit * u, int indent, seen_ { char marker; int dh; - bool isbattle = (bool)(mode == seen_battle); + bool isbattle = (mode == seen_battle); char buf[8192]; if (fval(u_race(u), RCF_INVISIBLE)) @@ -2332,7 +2332,9 @@ report_plaintext(const char *filename, report_context * ctx, if (b) { nr_building(out, r, b, f); while (u && u->building == b) { - nr_unit(out, f, u, 6, r->seen.mode); + if (visible_unit(u, f, stealthmod, r->seen.mode)) { + nr_unit(out, f, u, 6, r->seen.mode); + } u = u->next; } b = b->next; @@ -2353,7 +2355,9 @@ report_plaintext(const char *filename, report_context * ctx, if (sh) { nr_ship(out, r, sh, f, u); while (u && u->ship == sh) { - nr_unit(out, f, u, 6, r->seen.mode); + if (visible_unit(u, f, stealthmod, r->seen.mode)) { + nr_unit(out, f, u, 6, r->seen.mode); + } u = u->next; } sh = sh->next; diff --git a/src/reports.c b/src/reports.c index 208934adb..f5b7f5531 100644 --- a/src/reports.c +++ b/src/reports.c @@ -2445,13 +2445,18 @@ bool visible_unit(const unit *u, const faction *f, int stealthmod, seen_mode mod return true; } else { - if (stealthmod > INT_MIN && mode >= seen_unit) { + if (stealthmod > INT_MIN && (mode == seen_lighthouse || mode >= seen_unit)) { return cansee(f, u->region, u, stealthmod); } } return false; } +bool see_region_details(const region *r) +{ + return r->seen.mode >= seen_travel; +} + void register_reports(void) { /* register datatypes for the different message objects */ diff --git a/src/reports.h b/src/reports.h index 473ac661c..0bdaf7d8c 100644 --- a/src/reports.h +++ b/src/reports.h @@ -135,6 +135,7 @@ extern "C" { const char *get_mailcmd(const struct locale *loc); bool visible_unit(const struct unit *u, const struct faction *f, int stealthmod, seen_mode mode); + bool see_region_details(const struct region *r); #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 e86fbbbf8..2b22782ae 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -823,21 +823,37 @@ static void test_newbie_warning(CuTest *tc) { test_teardown(); } -static void test_cansee_spell(CuTest *tc) { +static void test_visible_unit(CuTest *tc) { unit *u2; faction *f; + ship *sh; test_setup(); f = test_create_faction(NULL); u2 = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); + sh = test_create_ship(u2->region, NULL); CuAssertTrue(tc, cansee(f, u2->region, u2, 0)); + CuAssertTrue(tc, visible_unit(u2, f, 0, seen_unit)); CuAssertTrue(tc, visible_unit(u2, f, 0, seen_spell)); CuAssertTrue(tc, visible_unit(u2, f, 0, seen_battle)); + CuAssertTrue(tc, !visible_unit(u2, f, 0, seen_travel)); + CuAssertTrue(tc, !visible_unit(u2, f, 0, seen_none)); + CuAssertTrue(tc, !visible_unit(u2, f, 0, seen_neighbour)); + + CuAssertTrue(tc, visible_unit(u2, f, 0, seen_lighthouse)); + CuAssertTrue(tc, !visible_unit(u2, f, -2, seen_lighthouse)); + u2->ship = sh; + CuAssertTrue(tc, visible_unit(u2, f, -2, seen_lighthouse)); + u2->ship = NULL; set_level(u2, SK_STEALTH, 1); CuAssertTrue(tc, !cansee(f, u2->region, u2, 0)); CuAssertTrue(tc, cansee(f, u2->region, u2, 1)); + + u2->ship = sh; + CuAssertTrue(tc, visible_unit(u2, f, -2, seen_lighthouse)); + u2->ship = NULL; CuAssertTrue(tc, visible_unit(u2, f, 1, seen_spell)); CuAssertTrue(tc, visible_unit(u2, f, 1, seen_battle)); @@ -873,6 +889,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); + SUITE_ADD_TEST(suite, test_visible_unit); return suite; }