diff --git a/src/creport.c b/src/creport.c index 1678d5d47..34ff6c843 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1343,7 +1343,7 @@ static void cr_output_region(FILE * F, report_context * ctx, seen_region * sr) if (sr->mode != see_unit) fprintf(F, "\"%s\";visibility\n", visibility[sr->mode]); if (sr->mode == see_neighbour) { - cr_borders(ctx->seen, r, f, sr->mode, F); + cr_borders(ctx->f->seen, r, f, sr->mode, F); } else { building *b; @@ -1431,7 +1431,7 @@ static void cr_output_region(FILE * F, report_context * ctx, seen_region * sr) print_items(F, r->land->items, f->locale); } cr_output_curses_compat(F, f, r, TYP_REGION); - cr_borders(ctx->seen, r, f, sr->mode, F); + cr_borders(ctx->f->seen, r, f, sr->mode, F); if (sr->mode == see_unit && is_astral(r) && !is_cursed(r->attribs, C_ASTRALBLOCK, 0)) { /* Sonderbehandlung Teleport-Ebene */ @@ -1686,7 +1686,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset) /* traverse all regions */ for (r = ctx->first; sr == NULL && r != ctx->last; r = r->next) { - sr = find_seen(ctx->seen, r); + sr = find_seen(ctx->f->seen, r); } for (; sr != NULL; sr = sr->next) { cr_output_region(F, ctx, sr); diff --git a/src/jsreport.c b/src/jsreport.c index 44f015053..56e94ab8b 100644 --- a/src/jsreport.c +++ b/src/jsreport.c @@ -1,5 +1,6 @@ #include "reports.h" #include "jsreport.h" +#include #include #include #include @@ -31,7 +32,7 @@ static int report_json(const char *filename, report_context * ctx, const char *c region *r; /* traverse all regions */ for (sr = NULL, r = ctx->first; sr == NULL && r != ctx->last; r = r->next) { - sr = find_seen(ctx->seen, r); + sr = find_seen(ctx->f->seen, r); } for (; sr != NULL; sr = sr->next) { int tx = sr->r->x; @@ -55,7 +56,7 @@ static int report_json(const char *filename, report_context * ctx, const char *c coor_from_tiled(&tx, &ty); r = findregion(tx, ty); if (r) { - sr = find_seen(ctx->seen, r); + sr = find_seen(ctx->f->seen, r); if (sr) { terrain_t ter = oldterrain(r->terrain); if (ter == NOTERRAIN) { diff --git a/src/report.c b/src/report.c index 039dc8353..9d3c8a191 100644 --- a/src/report.c +++ b/src/report.c @@ -1412,7 +1412,7 @@ report_template(const char *filename, report_context * ctx, const char *charset) newline(out); for (r = ctx->first; sr == NULL && r != ctx->last; r = r->next) { - sr = find_seen(ctx->seen, r); + sr = find_seen(ctx->f->seen, r); } for (; sr != NULL; sr = sr->next) { @@ -2306,7 +2306,7 @@ const char *charset) anyunits = 0; for (r = ctx->first; sr == NULL && r != ctx->last; r = r->next) { - sr = find_seen(ctx->seen, r); + sr = find_seen(ctx->f->seen, r); } for (; sr != NULL; sr = sr->next) { region *r = sr->r; diff --git a/src/reports.c b/src/reports.c index 58b6144e3..b5cccbab3 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1038,7 +1038,7 @@ static void get_addresses(report_context * ctx) /* find the first region that this faction can see */ for (r = ctx->first; sr == NULL && r != ctx->last; r = r->next) { - sr = find_seen(ctx->seen, r); + sr = find_seen(ctx->f->seen, r); } for (; sr != NULL; sr = sr->next) { @@ -1166,9 +1166,9 @@ static void get_seen_interval(report_context * ctx) * which may well be outside of [firstregion, lastregion) */ int i; - assert(ctx->seen); + assert(ctx->f->seen); for (i = 0; i != MAXSEEHASH; ++i) { - seen_region *sr = ctx->seen[i]; + seen_region *sr = ctx->f->seen[i]; while (sr != NULL) { if (ctx->first == NULL || sr->r->index < ctx->first->index) { ctx->first = sr->r; @@ -1179,7 +1179,7 @@ static void get_seen_interval(report_context * ctx) sr = sr->nextHash; } } - link_seen(ctx->seen, ctx->first, ctx->last); + link_seen(ctx->f->seen, ctx->first, ctx->last); } bool @@ -1624,15 +1624,19 @@ static region *firstregion(faction * f) #endif } -static seen_region **prepare_report(faction * f) +static void prepare_report(struct report_context *ctx, faction *f) { + region *r; struct seen_region *sr; - region *r = firstregion(f); - region *last = lastregion(f); - link_seen(f->seen, r, last); + ctx->f = f; + ctx->report_time = time(NULL); + ctx->first = firstregion(f); + ctx->last = lastregion(f); + ctx->addresses = NULL; + ctx->userdata = NULL; - for (sr = NULL; sr == NULL && r != last; r = r->next) { + for (r = ctx->first, sr = NULL; sr == NULL && r != ctx->last; r = r->next) { sr = find_seen(f->seen, r); } @@ -1649,7 +1653,7 @@ static seen_region **prepare_report(faction * f) view(f->seen, r, f); } } - return f->seen; + get_seen_interval(ctx); } int write_reports(faction * f, time_t ltime) @@ -1663,16 +1667,7 @@ int write_reports(faction * f, time_t ltime) if (noreports) { return false; } - ctx.f = f; - ctx.report_time = time(NULL); - ctx.seen = prepare_report(f); - ctx.first = firstregion(f); - ctx.last = lastregion(f); - ctx.addresses = NULL; - ctx.userdata = NULL; - if (ctx.seen) { - get_seen_interval(&ctx); - } + prepare_report(&ctx, f); get_addresses(&ctx); if (_access(reportpath(), 0) < 0) { _mkdir(reportpath()); @@ -1714,8 +1709,8 @@ int write_reports(faction * f, time_t ltime) log_warning("No report for faction %s!", factionid(f)); } ql_free(ctx.addresses); - if (ctx.seen) { - seen_done(ctx.seen); + if (ctx.f->seen) { + seen_done(ctx.f->seen); } return 0; } diff --git a/src/reports.h b/src/reports.h index c72cebab1..f0e666ad1 100644 --- a/src/reports.h +++ b/src/reports.h @@ -96,7 +96,6 @@ extern "C" { typedef struct report_context { struct faction *f; struct quicklist *addresses; - struct seen_region **seen; struct region *first, *last; void *userdata; time_t report_time;