diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index 72f5d0036..e31ccbc81 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -1085,7 +1085,6 @@ report_computer(const char * filename, report_context * ctx) ship *sh; unit *u; const char * mailto = locale_string(f->locale, "mailto"); - region * first = firstregion(f), * last = lastregion(f); const attrib * a; #ifdef SCORE_MODULE int score = 0, avgscore = 0; @@ -1097,7 +1096,6 @@ report_computer(const char * filename, report_context * ctx) } /* must call this to get all the neighbour regions */ - get_seen_interval(ctx->seen, &first, &last); /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ /* initialisations, header and lists */ @@ -1234,7 +1232,7 @@ report_computer(const char * filename, report_context * ctx) } /* traverse all regions */ - for (r=first;r!=last;r=r->next) { + for (r=ctx->first;r!=ctx->last;r=r->next) { int modifier = 0; const char * tname; const seen_region * sd = find_seen(ctx->seen, r); diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index bb9d9e9b9..513e683f5 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -1902,7 +1902,6 @@ report_plaintext(const char * filename, report_context * ctx) attrib *a; message * m; unsigned char op; - region * last = lastregion(f); int ix = Pow(O_STATISTICS); int wants_stats = (f->options & ix); FILE * F = fopen(filename, "wt"); @@ -2074,10 +2073,8 @@ report_plaintext(const char * filename, report_context * ctx) rnl(F); centre(F, buf, true); } - /* Der Report soll später einmal durch einen Makroprozessor laufen. - * (enno) was? wer hat das geschrieben? - * Momentan ist das wegen der der Mailverschickmimik schwierig. */ - rp_messages(F, f->msgs, f, 0, true, true); + + rp_messages(F, f->msgs, f, 0, true, true); rp_battles(F, f); a = a_find(f->attribs, &at_reportspell); if (a) { @@ -2137,7 +2134,7 @@ report_plaintext(const char * filename, report_context * ctx) anyunits = 0; - for (r=firstregion(f);r!=last;r=r->next) { + for (r=ctx->first;r!=ctx->last;r=r->next) { boolean unit_in_region = false; boolean durchgezogen_in_region = false; int turm_sieht_region = false; diff --git a/src/common/gamecode/xmlreport.c b/src/common/gamecode/xmlreport.c index ba7db7d3f..398bb8d5c 100644 --- a/src/common/gamecode/xmlreport.c +++ b/src/common/gamecode/xmlreport.c @@ -148,13 +148,12 @@ report_xml(const char * filename, report_context * ctx) xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); xmlNodePtr xmlReport = xmlNewNode(NULL, BAD_CAST "report"); const faction_list * address; - region * r = firstregion(ctx->f), * rend = lastregion(ctx->f); + region * r = ctx->first, * rend = ctx->last; for (address=ctx->addresses;address;address=address->next) { xmlAddChild(xmlReport, report_faction(ctx, address->data)); } - get_seen_interval(ctx->seen, &r, &rend); for (;r!=rend;r=r->next) { seen_region * sr = find_seen(ctx->seen, r); if (sr!=NULL) xmlAddChild(xmlReport, report_region(ctx, sr)); diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index 6372d8824..1a7008473 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -2117,28 +2117,17 @@ lastregion (faction * f) /* it is safe to start in the region of the first unit. */ f->last = u->region; -#ifdef ENUM_REGIONS /* if regions have indices, we can skip ahead: */ for (u=u->nextF; u!=NULL; u=u->nextF) { r = u->region; if (r->index > f->last->index) f->last = r; } -#endif + /* we continue from the best region and look for travelthru etc. */ for (r = f->last->next; r; r = r->next) { plane * p = rplane(r); attrib *ru; -#ifndef ENUM_REGIONS - /* for index-regions we don't need this, we already did it earlier */ - for (u = r->units; u; u = u->next) { - if (u->faction == f) { - f->last = r; - break; - } - } - if (f->last == r) continue; -#endif /* search the region for travelthru-attributes: */ if (fval(r, RF_TRAVELUNIT)) { for (ru = a_find(r->attribs, &at_travelunit); ru; ru = ru->nexttype) { @@ -2171,34 +2160,6 @@ firstregion (faction * f) if (f->units==NULL) return NULL; if (r!=NULL) return r; -#ifndef ENUM_REGIONS - for (r = regions; r; r = r->next) { - attrib *ru; - unit *u; - plane * p = rplane(r); - for (u = r->units; u; u = u->next) { - if (u->faction == f) { - return f->first = r; - } - } - if (f->first == r->next) - continue; - if (fval(r, RF_TRAVELUNIT)) { - for (ru = a_find(r->attribs, &at_travelunit); ru; ru = ru->nexttype) { - u = (unit*)ru->data.v; - if (u->faction == f) { - return f->first = r; - } - } - } - if (check_leuchtturm(r, f)) { - return f->first = r; - } - if (p && is_watcher(p, f)) { - return f->first = r; - } - } -#endif return f->first = regions; #else return regions; diff --git a/src/common/kernel/faction.c b/src/common/kernel/faction.c index 152768395..80e7470ec 100644 --- a/src/common/kernel/faction.c +++ b/src/common/kernel/faction.c @@ -328,17 +328,12 @@ void update_interval(struct faction * f, struct region * r) { if (r==NULL || f==NULL) return; -#ifdef ENUM_REGIONS if (f->first==NULL || f->first->index>r->index) { f->first = r; } if (f->last==NULL || f->last->index<=r->index) { f->last = r; } -#else - f->first = 0; - f->last = 0; -#endif } #endif diff --git a/src/common/kernel/region.c b/src/common/kernel/region.c index 16f5c3487..1f460de09 100644 --- a/src/common/kernel/region.c +++ b/src/common/kernel/region.c @@ -718,9 +718,8 @@ rsettrees(const region *r, int ageclass, int value) static region *last; -#ifdef ENUM_REGIONS static unsigned int max_index = 0; -#endif + region * new_region(short x, short y) { @@ -744,10 +743,8 @@ new_region(short x, short y) else addlist(®ions, r); last = r; -#ifdef ENUM_REGIONS assert(r->next==NULL); r->index = ++max_index; -#endif return r; } diff --git a/src/common/kernel/region.h b/src/common/kernel/region.h index f54667e10..c588d34e4 100644 --- a/src/common/kernel/region.h +++ b/src/common/kernel/region.h @@ -25,11 +25,6 @@ extern "C" { a hash-access each time a neighbour is needed */ #define FAST_CONNECT -/* ENUM_REGIONS: regions have an ascending number, to improve the speed of - determining the interval in which a faction has its units. See the - implementations of firstregion and lastregion */ -#define ENUM_REGIONS - #define RF_CHAOTIC (1<<0) #define RF_MALLORN (1<<1) #define RF_BLOCKED (1<<2) @@ -91,6 +86,10 @@ typedef struct region { struct unit *units; struct ship *ships; struct building *buildings; + unsigned int index; + /* an ascending number, to improve the speed of determining the interval in + which a faction has its units. See the implementations of firstregion + and lastregion */ short x, y; struct plane *planep; char *display; @@ -113,9 +112,6 @@ typedef struct region { #ifdef FAST_CONNECT struct region * connect[MAXDIRECTIONS]; #endif -#ifdef ENUM_REGIONS - unsigned int index; -#endif } region; typedef struct region_list { @@ -138,13 +134,8 @@ typedef struct { direction_t dir; } moveblock; -#ifdef ENUM_REGIONS -# define reg_hashkey(r) (r->index) -# define coor_hashkey(x, y) (abs(x + 0x100 * y)) -#else -# define reg_hashkey(r) (abs((r)->x + 0x100 * (r)->y)) -# define coor_hashkey(x, y) (abs(x + 0x100 * y)) -#endif +#define reg_hashkey(r) (r->index) +#define coor_hashkey(x, y) (abs(x + 0x100 * y)) int distance(const struct region*, const struct region*); int koor_distance(int ax, int ay, int bx, int by) ; diff --git a/src/common/kernel/reports.c b/src/common/kernel/reports.c index 06ed43c17..a71b69172 100644 --- a/src/common/kernel/reports.c +++ b/src/common/kernel/reports.c @@ -1105,25 +1105,25 @@ ucansee(const struct faction *f, const struct unit *u, const struct unit *x) return x; } -faction_list * -get_addresses(faction * f, struct seen_region * seehash[]) +static void +get_addresses(report_context * ctx) { /* "TODO: travelthru" */ - region *r, *last = lastregion(f); + region *r; const faction * lastf = NULL; faction_list * flist = calloc(1, sizeof(faction_list)); - flist->data = f; + flist->data = ctx->f; - for (r=firstregion(f);r!=last;r=r->next) { + for (r=ctx->first;r!=ctx->last;r=r->next) { const unit * u = r->units; - const seen_region * sr = find_seen(seehash, r); + const seen_region * sr = find_seen(ctx->seen, r); if (sr==NULL) continue; while (u!=NULL) { - faction * sf = visible_faction(f, u); - boolean ballied = sf && sf!=f && sf!=lastf - && !fval(u, UFL_PARTEITARNUNG) && cansee(f, r, u, 0); - if (ballied || ALLIED(f, sf)) { + faction * sf = visible_faction(ctx->f, u); + boolean ballied = sf && sf!=ctx->f && sf!=lastf + && !fval(u, UFL_PARTEITARNUNG) && cansee(ctx->f, r, u, 0); + if (ballied || ALLIED(ctx->f, sf)) { faction_list ** fnew = &flist; while (*fnew && (*fnew)->data->no < sf->no) { fnew =&(*fnew)->next; @@ -1140,10 +1140,10 @@ get_addresses(faction * f, struct seen_region * seehash[]) } } - if (f->alliance != NULL) { + if (ctx->f->alliance != NULL) { faction *f2; for(f2 = factions; f2; f2 = f2->next) { - if(f2->alliance != NULL && f2->alliance == f->alliance) { + if(f2->alliance != NULL && f2->alliance == ctx->f->alliance) { faction_list ** fnew = &flist; while (*fnew && (*fnew)->data->no < f2->no) { fnew =&(*fnew)->next; @@ -1157,7 +1157,7 @@ get_addresses(faction * f, struct seen_region * seehash[]) } } } - return flist; + ctx->addresses = flist; } #define MAXSEEHASH 10007 @@ -1206,42 +1206,24 @@ find_seen(struct seen_region * seehash[], const region * r) return NULL; } -void -get_seen_interval(struct seen_region ** seen, region ** first, region ** last) +static void +get_seen_interval(report_context * ctx) { /* this is required to find the neighbour regions of the ones we are in, * which may well be outside of [firstregion, lastregion) */ -#ifdef ENUM_REGIONS int i; for (i=0;i!=MAXSEEHASH;++i) { - seen_region * sr = seen[i]; + seen_region * sr = ctx->seen[i]; while (sr!=NULL) { - if (*first==NULL || sr->r->index<(*first)->index) { - *first = sr->r; + if (ctx->first==NULL || sr->r->indexfirst->index) { + ctx->first = sr->r; } - if (*last!=NULL && sr->r->index>=(*last)->index) { - *last = sr->r->next; + if (ctx->last!=NULL && sr->r->index>=ctx->last->index) { + ctx->last = sr->r->next; } sr = sr->nextHash; } } -#else - region * r = regions; - while (r!=first) { - if (find_seen(seen, r)!=NULL) { - *first = r; - break; - } - r = r->next; - } - r = *last; - while (r!=NULL) { - if (find_seen(seen, r)!=NULL) { - *last = r->next; - } - r = r->next; - } -#endif } boolean @@ -1498,16 +1480,18 @@ int write_reports(faction * f, time_t ltime) { boolean gotit = false; - struct seen_region ** seen = prepare_report(f); - faction_list * addresses = get_addresses(f, seen); report_type * rtype = report_types; struct report_context ctx; ctx.f = f; - ctx.addresses = addresses; ctx.report_time = time(NULL); - ctx.seen = seen; + ctx.seen = prepare_report(f); + ctx.first = firstregion(f); + ctx.last = lastregion(f); + ctx.addresses = NULL; ctx.userdata = NULL; + get_seen_interval(&ctx); + get_addresses(&ctx); printf("Reports für %s: ", factionname(f)); fflush(stdout); @@ -1529,8 +1513,8 @@ write_reports(faction * f, time_t ltime) log_warning(("No report for faction %s!\n", factionid(f))); } - freelist(addresses); - seen_done(seen); + freelist(ctx.addresses); + seen_done(ctx.seen); return 0; } diff --git a/src/common/kernel/reports.h b/src/common/kernel/reports.h index 1af04ef88..65ce4cd1d 100644 --- a/src/common/kernel/reports.h +++ b/src/common/kernel/reports.h @@ -84,15 +84,15 @@ extern boolean add_seen(struct seen_region * seehash[], struct region * r, unsig extern struct seen_region ** seen_init(void); extern void seen_done(struct seen_region * seehash[]); extern void free_seen(void); -extern void get_seen_interval(struct seen_region ** seen, struct region ** first, struct region ** last); extern const char * visibility[]; typedef struct report_context { struct faction * f; struct faction_list * addresses; struct seen_region ** seen; - time_t report_time; + struct region * first, * last; void * userdata; + time_t report_time; } report_context; typedef int (*report_fun)(const char * filename, report_context * ctx); @@ -106,7 +106,6 @@ extern int bufunit_ugroupleader(const struct faction * f, const struct unit * u, #endif extern const char * reportpath(void); -extern struct faction_list * get_addresses(struct faction * f, struct seen_region * seehash[]); extern const char * trailinto(const struct region * r, const struct locale * lang); extern void reports_init(void);