From 19a2a69f337619dcd2c0ab14174474245763e98d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 5 Aug 2020 16:29:20 +0200 Subject: [PATCH] Lighthouse: only show large swimming units (more than 10 weight). Eliminate RCF_INVISIBLE and the spell race. --- res/e3a/races.xml | 6 +----- res/eressea/races.xml | 4 ---- src/creport.c | 3 --- src/kernel/race.h | 3 +-- src/kernel/unit.c | 6 ++---- src/kernel/unit.test.c | 10 ---------- src/laws.c | 23 +++++++++++------------ src/report.c | 7 ++----- src/reports.c | 2 +- src/reports.test.c | 3 ++- 10 files changed, 20 insertions(+), 47 deletions(-) diff --git a/res/e3a/races.xml b/res/e3a/races.xml index 197a2f1d1..d039b067d 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -400,7 +400,7 @@ - + @@ -678,10 +678,6 @@ - - - - diff --git a/res/eressea/races.xml b/res/eressea/races.xml index b8d8c5139..ac182a2f8 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -675,10 +675,6 @@ - - - - diff --git a/src/creport.c b/src/creport.c index eaa19e186..18957447b 100644 --- a/src/creport.c +++ b/src/creport.c @@ -745,9 +745,6 @@ void cr_output_unit(stream *out, const faction * f, assert(u && u->number); - if (fval(u_race(u), RCF_INVISIBLE)) - return; - stream_printf(out, "EINHEIT %d\n", u->no); stream_printf(out, "\"%s\";Name\n", unit_getname(u)); str = u_description(u, lang); diff --git a/src/kernel/race.h b/src/kernel/race.h index 8918437e1..a034fd666 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -212,11 +212,10 @@ extern "C" { #define RCF_COASTAL (1<<22) /* kann in Landregionen an der Kueste sein */ #define RCF_UNARMEDGUARD (1<<23) /* kann ohne Waffen bewachen */ #define RCF_CANSAIL (1<<24) /* Einheit darf Schiffe betreten */ -#define RCF_INVISIBLE (1<<25) /* not visible in any report */ +#define RCF_FAMILIAR (1<<25) /* may be a familiar */ #define RCF_SHIPSPEED (1<<26) /* race gets +1 on shipspeed */ #define RCF_ATTACK_MOVED (1<<27) /* may attack if it has moved */ #define RCF_MIGRANTS (1<<28) /* may have migrant units (human bonus) */ -#define RCF_FAMILIAR (1<<29) /* may be a familiar */ #define RCF_DEFAULT RCF_CANSAIL diff --git a/src/kernel/unit.c b/src/kernel/unit.c index bd8e91d7e..2229c16f7 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -937,9 +937,7 @@ void u_setfaction(unit * u, faction * f) bool count_unit(const unit *u) { - const race *rc = u_race(u); - /* spells are invisible. units we cannot see do not count to our limit */ - return rc == NULL || (rc->flags & RCF_INVISIBLE) == 0; + return u_race(u) != NULL; } void set_number(unit * u, int count) @@ -948,7 +946,7 @@ void set_number(unit * u, int count) assert(count <= UNIT_MAXSIZE); if (count == 0) { - u->flags &= ~(UFL_HERO); + u->flags &= ~UFL_HERO; } if (u->faction && count_unit(u)) { u->faction->num_people += count - u->number; diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index a5b0ec89d..75fd9ea08 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -520,14 +520,11 @@ static void test_heal_factor(CuTest *tc) { } static void test_unlimited_units(CuTest *tc) { - race *rc; faction *f; unit *u; test_setup(); f = test_create_faction(NULL); - rc = test_create_race("spell"); - rc->flags |= RCF_INVISIBLE; CuAssertIntEquals(tc, 0, f->num_units); CuAssertIntEquals(tc, 0, f->num_people); u = test_create_unit(f, test_create_region(0, 0, NULL)); @@ -540,14 +537,7 @@ static void test_unlimited_units(CuTest *tc) { u_setfaction(u, f); CuAssertIntEquals(tc, 1, f->num_units); CuAssertIntEquals(tc, 1, f->num_people); - u_setrace(u, rc); - CuAssertTrue(tc, !count_unit(u)); - CuAssertIntEquals(tc, 0, f->num_units); - CuAssertIntEquals(tc, 0, f->num_people); scale_number(u, 10); - CuAssertIntEquals(tc, 0, f->num_units); - CuAssertIntEquals(tc, 0, f->num_people); - u_setrace(u, f->race); CuAssertIntEquals(tc, 1, f->num_units); CuAssertIntEquals(tc, 10, f->num_people); remove_unit(&u->region->units, u); diff --git a/src/laws.c b/src/laws.c index 25548bc18..cdc36d2ed 100644 --- a/src/laws.c +++ b/src/laws.c @@ -4068,31 +4068,30 @@ void turn_end(void) update_spells(); } -/** determine if unit can be seen by faction +/** + * Determine if unit can be seen by faction. + * * @param f -- the observiong faction * @param u -- the unit that is observed * @param r -- the region that u is obesrved from (see below) * @param m -- terrain modifier to stealth - * + * * r kann != u->region sein, wenn es um Durchreisen geht, * oder Zauber (sp_generous, sp_fetchastral). * Es muss auch niemand aus f in der region sein, wenn sie vom Turm - * erblickt wird */ -bool -cansee(const faction * f, const region * r, const unit * u, int modifier) + * erblickt wird. + */ +bool cansee(const faction * f, const region * r, const unit * u, int modifier) { int stealth, rings; if (u->faction == f || omniscient(f)) { return true; } - else if (fval(u_race(u), RCF_INVISIBLE)) { - return false; - } else if (u->number == 0) { attrib *a = a_find(u->attribs, &at_creator); - if (a) { /* u is an empty temporary unit. In this special case - we look at the creating unit. */ + if (a) { + /* u is an empty temporary unit. In this special case we look at the creating unit. */ u = (unit *)a->data.v; } else { @@ -4132,7 +4131,7 @@ cansee(const faction * f, const region * r, const unit * u, int modifier) bool cansee_unit(const unit * u, const unit * target, int modifier) /* target->region kann != u->region sein, wenn es um durchreisen geht */ { - if (fval(u_race(target), RCF_INVISIBLE) || target->number == 0) + if (target->number == 0) return false; else if (target->faction == u->faction) return true; @@ -4175,7 +4174,7 @@ cansee_durchgezogen(const faction * f, const region * r, const unit * u, { unit *u2; - if (fval(u_race(u), RCF_INVISIBLE) || u->number == 0) + if (u->number == 0) return false; else if (u->faction == f) return true; diff --git a/src/report.c b/src/report.c index ab25b79b2..f283b552f 100644 --- a/src/report.c +++ b/src/report.c @@ -627,9 +627,6 @@ nr_unit(struct stream *out, const faction * f, const unit * u, int indent, seen_ bool isbattle = (mode == seen_battle); char buf[8192]; - if (fval(u_race(u), RCF_INVISIBLE)) - return; - newline(out); dh = bufunit_depr(f, u, mode, buf, sizeof(buf)); @@ -1231,7 +1228,7 @@ static void report_statistics(struct stream *out, const region * r, const factio /* count */ for (number = 0, u = r->units; u; u = u->next) { - if (u->faction == f && !fval(u_race(u), RCF_INVISIBLE)) { + if (u->faction == f) { for (itm = u->items; itm; itm = itm->next) { i_change(&items, itm->type, itm->number); } @@ -1321,7 +1318,7 @@ report_template(const char *filename, report_context * ctx, const char *bom) continue; for (u = r->units; u; u = u->next) { - if (u->faction == f && !fval(u_race(u), RCF_INVISIBLE)) { + if (u->faction == f) { order *ord; if (!dh) { plane *pl = getplane(r); diff --git a/src/reports.c b/src/reports.c index c362d2b0e..547351824 100644 --- a/src/reports.c +++ b/src/reports.c @@ -2371,7 +2371,7 @@ bool visible_unit(const unit *u, const faction *f, int stealthmod, seen_mode mod else { if (stealthmod > INT_MIN) { if (mode == seen_lighthouse) { - return true; + return u_race(u)->weight > 10000; } else if (mode > seen_travel || u->building || u->ship || is_guard(u)) { return cansee(f, u->region, u, stealthmod); } diff --git a/src/reports.test.c b/src/reports.test.c index 68a37e769..50dc08704 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -870,7 +870,8 @@ static void test_visible_unit(CuTest *tc) { CuAssertTrue(tc, !visible_unit(u, f, 0, seen_neighbour)); CuAssertTrue(tc, !visible_unit(u, f, 0, seen_lighthouse_land)); - CuAssertTrue(tc, visible_unit(u, f, 0, seen_lighthouse)); + CuAssertTrue(tc, !visible_unit(u, f, -2, seen_lighthouse)); + rc->weight = 11000; CuAssertTrue(tc, visible_unit(u, f, -2, seen_lighthouse)); u->ship = sh = test_create_ship(u->region, NULL);