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);
if (r->seen.mode >= seen_unit) {
report_region_schemes(out, r, f); report_region_schemes(out, r, f);
}
if (r->seen.mode >= seen_lighthouse) {
report_region_edges(out, r, f, edges, ne); 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,20 +1906,16 @@ 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);
}
/* How many are we listing? For grammar. */
maxtravel = count_travelthru(r, f);
if (maxtravel > 0) { if (maxtravel > 0) {
cb_data cbdata; cb_data cbdata;
char buf[8192]; char buf[8192];
newline(out);
init_cb(&cbdata, out, buf, sizeof(buf), f); init_cb(&cbdata, out, buf, sizeof(buf), f);
cbdata.maxtravel = maxtravel; cbdata.maxtravel = maxtravel;
cbdata.writep += cbdata.writep +=
@ -1922,6 +1923,28 @@ void report_travelthru(struct stream *out, region *r, const faction *f)
travelthru_map(r, cb_write_travelthru, &cbdata); travelthru_map(r, cb_write_travelthru, &cbdata);
return; return;
} }
}
}
static void report_market(stream * out, const region *r, const faction *f) {
const item_type *lux = r_luxury(r);
const item_type *herb = r->land->herbtype;
message * 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);
}
} }
int int
@ -2124,78 +2147,50 @@ 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;
/* Beschreibung */
rpline(out); rpline(out);
newline(out); newline(out);
report_region(out, r, f);
}
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) { else if (!fval(r->terrain, SEA_REGION) && rpeasants(r) / TRADE_FRACTION > 0) {
m = msg_message("nr_market_info_s", "p1",lux->rtype); report_prices(out, r, f);
} }
else if (herb) { report_guards(out, r, f);
m = msg_message("nr_market_info_s", "p1", herb->rtype);
}
if (m) {
newline(out);
nr_paragraph(out, m, f);
}
}
else {
if (!fval(r->terrain, SEA_REGION) && rpeasants(r) / TRADE_FRACTION > 0) {
newline(out);
prices(out, r, f);
}
}
guards(out, r, f);
newline(out);
report_travelthru(out, r, f); report_travelthru(out, r, f);
if (wants_stats) {
report_statistics(out, r, f);
} }
else { }
report_region(out, r, f); else if (r->seen.mode >= seen_lighthouse) {
newline(out);
report_travelthru(out, r, f); 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);
}
}
/* 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;
if (r->seen.mode >= seen_travel) {
building *b = r->buildings;
while (b) { while (b) {
while (b && (!u || u->building != b)) { while (b && (!u || u->building != b)) {
nr_building(out, r, b, f); nr_building(out, r, b, f);
@ -2212,6 +2207,7 @@ report_plaintext(const char *filename, report_context * ctx,
b = b->next; b = b->next;
} }
} }
}
while (u && !u->ship) { while (u && !u->ship) {
if (visible_unit(u, f, stealthmod, r->seen.mode)) { if (visible_unit(u, f, stealthmod, r->seen.mode)) {
nr_unit(out, f, u, 4, r->seen.mode); nr_unit(out, f, u, 4, r->seen.mode);
@ -2235,10 +2231,8 @@ report_plaintext(const char *filename, report_context * ctx,
sh = sh->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,6 +1116,7 @@ void get_addresses(report_context * ctx)
} }
for (; r != NULL; r = r->next) { for (; r != NULL; r = r->next) {
if (r->seen.mode >= seen_lighthouse) {
int stealthmod = stealth_modifier(r, ctx->f, r->seen.mode); int stealthmod = stealth_modifier(r, ctx->f, r->seen.mode);
if (r->seen.mode == seen_lighthouse) { if (r->seen.mode == seen_lighthouse) {
unit *u = r->units; unit *u = r->units;
@ -1150,6 +1152,7 @@ void get_addresses(report_context * ctx)
} }
} }
} }
}
if (f_get_alliance(ctx->f)) { if (f_get_alliance(ctx->f)) {
faction *f2; faction *f2;
@ -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));