forked from github/server
re-enable report writing, fix report.c to work without seen_region
This commit is contained in:
parent
007f4d8b0d
commit
d449ce4a8c
|
@ -105,7 +105,7 @@ set (ERESSEA_SRC
|
|||
skill.c
|
||||
json.c
|
||||
# creport.c
|
||||
# report.c
|
||||
report.c
|
||||
economy.c
|
||||
give.c
|
||||
items.c
|
||||
|
@ -200,7 +200,7 @@ set(TESTS_SRC
|
|||
volcano.test.c
|
||||
reports.test.c
|
||||
# creport.test.c
|
||||
# report.test.c
|
||||
report.test.c
|
||||
summary.test.c
|
||||
travelthru.test.c
|
||||
callback.test.c
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "chaos.h"
|
||||
#include "items.h"
|
||||
//#include "creport.h"
|
||||
//#include "report.h"
|
||||
#include "report.h"
|
||||
#include "names.h"
|
||||
#include "reports.h"
|
||||
#include "spells.h"
|
||||
|
@ -64,7 +64,7 @@ void game_init(void)
|
|||
register_triggers();
|
||||
register_xmas();
|
||||
|
||||
// register_nr();
|
||||
register_nr();
|
||||
// register_cr();
|
||||
|
||||
register_races();
|
||||
|
|
|
@ -697,13 +697,11 @@ void r_setdemand(region * r, const luxury_type * ltype, int value)
|
|||
d->value = value;
|
||||
}
|
||||
|
||||
const item_type *r_luxury(region * r)
|
||||
const item_type *r_luxury(const region * r)
|
||||
{
|
||||
struct demand *dmd;
|
||||
if (r->land) {
|
||||
if (!r->land->demands) {
|
||||
fix_demand(r);
|
||||
}
|
||||
assert(r->land->demands || !"need to call fix_demands on a region");
|
||||
for (dmd = r->land->demands; dmd; dmd = dmd->next) {
|
||||
if (dmd->value == 0)
|
||||
return dmd->type->itype;
|
||||
|
|
|
@ -274,7 +274,7 @@ extern "C" {
|
|||
int value);
|
||||
int owner_change(const region * r);
|
||||
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);
|
||||
|
||||
struct faction *update_owners(struct region *r);
|
||||
|
|
86
src/report.c
86
src/report.c
|
@ -21,6 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
|
||||
#include "report.h"
|
||||
#include "reports.h"
|
||||
#include "laws.h"
|
||||
#include "travelthru.h"
|
||||
|
@ -937,14 +938,14 @@ static void describe(stream *out, const region * r, faction * f)
|
|||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
|
||||
if (sr->mode == see_travel) {
|
||||
bytes = _snprintf(bufp, size, " (%s)", LOC(f->locale, "see_travel"));
|
||||
if (r->seen.mode == seen_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"));
|
||||
}
|
||||
else if (sr->mode == see_lighthouse) {
|
||||
bytes = _snprintf(bufp, size, " (%s)", LOC(f->locale, "see_lighthouse"));
|
||||
else if (r->seen.mode == seen_lighthouse) {
|
||||
bytes = _snprintf(bufp, size, " (%s)", LOC(f->locale, "seen_lighthouse"));
|
||||
}
|
||||
else {
|
||||
bytes = 0;
|
||||
|
@ -991,9 +992,9 @@ static void describe(stream *out, const region * r, faction * f)
|
|||
}
|
||||
|
||||
/* iron & stone */
|
||||
if (sr->mode == see_unit) {
|
||||
if (r->seen.mode == seen_unit) {
|
||||
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) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
if (rmoney(r) && sr->mode >= see_travel) {
|
||||
if (rmoney(r) && r->seen.mode >= seen_travel) {
|
||||
bytes = _snprintf(bufp, size, ", %d ", rmoney(r));
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
|
@ -1189,7 +1190,7 @@ static void describe(stream *out, const region * r, faction * f)
|
|||
*bufp = 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)) {
|
||||
/* Sonderbehandlung Teleport-Ebene */
|
||||
region_list *rl = astralregions(r, inhabitable);
|
||||
|
@ -1392,7 +1393,6 @@ report_template(const char *filename, report_context * ctx, const char *charset)
|
|||
region *r;
|
||||
FILE *F = fopen(filename, "w");
|
||||
stream strm = { 0 }, *out = &strm;
|
||||
seen_region *sr = NULL;
|
||||
char buf[8192], *bufp;
|
||||
size_t size;
|
||||
int bytes;
|
||||
|
@ -1424,16 +1424,11 @@ report_template(const char *filename, report_context * ctx, const char *charset)
|
|||
rps_nowrap(out, buf);
|
||||
newline(out);
|
||||
|
||||
for (r = ctx->first; sr == NULL && r != ctx->last; r = r->next) {
|
||||
sr = find_seen(ctx->f->seen, r);
|
||||
}
|
||||
|
||||
for (; sr != NULL; sr = sr->next) {
|
||||
region *r = sr->r;
|
||||
for (r = ctx->first; r != ctx->last; r = r->next) {
|
||||
unit *u;
|
||||
int dh = 0;
|
||||
|
||||
if (sr->mode < see_unit)
|
||||
if (r->seen.mode < seen_unit)
|
||||
continue;
|
||||
|
||||
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
|
||||
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 region *r = sr->r;
|
||||
char buffer[8192], *bufp = buffer;
|
||||
size_t size = sizeof(buffer) - 1;
|
||||
int bytes;
|
||||
|
@ -1852,8 +1846,7 @@ const unit * captain)
|
|||
}
|
||||
|
||||
static void
|
||||
nr_building(stream *out, const seen_region * sr, const building * b,
|
||||
const faction * f)
|
||||
nr_building(stream *out, const region *r, const building *b, const faction *f)
|
||||
{
|
||||
int i, bytes;
|
||||
const char *name, *bname, *billusion = NULL;
|
||||
|
@ -1893,7 +1886,7 @@ const faction * f)
|
|||
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,
|
||||
b->besieged - b->size * SIEGEFACTOR);
|
||||
bytes = (int)nr_render(msg, lang, bufp, size, f);
|
||||
|
@ -1920,12 +1913,10 @@ const faction * f)
|
|||
*bufp = 0;
|
||||
paragraph(out, buffer, 2, 0, 0);
|
||||
|
||||
if (sr->mode < see_lighthouse)
|
||||
return;
|
||||
|
||||
i = 0;
|
||||
if (r->seen.mode >= seen_lighthouse) {
|
||||
nr_curses(out, 4, f, TYP_BUILDING, b);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
char buf[8192];
|
||||
|
@ -2058,7 +2049,6 @@ const char *charset)
|
|||
int wants_stats = (f->options & ix);
|
||||
FILE *F = fopen(filename, "w");
|
||||
stream strm = { 0 }, *out = &strm;
|
||||
seen_region *sr = NULL;
|
||||
char buf[8192];
|
||||
char *bufp;
|
||||
bool utf8 = _strcmpl(charset, "utf8") == 0 || _strcmpl(charset, "utf-8") == 0;
|
||||
|
@ -2286,22 +2276,18 @@ const char *charset)
|
|||
CHECK_ERRNO();
|
||||
anyunits = 0;
|
||||
|
||||
for (r = ctx->first; sr == NULL && r != ctx->last; r = r->next) {
|
||||
sr = find_seen(ctx->f->seen, r);
|
||||
}
|
||||
for (; sr != NULL; sr = sr->next) {
|
||||
region *r = sr->r;
|
||||
int stealthmod = stealth_modifier(sr->mode);
|
||||
for (r = ctx->first; r != ctx->last; r = r->next) {
|
||||
int stealthmod = stealth_modifier(r->seen.mode);
|
||||
building *b = r->buildings;
|
||||
ship *sh = r->ships;
|
||||
|
||||
if (sr->mode < see_lighthouse)
|
||||
if (r->seen.mode < seen_lighthouse)
|
||||
continue;
|
||||
/* Beschreibung */
|
||||
|
||||
if (sr->mode == see_unit) {
|
||||
if (r->seen.mode == seen_unit) {
|
||||
anyunits = 1;
|
||||
describe(out, sr, f);
|
||||
describe(out, r, f);
|
||||
if (markets_module() && r->land) {
|
||||
const item_type *lux = r_luxury(r);
|
||||
const item_type *herb = r->land->herbtype;
|
||||
|
@ -2331,27 +2317,27 @@ const char *charset)
|
|||
write_travelthru(out, r, f);
|
||||
}
|
||||
else {
|
||||
if (sr->mode == see_far) {
|
||||
describe(out, sr, f);
|
||||
if (r->seen.mode == seen_far) {
|
||||
describe(out, r, f);
|
||||
newline(out);
|
||||
guards(out, r, f);
|
||||
newline(out);
|
||||
write_travelthru(out, r, f);
|
||||
}
|
||||
else {
|
||||
describe(out, sr, f);
|
||||
describe(out, r, f);
|
||||
newline(out);
|
||||
write_travelthru(out, r, f);
|
||||
}
|
||||
}
|
||||
/* Statistik */
|
||||
|
||||
if (wants_stats && sr->mode == see_unit)
|
||||
if (wants_stats && r->seen.mode == seen_unit)
|
||||
statistics(out, r, f);
|
||||
|
||||
/* 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
|
||||
message_list *mlist = r_getmessages(r, f);
|
||||
if (mlist) {
|
||||
|
@ -2368,13 +2354,13 @@ const char *charset)
|
|||
u = r->units;
|
||||
while (b) {
|
||||
while (b && (!u || u->building != b)) {
|
||||
nr_building(out, sr, b, f);
|
||||
nr_building(out, r, b, f);
|
||||
b = b->next;
|
||||
}
|
||||
if (b) {
|
||||
nr_building(out, sr, b, f);
|
||||
nr_building(out, r, b, f);
|
||||
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;
|
||||
}
|
||||
b = b->next;
|
||||
|
@ -2383,7 +2369,7 @@ const char *charset)
|
|||
while (u && !u->ship) {
|
||||
if (stealthmod > INT_MIN) {
|
||||
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);
|
||||
|
@ -2391,13 +2377,13 @@ const char *charset)
|
|||
}
|
||||
while (sh) {
|
||||
while (sh && (!u || u->ship != sh)) {
|
||||
nr_ship(out, sr, sh, f, NULL);
|
||||
nr_ship(out, r, sh, f, NULL);
|
||||
sh = sh->next;
|
||||
}
|
||||
if (sh) {
|
||||
nr_ship(out, sr, sh, f, u);
|
||||
nr_ship(out, r, sh, f, u);
|
||||
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;
|
||||
}
|
||||
sh = sh->next;
|
||||
|
|
|
@ -971,7 +971,7 @@ typedef struct address_data {
|
|||
int stealthmod;
|
||||
} 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;
|
||||
faction *f = data->f;
|
||||
|
||||
|
@ -1378,8 +1378,9 @@ static region *firstregion(faction * f)
|
|||
#endif
|
||||
}
|
||||
|
||||
static void cb_add_seen(region *r, unit *u, void *cbdata) {
|
||||
unused_arg(cbdata);
|
||||
static void cb_add_seen(const region *rc, unit *u, void *cbdata) {
|
||||
region *r = (region *)cbdata;
|
||||
assert(rc == r);
|
||||
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)) {
|
||||
travelthru_map(r, cb_add_seen, ctx);
|
||||
travelthru_map(r, cb_add_seen, r);
|
||||
}
|
||||
}
|
||||
// [fast,last) interval of seen regions (with lighthouses and travel)
|
||||
|
@ -2147,7 +2148,7 @@ typedef struct count_data {
|
|||
const struct faction *f;
|
||||
} 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;
|
||||
const struct faction *f = data->f;
|
||||
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 };
|
||||
data.f = f;
|
||||
travelthru_map(r, count_cb, &data);
|
||||
|
|
|
@ -125,7 +125,7 @@ extern "C" {
|
|||
|
||||
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 MAX_INVENTORY 128 /* maimum number of different items in an inventory */
|
||||
|
|
|
@ -95,7 +95,7 @@ bool travelthru_cansee(const struct region *r, const struct faction *f, const st
|
|||
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;
|
||||
assert(r);
|
||||
|
|
|
@ -11,7 +11,7 @@ extern "C" {
|
|||
struct region;
|
||||
struct faction;
|
||||
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);
|
||||
void travelthru_add(struct region * r, struct unit * u);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
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;
|
||||
unused_arg(r);
|
||||
*n += u->number;
|
||||
|
|
Loading…
Reference in New Issue