Sichtbarkeit von Landregionen aus Leuchttürmen.

https://bugs.eressea.de/view.php?id=2490
This commit is contained in:
Enno Rehling 2019-08-20 17:24:05 +02:00
parent 5264b6e4f5
commit 62a45496e4
5 changed files with 141 additions and 142 deletions

View File

@ -59,6 +59,7 @@ struct weapon_type;
typedef enum { typedef enum {
seen_none, seen_none,
seen_neighbour, seen_neighbour,
seen_lighthouse_land,
seen_lighthouse, seen_lighthouse,
seen_travel, seen_travel,
seen_unit, seen_unit,

View File

@ -750,7 +750,7 @@ static void append_message(sbstring *sbp, message *m, const faction * f) {
sbp->end += size; sbp->end += size;
} }
static void prices(struct stream *out, const region * r, const faction * f) static void report_prices(struct stream *out, const region * r, const faction * f)
{ {
const luxury_type *sale = NULL; const luxury_type *sale = NULL;
struct demand *dmd; struct demand *dmd;
@ -771,6 +771,7 @@ static void prices(struct stream *out, const region * r, const faction * f)
m = msg_message("nr_market_sale", "product price", m = msg_message("nr_market_sale", "product price",
sale->itype->rtype, sale->price); sale->itype->rtype, sale->price);
newline(out);
nr_render(m, f->locale, buf, sizeof(buf), f); nr_render(m, f->locale, buf, sizeof(buf), f);
msg_release(m); msg_release(m);
sbs_adopt(&sbs, buf, sizeof(buf)); sbs_adopt(&sbs, buf, sizeof(buf));
@ -867,7 +868,8 @@ static void report_region_description(struct stream *out, const region * r, fact
sbs_strcat(&sbs, LOC(f->locale, "see_neighbour")); sbs_strcat(&sbs, LOC(f->locale, "see_neighbour"));
sbs_strcat(&sbs, ")"); sbs_strcat(&sbs, ")");
} }
else if (r->seen.mode == seen_lighthouse) { else if ((r->seen.mode == seen_lighthouse)
|| (r->seen.mode == seen_lighthouse_land)) {
sbs_strcat(&sbs, " ("); sbs_strcat(&sbs, " (");
sbs_strcat(&sbs, LOC(f->locale, "see_lighthouse")); sbs_strcat(&sbs, LOC(f->locale, "see_lighthouse"));
sbs_strcat(&sbs, ")"); sbs_strcat(&sbs, ")");
@ -1154,17 +1156,22 @@ void report_region(struct stream *out, const region * r, faction * f)
} }
report_region_description(out, r, f, see); report_region_description(out, r, f, see);
report_region_schemes(out, r, f); if (r->seen.mode >= seen_unit) {
report_region_edges(out, r, f, edges, ne); report_region_schemes(out, r, f);
}
if (r->seen.mode >= seen_lighthouse) {
report_region_edges(out, r, f, edges, ne);
}
} }
static void statistics(struct stream *out, const region * r, const faction * f) static void report_statistics(struct stream *out, const region * r, const faction * f)
{ {
int p = rpeasants(r); int p = rpeasants(r);
message *m; message *m;
char buf[4096]; char buf[4096];
/* print */ /* print */
newline(out);
m = msg_message("nr_stat_header", "region", r); m = msg_message("nr_stat_header", "region", r);
nr_render(m, f->locale, buf, sizeof(buf), f); nr_render(m, f->locale, buf, sizeof(buf), f);
msg_release(m); msg_release(m);
@ -1611,7 +1618,7 @@ static void allies(struct stream *out, const faction * f)
} }
} }
static void guards(struct stream *out, const region * r, const faction * see) static void report_guards(struct stream *out, const region * r, const faction * see)
{ {
/* die Partei see sieht dies; wegen /* die Partei see sieht dies; wegen
* "unbekannte Partei", wenn man es selbst ist... */ * "unbekannte Partei", wenn man es selbst ist... */
@ -1810,12 +1817,10 @@ nr_building(struct stream *out, const region *r, const building *b, const factio
} }
paragraph(out, buffer, 2, 0, 0); paragraph(out, buffer, 2, 0, 0);
if (r->seen.mode >= seen_lighthouse) { nr_curses(out, 4, f, TYP_BUILDING, b);
nr_curses(out, 4, f, TYP_BUILDING, b);
}
} }
static void nr_paragraph(struct stream *out, message * m, faction * f) static void nr_paragraph(struct stream *out, message * m, const faction * f)
{ {
char buf[4096]; char buf[4096];
@ -1901,26 +1906,44 @@ static void cb_write_travelthru(region *r, unit *u, void *cbdata) {
void report_travelthru(struct stream *out, region *r, const faction *f) void report_travelthru(struct stream *out, region *r, const faction *f)
{ {
int maxtravel;
assert(r); assert(r);
assert(f); assert(f);
if (!fval(r, RF_TRAVELUNIT)) { if (fval(r, RF_TRAVELUNIT)) {
return; int maxtravel = count_travelthru(r, f);
if (maxtravel > 0) {
cb_data cbdata;
char buf[8192];
newline(out);
init_cb(&cbdata, out, buf, sizeof(buf), f);
cbdata.maxtravel = maxtravel;
cbdata.writep +=
str_strlcpy(buf, LOC(f->locale, "travelthru_header"), sizeof(buf));
travelthru_map(r, cb_write_travelthru, &cbdata);
return;
}
} }
}
/* How many are we listing? For grammar. */ static void report_market(stream * out, const region *r, const faction *f) {
maxtravel = count_travelthru(r, f); const item_type *lux = r_luxury(r);
if (maxtravel > 0) { const item_type *herb = r->land->herbtype;
cb_data cbdata; message * m = NULL;
char buf[8192];
init_cb(&cbdata, out, buf, sizeof(buf), f); if (herb && lux) {
cbdata.maxtravel = maxtravel; m = msg_message("nr_market_info_p", "p1 p2",
cbdata.writep += lux->rtype, herb->rtype);
str_strlcpy(buf, LOC(f->locale, "travelthru_header"), sizeof(buf)); }
travelthru_map(r, cb_write_travelthru, &cbdata); else if (lux) {
return; m = msg_message("nr_market_info_s", "p1", lux->rtype);
}
else if (herb) {
m = msg_message("nr_market_info_s", "p1", herb->rtype);
}
if (m) {
newline(out);
nr_paragraph(out, m, f);
} }
} }
@ -2124,121 +2147,92 @@ report_plaintext(const char *filename, report_context * ctx,
for (r = ctx->first; r != ctx->last; r = r->next) { for (r = ctx->first; r != ctx->last; r = r->next) {
int stealthmod = stealth_modifier(r, f, r->seen.mode); int stealthmod = stealth_modifier(r, f, r->seen.mode);
building *b = r->buildings;
ship *sh = r->ships; ship *sh = r->ships;
if (r->seen.mode < seen_lighthouse) if (r->seen.mode >= seen_lighthouse_land) {
continue; rpline(out);
/* Beschreibung */ newline(out);
report_region(out, r, f);
}
rpline(out);
newline(out);
if (r->seen.mode >= seen_unit) { if (r->seen.mode >= seen_unit) {
anyunits = 1; anyunits = 1;
report_region(out, r, f);
if (markets_module() && r->land) { if (markets_module() && r->land) {
const item_type *lux = r_luxury(r); report_market(out, r, f);
const item_type *herb = r->land->herbtype;
m = NULL;
if (herb && lux) {
m = msg_message("nr_market_info_p", "p1 p2",
lux->rtype, herb->rtype);
}
else if (lux) {
m = msg_message("nr_market_info_s", "p1",lux->rtype);
}
else if (herb) {
m = msg_message("nr_market_info_s", "p1", herb->rtype);
}
if (m) {
newline(out);
nr_paragraph(out, m, f);
}
} }
else { else if (!fval(r->terrain, SEA_REGION) && rpeasants(r) / TRADE_FRACTION > 0) {
if (!fval(r->terrain, SEA_REGION) && rpeasants(r) / TRADE_FRACTION > 0) { report_prices(out, r, f);
newline(out);
prices(out, r, f);
}
} }
guards(out, r, f); report_guards(out, r, f);
newline(out);
report_travelthru(out, r, f); report_travelthru(out, r, f);
} if (wants_stats) {
else { report_statistics(out, r, f);
report_region(out, r, f);
newline(out);
report_travelthru(out, r, f);
}
if (wants_stats && r->seen.mode >= seen_travel) {
if (r->land || r->seen.mode >= seen_unit) {
newline(out);
statistics(out, r, f);
} }
} }
else if (r->seen.mode >= seen_lighthouse) {
report_travelthru(out, r, f);
}
/* Nachrichten an REGION in der Region */ /* Nachrichten an REGION in der Region */
if (r->seen.mode >= seen_travel) { if (r->seen.mode >= seen_lighthouse) {
message_list *mlist = r_getmessages(r, f); message_list *mlist = r_getmessages(r, f);
newline(out);
if (mlist) { if (mlist) {
struct mlist **split = merge_messages(mlist, r->msgs); struct mlist **split = merge_messages(mlist, r->msgs);
newline(out); newline(out);
rp_messages(out, mlist, f, 0, false); rp_messages(out, mlist, f, 0, false);
split_messages(mlist, split); split_messages(mlist, split);
} }
else { else if (r->msgs) {
newline(out);
rp_messages(out, r->msgs, f, 0, false); rp_messages(out, r->msgs, f, 0, false);
} }
}
/* report all units. they are pre-sorted in an efficient manner */ /* report all units. they are pre-sorted in an efficient manner */
u = r->units; u = r->units;
while (b) { if (r->seen.mode >= seen_travel) {
while (b && (!u || u->building != b)) { building *b = r->buildings;
nr_building(out, r, b, f); while (b) {
b = b->next; while (b && (!u || u->building != b)) {
} nr_building(out, r, b, f);
if (b) { b = b->next;
nr_building(out, r, b, f);
while (u && u->building == b) {
if (visible_unit(u, f, stealthmod, r->seen.mode)) {
nr_unit(out, f, u, 6, r->seen.mode);
} }
u = u->next; if (b) {
} nr_building(out, r, b, f);
b = b->next; while (u && u->building == b) {
} if (visible_unit(u, f, stealthmod, r->seen.mode)) {
} nr_unit(out, f, u, 6, r->seen.mode);
while (u && !u->ship) { }
if (visible_unit(u, f, stealthmod, r->seen.mode)) { u = u->next;
nr_unit(out, f, u, 4, r->seen.mode); }
} b = b->next;
assert(!u->building);
u = u->next;
}
while (sh) {
while (sh && (!u || u->ship != sh)) {
nr_ship(out, r, sh, f, NULL);
sh = sh->next;
}
if (sh) {
nr_ship(out, r, sh, f, u);
while (u && u->ship == sh) {
if (visible_unit(u, f, stealthmod, r->seen.mode)) {
nr_unit(out, f, u, 6, r->seen.mode);
} }
u = u->next;
} }
sh = sh->next;
} }
while (u && !u->ship) {
if (visible_unit(u, f, stealthmod, r->seen.mode)) {
nr_unit(out, f, u, 4, r->seen.mode);
}
assert(!u->building);
u = u->next;
}
while (sh) {
while (sh && (!u || u->ship != sh)) {
nr_ship(out, r, sh, f, NULL);
sh = sh->next;
}
if (sh) {
nr_ship(out, r, sh, f, u);
while (u && u->ship == sh) {
if (visible_unit(u, f, stealthmod, r->seen.mode)) {
nr_unit(out, f, u, 6, r->seen.mode);
}
u = u->next;
}
sh = sh->next;
}
}
assert(!u);
} }
assert(!u);
newline(out);
ERRNO_CHECK(); ERRNO_CHECK();
} }
if (!is_monsters(f)) { if (!is_monsters(f)) {

View File

@ -260,7 +260,7 @@ static void test_report_travelthru(CuTest *tc) {
out.api->rewind(out.handle); out.api->rewind(out.handle);
len = out.api->read(out.handle, buf, sizeof(buf)); len = out.api->read(out.handle, buf, sizeof(buf));
buf[len] = '\0'; buf[len] = '\0';
CuAssertStrEquals_Msg(tc, "list one unit", "Durchreise: Hodor (1).\n", buf); CuAssertStrEquals_Msg(tc, "list one unit", "\nDurchreise: Hodor (1).\n", buf);
mstream_done(&out); mstream_done(&out);
mstream_init(&out); mstream_init(&out);

View File

@ -102,6 +102,7 @@ const char *visibility[] = {
"none", "none",
"neighbour", "neighbour",
"lighthouse", "lighthouse",
"lighthouse",
"travel", "travel",
"far", "far",
"unit", "unit",
@ -1115,38 +1116,40 @@ void get_addresses(report_context * ctx)
} }
for (; r != NULL; r = r->next) { for (; r != NULL; r = r->next) {
int stealthmod = stealth_modifier(r, ctx->f, r->seen.mode); if (r->seen.mode >= seen_lighthouse) {
if (r->seen.mode == seen_lighthouse) { int stealthmod = stealth_modifier(r, ctx->f, r->seen.mode);
unit *u = r->units; if (r->seen.mode == seen_lighthouse) {
for (; u; u = u->next) { unit *u = r->units;
faction *sf = visible_faction(ctx->f, u); for (; u; u = u->next) {
if (lastf != sf) { faction *sf = visible_faction(ctx->f, u);
if (u->building || u->ship || (stealthmod > INT_MIN if (lastf != sf) {
&& cansee(ctx->f, r, u, stealthmod))) { if (u->building || u->ship || (stealthmod > INT_MIN
add_seen_faction_i(&flist, sf); && cansee(ctx->f, r, u, stealthmod))) {
lastf = sf; add_seen_faction_i(&flist, sf);
lastf = sf;
}
} }
} }
} }
} else if (r->seen.mode == seen_travel) {
else if (r->seen.mode == seen_travel) { /* when we travel through a region, then we must add
/* when we travel through a region, then we must add * the factions of any units we saw */
* the factions of any units we saw */ add_travelthru_addresses(r, ctx->f, &flist, stealthmod);
add_travelthru_addresses(r, ctx->f, &flist, stealthmod); }
} else if (r->seen.mode > seen_travel) {
else if (r->seen.mode > seen_travel) { const unit *u = r->units;
const unit *u = r->units; while (u != NULL) {
while (u != NULL) { if (u->faction != ctx->f) {
if (u->faction != ctx->f) { faction *sf = visible_faction(ctx->f, u);
faction *sf = visible_faction(ctx->f, u); bool ballied = sf && sf != ctx->f && sf != lastf
bool ballied = sf && sf != ctx->f && sf != lastf && !fval(u, UFL_ANON_FACTION) && cansee(ctx->f, r, u, stealthmod);
&& !fval(u, UFL_ANON_FACTION) && cansee(ctx->f, r, u, stealthmod); if (ballied || is_allied(ctx->f, sf)) {
if (ballied || is_allied(ctx->f, sf)) { add_seen_faction_i(&flist, sf);
add_seen_faction_i(&flist, sf); lastf = sf;
lastf = sf; }
} }
u = u->next;
} }
u = u->next;
} }
} }
} }
@ -1294,7 +1297,7 @@ static void add_seen_lighthouse(region *r, faction *f)
add_seen_nb(f, r, seen_lighthouse); add_seen_nb(f, r, seen_lighthouse);
} }
else { else {
add_seen_nb(f, r, seen_neighbour); add_seen_nb(f, r, seen_lighthouse_land);
} }
} }

View File

@ -573,7 +573,7 @@ static void test_prepare_lighthouse(CuTest *tc) {
CuAssertIntEquals(tc, seen_unit, r1->seen.mode); CuAssertIntEquals(tc, seen_unit, r1->seen.mode);
CuAssertIntEquals(tc, seen_lighthouse, r2->seen.mode); CuAssertIntEquals(tc, seen_lighthouse, r2->seen.mode);
CuAssertIntEquals(tc, seen_neighbour, r3->seen.mode); CuAssertIntEquals(tc, seen_neighbour, r3->seen.mode);
CuAssertIntEquals(tc, seen_neighbour, r4->seen.mode); CuAssertIntEquals(tc, seen_lighthouse_land, r4->seen.mode);
finish_reports(&ctx); finish_reports(&ctx);
test_teardown(); test_teardown();
} }
@ -868,6 +868,7 @@ static void test_visible_unit(CuTest *tc) {
CuAssertTrue(tc, !visible_unit(u, f, 0, seen_travel)); CuAssertTrue(tc, !visible_unit(u, f, 0, seen_travel));
CuAssertTrue(tc, !visible_unit(u, f, 0, seen_none)); CuAssertTrue(tc, !visible_unit(u, f, 0, seen_none));
CuAssertTrue(tc, !visible_unit(u, f, 0, seen_neighbour)); 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, 0, seen_lighthouse));
CuAssertTrue(tc, !visible_unit(u, f, -2, seen_lighthouse)); CuAssertTrue(tc, !visible_unit(u, f, -2, seen_lighthouse));