From 6bd4e543ba7ec06cd0de8888ce0242f14abeb856 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 23 Dec 2017 17:37:24 +0100 Subject: [PATCH] BUG 2395: lighthouses were seeing units they should not. DRY! --- src/creport.c | 9 +-------- src/report.c | 6 ++---- src/reports.c | 15 +++++++++++++++ src/reports.h | 2 ++ 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/creport.c b/src/creport.c index 3f3e1bfb8..68f634dad 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1295,12 +1295,6 @@ static void cr_output_region(FILE * F, report_context * ctx, region * r) int oc[4][2], o = 0; int uid = r->uid; -#ifdef OCEAN_NEIGHBORS_GET_NO_ID - if (r->seen.mode <= seen_neighbour && !r->land) { - uid = 0; - } -#endif - if (opt_cr_absolute_coords) { nx = r->x; ny = r->y; @@ -1487,8 +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 (u->building || u->ship || (stealthmod > INT_MIN - && cansee_ex(f, r, u, stealthmod, r->seen.mode))) { + if (visible_unit(u, f, stealthmod)) { cr_output_unit_compat(F, r, f, u, r->seen.mode); } } diff --git a/src/report.c b/src/report.c index d6179ef37..bd884acee 100644 --- a/src/report.c +++ b/src/report.c @@ -2337,10 +2337,8 @@ report_plaintext(const char *filename, report_context * ctx, } } while (u && !u->ship) { - if (stealthmod > INT_MIN && r->seen.mode >= seen_unit) { - if (u->faction == f || cansee_ex(f, r, u, stealthmod, r->seen.mode)) { - nr_unit(out, f, u, 4, r->seen.mode); - } + if (visible_unit(u, f, stealthmod)) { + nr_unit(out, f, u, 4, r->seen.mode); } assert(!u->building); u = u->next; diff --git a/src/reports.c b/src/reports.c index 776df247f..67b78850d 100644 --- a/src/reports.c +++ b/src/reports.c @@ -2225,6 +2225,21 @@ int count_travelthru(struct region *r, const struct faction *f) { return data.n; } +bool visible_unit(const unit *u, const faction *f, int stealthmod) +{ + 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 false; +} + void register_reports(void) { /* register datatypes for the different message objects */ diff --git a/src/reports.h b/src/reports.h index 4407bb1c1..9219e222a 100644 --- a/src/reports.h +++ b/src/reports.h @@ -137,6 +137,8 @@ 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); + #define GR_PLURAL 0x01 /* grammar: plural */ #define MAX_INVENTORY 128 /* maimum number of different items in an inventory */ #define MAX_RAWMATERIALS 8 /* maximum kinds of raw materials in a regions */