re-enable report writing, fix report.c to work without seen_region

This commit is contained in:
Enno Rehling 2016-09-16 18:03:28 +02:00
parent 007f4d8b0d
commit d449ce4a8c
10 changed files with 70 additions and 85 deletions

View File

@ -105,7 +105,7 @@ set (ERESSEA_SRC
skill.c skill.c
json.c json.c
# creport.c # creport.c
# report.c report.c
economy.c economy.c
give.c give.c
items.c items.c
@ -200,7 +200,7 @@ set(TESTS_SRC
volcano.test.c volcano.test.c
reports.test.c reports.test.c
# creport.test.c # creport.test.c
# report.test.c report.test.c
summary.test.c summary.test.c
travelthru.test.c travelthru.test.c
callback.test.c callback.test.c

View File

@ -30,7 +30,7 @@
#include "chaos.h" #include "chaos.h"
#include "items.h" #include "items.h"
//#include "creport.h" //#include "creport.h"
//#include "report.h" #include "report.h"
#include "names.h" #include "names.h"
#include "reports.h" #include "reports.h"
#include "spells.h" #include "spells.h"
@ -64,7 +64,7 @@ void game_init(void)
register_triggers(); register_triggers();
register_xmas(); register_xmas();
// register_nr(); register_nr();
// register_cr(); // register_cr();
register_races(); register_races();

View File

@ -697,13 +697,11 @@ void r_setdemand(region * r, const luxury_type * ltype, int value)
d->value = value; d->value = value;
} }
const item_type *r_luxury(region * r) const item_type *r_luxury(const region * r)
{ {
struct demand *dmd; struct demand *dmd;
if (r->land) { if (r->land) {
if (!r->land->demands) { assert(r->land->demands || !"need to call fix_demands on a region");
fix_demand(r);
}
for (dmd = r->land->demands; dmd; dmd = dmd->next) { for (dmd = r->land->demands; dmd; dmd = dmd->next) {
if (dmd->value == 0) if (dmd->value == 0)
return dmd->type->itype; return dmd->type->itype;

View File

@ -274,7 +274,7 @@ extern "C" {
int value); int value);
int owner_change(const region * r); int owner_change(const region * r);
bool is_mourning(const region * r, int in_turn); bool is_mourning(const region * r, int in_turn);
const struct item_type *r_luxury(struct region *r); const struct item_type *r_luxury(const struct region *r);
void get_neighbours(const struct region *r, struct region **list); void get_neighbours(const struct region *r, struct region **list);
struct faction *update_owners(struct region *r); struct faction *update_owners(struct region *r);

View File

@ -21,6 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <platform.h> #include <platform.h>
#include <kernel/config.h> #include <kernel/config.h>
#include "report.h"
#include "reports.h" #include "reports.h"
#include "laws.h" #include "laws.h"
#include "travelthru.h" #include "travelthru.h"
@ -937,14 +938,14 @@ static void describe(stream *out, const region * r, faction * f)
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
if (sr->mode == see_travel) { if (r->seen.mode == seen_travel) {
bytes = _snprintf(bufp, size, " (%s)", LOC(f->locale, "see_travel")); bytes = _snprintf(bufp, size, " (%s)", LOC(f->locale, "seen_travel"));
} }
else if (sr->mode == see_neighbour) { else if (r->seen.mode == seen_neighbour) {
bytes = _snprintf(bufp, size, " (%s)", LOC(f->locale, "see_neighbour")); bytes = _snprintf(bufp, size, " (%s)", LOC(f->locale, "see_neighbour"));
} }
else if (sr->mode == see_lighthouse) { else if (r->seen.mode == seen_lighthouse) {
bytes = _snprintf(bufp, size, " (%s)", LOC(f->locale, "see_lighthouse")); bytes = _snprintf(bufp, size, " (%s)", LOC(f->locale, "seen_lighthouse"));
} }
else { else {
bytes = 0; bytes = 0;
@ -991,9 +992,9 @@ static void describe(stream *out, const region * r, faction * f)
} }
/* iron & stone */ /* iron & stone */
if (sr->mode == see_unit) { if (r->seen.mode == seen_unit) {
resource_report result[MAX_RAWMATERIALS]; resource_report result[MAX_RAWMATERIALS];
int n, numresults = report_resources(sr, result, MAX_RAWMATERIALS, f); int n, numresults = report_resources(r, result, MAX_RAWMATERIALS, f, true);
for (n = 0; n < numresults; ++n) { for (n = 0; n < numresults; ++n) {
if (result[n].number >= 0 && result[n].level >= 0) { if (result[n].number >= 0 && result[n].level >= 0) {
@ -1044,7 +1045,7 @@ static void describe(stream *out, const region * r, faction * f)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
} }
if (rmoney(r) && sr->mode >= see_travel) { if (rmoney(r) && r->seen.mode >= seen_travel) {
bytes = _snprintf(bufp, size, ", %d ", rmoney(r)); bytes = _snprintf(bufp, size, ", %d ", rmoney(r));
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
@ -1189,7 +1190,7 @@ static void describe(stream *out, const region * r, faction * f)
*bufp = 0; *bufp = 0;
paragraph(out, buf, 0, 0, 0); paragraph(out, buf, 0, 0, 0);
if (sr->mode == see_unit && is_astral(r) && if (r->seen.mode == seen_unit && is_astral(r) &&
!is_cursed(r->attribs, C_ASTRALBLOCK, 0)) { !is_cursed(r->attribs, C_ASTRALBLOCK, 0)) {
/* Sonderbehandlung Teleport-Ebene */ /* Sonderbehandlung Teleport-Ebene */
region_list *rl = astralregions(r, inhabitable); region_list *rl = astralregions(r, inhabitable);
@ -1392,7 +1393,6 @@ report_template(const char *filename, report_context * ctx, const char *charset)
region *r; region *r;
FILE *F = fopen(filename, "w"); FILE *F = fopen(filename, "w");
stream strm = { 0 }, *out = &strm; stream strm = { 0 }, *out = &strm;
seen_region *sr = NULL;
char buf[8192], *bufp; char buf[8192], *bufp;
size_t size; size_t size;
int bytes; int bytes;
@ -1424,16 +1424,11 @@ report_template(const char *filename, report_context * ctx, const char *charset)
rps_nowrap(out, buf); rps_nowrap(out, buf);
newline(out); newline(out);
for (r = ctx->first; sr == NULL && r != ctx->last; r = r->next) { for (r = ctx->first; r != ctx->last; r = r->next) {
sr = find_seen(ctx->f->seen, r);
}
for (; sr != NULL; sr = sr->next) {
region *r = sr->r;
unit *u; unit *u;
int dh = 0; int dh = 0;
if (sr->mode < see_unit) if (r->seen.mode < seen_unit)
continue; continue;
for (u = r->units; u; u = u->next) { for (u = r->units; u; u = u->next) {
@ -1778,10 +1773,9 @@ static void list_address(stream *out, const faction * uf, quicklist * seenfactio
} }
static void static void
nr_ship(stream *out, const seen_region * sr, const ship * sh, const faction * f, nr_ship(stream *out, const region *r, const ship * sh, const faction * f,
const unit * captain) const unit * captain)
{ {
const region *r = sr->r;
char buffer[8192], *bufp = buffer; char buffer[8192], *bufp = buffer;
size_t size = sizeof(buffer) - 1; size_t size = sizeof(buffer) - 1;
int bytes; int bytes;
@ -1852,8 +1846,7 @@ const unit * captain)
} }
static void static void
nr_building(stream *out, const seen_region * sr, const building * b, nr_building(stream *out, const region *r, const building *b, const faction *f)
const faction * f)
{ {
int i, bytes; int i, bytes;
const char *name, *bname, *billusion = NULL; const char *name, *bname, *billusion = NULL;
@ -1893,7 +1886,7 @@ const faction * f)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
if (b->besieged > 0 && sr->mode >= see_lighthouse) { if (b->besieged > 0 && r->seen.mode >= seen_lighthouse) {
msg = msg_message("nr_building_besieged", "soldiers diff", b->besieged, msg = msg_message("nr_building_besieged", "soldiers diff", b->besieged,
b->besieged - b->size * SIEGEFACTOR); b->besieged - b->size * SIEGEFACTOR);
bytes = (int)nr_render(msg, lang, bufp, size, f); bytes = (int)nr_render(msg, lang, bufp, size, f);
@ -1920,12 +1913,10 @@ const faction * f)
*bufp = 0; *bufp = 0;
paragraph(out, buffer, 2, 0, 0); paragraph(out, buffer, 2, 0, 0);
if (sr->mode < see_lighthouse) if (r->seen.mode >= seen_lighthouse) {
return;
i = 0;
nr_curses(out, 4, f, TYP_BUILDING, b); nr_curses(out, 4, f, TYP_BUILDING, b);
} }
}
static void nr_paragraph(stream *out, message * m, faction * f) static void nr_paragraph(stream *out, message * m, faction * f)
{ {
@ -1960,7 +1951,7 @@ static void init_cb(cb_data *data, stream *out, char *buffer, size_t size, const
data->counter = 0; data->counter = 0;
} }
static void cb_write_travelthru(region *r, unit *u, void *cbdata) { static void cb_write_travelthru(const region *r, unit *u, void *cbdata) {
cb_data *data = (cb_data *)cbdata; cb_data *data = (cb_data *)cbdata;
const faction *f = data->f; const faction *f = data->f;
@ -2015,7 +2006,7 @@ static void cb_write_travelthru(region *r, unit *u, void *cbdata) {
} }
} }
void write_travelthru(stream *out, region * r, const faction * f) void write_travelthru(stream *out, const region *r, const faction *f)
{ {
int maxtravel; int maxtravel;
char buf[8192]; char buf[8192];
@ -2058,7 +2049,6 @@ const char *charset)
int wants_stats = (f->options & ix); int wants_stats = (f->options & ix);
FILE *F = fopen(filename, "w"); FILE *F = fopen(filename, "w");
stream strm = { 0 }, *out = &strm; stream strm = { 0 }, *out = &strm;
seen_region *sr = NULL;
char buf[8192]; char buf[8192];
char *bufp; char *bufp;
bool utf8 = _strcmpl(charset, "utf8") == 0 || _strcmpl(charset, "utf-8") == 0; bool utf8 = _strcmpl(charset, "utf8") == 0 || _strcmpl(charset, "utf-8") == 0;
@ -2286,22 +2276,18 @@ const char *charset)
CHECK_ERRNO(); CHECK_ERRNO();
anyunits = 0; anyunits = 0;
for (r = ctx->first; sr == NULL && r != ctx->last; r = r->next) { for (r = ctx->first; r != ctx->last; r = r->next) {
sr = find_seen(ctx->f->seen, r); int stealthmod = stealth_modifier(r->seen.mode);
}
for (; sr != NULL; sr = sr->next) {
region *r = sr->r;
int stealthmod = stealth_modifier(sr->mode);
building *b = r->buildings; building *b = r->buildings;
ship *sh = r->ships; ship *sh = r->ships;
if (sr->mode < see_lighthouse) if (r->seen.mode < seen_lighthouse)
continue; continue;
/* Beschreibung */ /* Beschreibung */
if (sr->mode == see_unit) { if (r->seen.mode == seen_unit) {
anyunits = 1; anyunits = 1;
describe(out, sr, f); describe(out, r, f);
if (markets_module() && r->land) { if (markets_module() && r->land) {
const item_type *lux = r_luxury(r); const item_type *lux = r_luxury(r);
const item_type *herb = r->land->herbtype; const item_type *herb = r->land->herbtype;
@ -2331,27 +2317,27 @@ const char *charset)
write_travelthru(out, r, f); write_travelthru(out, r, f);
} }
else { else {
if (sr->mode == see_far) { if (r->seen.mode == seen_far) {
describe(out, sr, f); describe(out, r, f);
newline(out); newline(out);
guards(out, r, f); guards(out, r, f);
newline(out); newline(out);
write_travelthru(out, r, f); write_travelthru(out, r, f);
} }
else { else {
describe(out, sr, f); describe(out, r, f);
newline(out); newline(out);
write_travelthru(out, r, f); write_travelthru(out, r, f);
} }
} }
/* Statistik */ /* Statistik */
if (wants_stats && sr->mode == see_unit) if (wants_stats && r->seen.mode == seen_unit)
statistics(out, r, f); statistics(out, r, f);
/* Nachrichten an REGION in der Region */ /* Nachrichten an REGION in der Region */
if (sr->mode == see_unit || sr->mode == see_travel) { if (r->seen.mode == seen_unit || r->seen.mode == seen_travel) {
// TODO: Bug 2073 // TODO: Bug 2073
message_list *mlist = r_getmessages(r, f); message_list *mlist = r_getmessages(r, f);
if (mlist) { if (mlist) {
@ -2368,13 +2354,13 @@ const char *charset)
u = r->units; u = r->units;
while (b) { while (b) {
while (b && (!u || u->building != b)) { while (b && (!u || u->building != b)) {
nr_building(out, sr, b, f); nr_building(out, r, b, f);
b = b->next; b = b->next;
} }
if (b) { if (b) {
nr_building(out, sr, b, f); nr_building(out, r, b, f);
while (u && u->building == b) { while (u && u->building == b) {
nr_unit(out, f, u, 6, sr->mode); nr_unit(out, f, u, 6, r->seen.mode);
u = u->next; u = u->next;
} }
b = b->next; b = b->next;
@ -2383,7 +2369,7 @@ const char *charset)
while (u && !u->ship) { while (u && !u->ship) {
if (stealthmod > INT_MIN) { if (stealthmod > INT_MIN) {
if (u->faction == f || cansee(f, r, u, stealthmod)) { if (u->faction == f || cansee(f, r, u, stealthmod)) {
nr_unit(out, f, u, 4, sr->mode); nr_unit(out, f, u, 4, r->seen.mode);
} }
} }
assert(!u->building); assert(!u->building);
@ -2391,13 +2377,13 @@ const char *charset)
} }
while (sh) { while (sh) {
while (sh && (!u || u->ship != sh)) { while (sh && (!u || u->ship != sh)) {
nr_ship(out, sr, sh, f, NULL); nr_ship(out, r, sh, f, NULL);
sh = sh->next; sh = sh->next;
} }
if (sh) { if (sh) {
nr_ship(out, sr, sh, f, u); nr_ship(out, r, sh, f, u);
while (u && u->ship == sh) { while (u && u->ship == sh) {
nr_unit(out, f, u, 6, sr->mode); nr_unit(out, f, u, 6, r->seen.mode);
u = u->next; u = u->next;
} }
sh = sh->next; sh = sh->next;

View File

@ -971,7 +971,7 @@ typedef struct address_data {
int stealthmod; int stealthmod;
} address_data; } address_data;
static void cb_add_address(region *r, unit *ut, void *cbdata) { static void cb_add_address(const region *r, unit *ut, void *cbdata) {
address_data *data = (address_data *)cbdata; address_data *data = (address_data *)cbdata;
faction *f = data->f; faction *f = data->f;
@ -1378,8 +1378,9 @@ static region *firstregion(faction * f)
#endif #endif
} }
static void cb_add_seen(region *r, unit *u, void *cbdata) { static void cb_add_seen(const region *rc, unit *u, void *cbdata) {
unused_arg(cbdata); region *r = (region *)cbdata;
assert(rc == r);
faction_add_seen(u->faction, r, seen_travel); faction_add_seen(u->faction, r, seen_travel);
} }
@ -1444,7 +1445,7 @@ void prepare_report(report_context *ctx, faction *f)
} }
if (fval(r, RF_TRAVELUNIT)) { if (fval(r, RF_TRAVELUNIT)) {
travelthru_map(r, cb_add_seen, ctx); travelthru_map(r, cb_add_seen, r);
} }
} }
// [fast,last) interval of seen regions (with lighthouses and travel) // [fast,last) interval of seen regions (with lighthouses and travel)
@ -2147,7 +2148,7 @@ typedef struct count_data {
const struct faction *f; const struct faction *f;
} count_data; } count_data;
static void count_cb(region *r, unit *u, void *cbdata) { static void count_cb(const region *r, unit *u, void *cbdata) {
count_data *data = (count_data *)cbdata; count_data *data = (count_data *)cbdata;
const struct faction *f = data->f; const struct faction *f = data->f;
if (r != u->region && (!u->ship || ship_owner(u->ship) == u)) { if (r != u->region && (!u->ship || ship_owner(u->ship) == u)) {
@ -2157,7 +2158,7 @@ static void count_cb(region *r, unit *u, void *cbdata) {
} }
} }
int count_travelthru(struct region *r, const struct faction *f) { int count_travelthru(const struct region *r, const struct faction *f) {
count_data data = { 0 }; count_data data = { 0 };
data.f = f; data.f = f;
travelthru_map(r, count_cb, &data); travelthru_map(r, count_cb, &data);

View File

@ -125,7 +125,7 @@ extern "C" {
int stream_printf(struct stream * out, const char *format, ...); int stream_printf(struct stream * out, const char *format, ...);
int count_travelthru(struct region *r, const struct faction *f); int count_travelthru(const struct region *r, const struct faction *f);
#define GR_PLURAL 0x01 /* grammar: plural */ #define GR_PLURAL 0x01 /* grammar: plural */
#define MAX_INVENTORY 128 /* maimum number of different items in an inventory */ #define MAX_INVENTORY 128 /* maimum number of different items in an inventory */

View File

@ -95,7 +95,7 @@ bool travelthru_cansee(const struct region *r, const struct faction *f, const st
return false; return false;
} }
void travelthru_map(region * r, void(*cb)(region *, struct unit *, void *), void *cbdata) void travelthru_map(const region * r, void(*cb)(const region *, struct unit *, void *), void *cbdata)
{ {
attrib *a; attrib *a;
assert(r); assert(r);

View File

@ -11,7 +11,7 @@ extern "C" {
struct region; struct region;
struct faction; struct faction;
struct unit; struct unit;
void travelthru_map(struct region * r, void(*cb)(struct region *r, struct unit *, void *), void *cbdata); void travelthru_map(const struct region * r, void(*cb)(const struct region *r, struct unit *, void *), void *cbdata);
bool travelthru_cansee(const struct region *r, const struct faction *f, const struct unit *u); bool travelthru_cansee(const struct region *r, const struct faction *f, const struct unit *u);
void travelthru_add(struct region * r, struct unit * u); void travelthru_add(struct region * r, struct unit * u);

View File

@ -13,7 +13,7 @@
struct attrib; struct attrib;
static void count_travelers(region *r, unit *u, void *cbdata) { static void count_travelers(const region *r, unit *u, void *cbdata) {
int *n = (int *)cbdata; int *n = (int *)cbdata;
unused_arg(r); unused_arg(r);
*n += u->number; *n += u->number;