diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index ca2d68741..337848ac8 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -893,7 +893,7 @@ cr_find_address(FILE * F, const faction * uf, const faction_list * addresses) static void cr_reportspell(FILE * F, spellid_t id, const struct locale * lang) { - int k, itemanz, res, costtyp; + int k; spell *sp = find_spellbyid(id); const char * name = sp->sname; if (sp->info==NULL) { @@ -918,10 +918,10 @@ cr_reportspell(FILE * F, spellid_t id, const struct locale * lang) fputs("KOMPONENTEN\n", F); for (k = 0; k < MAXINGREDIENT; k++) { - res = sp->komponenten[k][0]; - itemanz = sp->komponenten[k][1]; - costtyp = sp->komponenten[k][2]; - if(itemanz > 0) { + resource_t res = sp->komponenten[k][0]; + int itemanz = sp->komponenten[k][1]; + int costtyp = sp->komponenten[k][2]; + if (itemanz > 0) { const char * name = resname(res, 0); fprintf(F, "%d %d;%s\n", itemanz, costtyp == SPC_LEVEL || costtyp == SPC_LINEAR, add_translation(name, LOC(lang, name))); @@ -1006,15 +1006,16 @@ cr_borders(const region * r, const faction * f, int seemode, FILE * F) /* main function of the creport. creates the header and traverses all regions */ void -report_computer(FILE * F, faction * f, const seen_region * seen, - const faction_list * addresses, const time_t report_time) +report_computer(FILE * F, faction * f, const faction_list * addresses, + const time_t report_time) { int i; + region * r; building *b; ship *sh; unit *u; const char * mailto = locale_string(f->locale, "mailto"); - const seen_region * sd = seen; + const region * last = lastregion(f); const attrib * a; /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ @@ -1131,16 +1132,15 @@ report_computer(FILE * F, faction * f, const seen_region * seen, } /* traverse all regions */ - while (sd!=NULL) { + for (r=firstregion(f);r!=last;r=r->next) { int modifier = 0; const char * tname; - unsigned char seemode = sd->mode; - const region * r = sd->r; - unit * owner = region_owner(r); - sd = sd->next; + const seen_region * sd = find_seen(r); + if (sd==NULL) continue; + if (!rplane(r)) { - if(opt_cr_absolute_coords) { + if (opt_cr_absolute_coords) { fprintf(F, "REGION %d %d\n", r->x, r->x); } else { fprintf(F, "REGION %d %d\n", region_x(r, f), region_y(r, f)); @@ -1162,7 +1162,7 @@ report_computer(FILE * F, faction * f, const seen_region * seen, } fprintf(F, "\"%s\";Terrain\n", add_translation(tname, locale_string(f->locale, tname))); - switch (seemode) { + switch (sd->mode) { case see_far: fputs("\"neighbourhood\";visibility\n", F); break; @@ -1173,11 +1173,14 @@ report_computer(FILE * F, faction * f, const seen_region * seen, fputs("\"travel\";visibility\n", F); break; } - if (owner) { - fprintf(F, "%d;owner\n", owner->faction->no); + { + unit * owner = region_owner(r); + if (owner) { + fprintf(F, "%d;owner\n", owner->faction->no); + } } - if (seemode == see_neighbour) { - cr_borders(r, f, seemode, F); + if (sd->mode == see_neighbour) { + cr_borders(r, f, sd->mode, F); } else { #define RESOURCECOMPAT char cbuf[8192], *pos = cbuf; @@ -1221,7 +1224,7 @@ report_computer(FILE * F, faction * f, const seen_region * seen, } fprintf(F, "%d;Pferde\n", rhorses(r)); - if (seemode>=see_unit) { + if (sd->mode>=see_unit) { struct demand * dmd = r->land->demands; #if NEW_RESOURCEGROWTH struct rawmaterial * res = r->resources; @@ -1306,8 +1309,8 @@ report_computer(FILE * F, faction * f, const seen_region * seen, } if (pos!=cbuf) fputs(cbuf, F); } - cr_borders(r, f, seemode, F); - if (seemode==see_unit && r->planep && r->planep->id == 1 && !is_cursed(r->attribs, C_ASTRALBLOCK, 0)) + cr_borders(r, f, sd->mode, F); + if (sd->mode==see_unit && r->planep && r->planep->id == 1 && !is_cursed(r->attribs, C_ASTRALBLOCK, 0)) { /* Sonderbehandlung Teleport-Ebene */ regionlist *rl = allinhab_in_range(r_astral_to_standard(r),TP_RADIUS); @@ -1382,7 +1385,7 @@ report_computer(FILE * F, faction * f, const seen_region * seen, /* visible units */ for (u = r->units; u; u = u->next) { boolean visible = true; - switch (seemode) { + switch (sd->mode) { case see_unit: modifier=0; break; @@ -1397,7 +1400,7 @@ report_computer(FILE * F, faction * f, const seen_region * seen, visible=false; } if (u->building || u->ship || (visible && cansee(f, r, u, modifier))) - cr_output_unit(F, r, f, u, seemode); + cr_output_unit(F, r, f, u, sd->mode); } } /* region traversal */ } diff --git a/src/common/gamecode/creport.h b/src/common/gamecode/creport.h index 3df2cca62..02629b254 100644 --- a/src/common/gamecode/creport.h +++ b/src/common/gamecode/creport.h @@ -21,9 +21,7 @@ struct faction_list; struct seen_region; struct faction; extern void report_computer(FILE * F, struct faction * f, - const struct seen_region * seen, - const struct faction_list * addresses, - const time_t report_time); + const struct faction_list * addresses, const time_t report_time); extern void creport_cleanup(void); extern void creport_init(void); diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index 5280df44a..12fec67f6 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -470,7 +470,8 @@ rparagraph(FILE *F, const char *s, int indent, char mark) static void report_spell(FILE * F, spellid_t id, const struct locale * lang) { - int k, itemanz, res, costtyp; + int k, itemanz, costtyp; + resource_t res; int dh = 0; spell *sp = find_spellbyid(id); @@ -1962,6 +1963,7 @@ report(FILE *F, faction * f, const faction_list * addresses, int dh; int anyunits; const struct region *r; + region * last = lastregion(f); building *b; ship *sh; unit *u; @@ -1969,7 +1971,6 @@ report(FILE *F, faction * f, const faction_list * addresses, message * m; int wants_stats; int wants_zugvorlage; - seen_region * sd; int ix; unsigned char op; char buf2[80]; @@ -2202,10 +2203,12 @@ report(FILE *F, faction * f, const faction_list * addresses, anyunits = 0; - for (sd = seen; sd!=NULL; sd = sd->next) { + for (r=firstregion(f);r!=last;r=r->next) { boolean unit_in_region = false; boolean durchgezogen_in_region = false; int turm_sieht_region = false; + seen_region * sd = find_seen(r); + if (sd==NULL) continue; switch (sd->mode) { case see_lighthouse: @@ -2632,24 +2635,31 @@ merian(FILE * out, faction * f) free(line); } #endif -seen_region * seen; seen_region * reuse; -seen_region * last; - #define MAXSEEHASH 4095 seen_region * seehash[MAXSEEHASH]; +static void +seen_init(void) +{ + int i; + for (i=0;i!=MAXSEEHASH;++i) { + seen_region * sd = seehash[i]; + if (sd==NULL) continue; + while (sd->nextHash!=NULL) sd = sd->nextHash; + sd->nextHash = reuse; + reuse = seehash[i]; + seehash[i] = NULL; + } +} + static void seen_done(void) { - while (seen) { - seen_region * r = seen; - seen = seen->next; - free(r); - } + seen_init(); while (reuse) { seen_region * r = reuse; - reuse = reuse->next; + reuse = reuse->nextHash; free(r); } } @@ -2666,63 +2676,18 @@ find_seen(const region * r) return NULL; } -seen_region * last; static boolean add_seen(const struct region * r, unsigned char mode, boolean dis) { seen_region * find = find_seen(r); if (find==NULL) { - seen_region * insert = NULL; int index = abs((r->x & 0xffff) + ((r->y) << 16)) % MAXSEEHASH; if (!reuse) reuse = (seen_region*)calloc(1, sizeof(struct seen_region)); find = reuse; - reuse = reuse->next; + reuse = reuse->nextHash; find->nextHash = seehash[index]; seehash[index] = find; find->r = r; - - /* first attempt: try to put it between previous insertion point and - * last region known so far. It's quite likely to be here. */ - if (last) { - for (insert=last;insert->next;insert=insert->next) { - region * rl; - seen_region * inext = insert->next; - for (rl=insert->r->next;rl && rl!=inext->r;rl=rl->next) { - if (rl==r) break; - } - if (rl==r) break; - } - /* if we did not find it, and mode is not see_neighbour, it *still* - * belongs at the end. otherwise, search more: */ - if (insert->next==NULL && mode==see_neighbour) { - const region * rl = NULL; - seen_region * sprev; - for(sprev=seen;sprev!=last;sprev=sprev->next) { - seen_region * snext = sprev->next; - for (rl=sprev->r->next;rl!=snext->r;rl=rl->next) { - if (rl==r) break; - } - if (rl==r) break; - } - /* search it after the insertion point, all the way to the end */ - if (rl==r) insert = sprev; - else { - for (rl=insert->r->next;rl;rl=rl->next) { - if (rl==r) break; - } - if (rl!=r) insert=NULL; /* in front */ - } - } - } - if (mode!=see_neighbour) last=find; - find->prev = insert; - if (insert!=0) { - find->next = insert->next; - insert->next = find; - } else { - find->next = seen; - seen = find; - } } else if (find->mode >= mode) { return false; } @@ -2833,13 +2798,7 @@ prepare_report(faction * f) { region * r; region * end = lastregion(f); - seen_region ** append = &reuse; - - while (*append) append = &(*append)->next; - *append = seen; - memset(seehash, 0, sizeof(seehash)); - seen = NULL; - last = NULL; + seen_init(); for (r = firstregion(f); r != end; r = r->next) { attrib *ru; unit * u; @@ -2967,7 +2926,7 @@ reports(void) } else printf("%s\n", factionname(f)); prepare_report(f); - addresses = get_addresses(f, seen); + addresses = get_addresses(f); if (!nonr && (f->options & wants_report)) { sprintf(buf, "%s/%d-%s.nr", reportpath(), turn, factionid(f)); @@ -2983,7 +2942,7 @@ reports(void) sprintf(buf, "%s/%d-%s.cr", reportpath(), turn, factionid(f)); F = cfopen(buf, "wt"); if (F) { - report_computer(F, f, seen, addresses, ltime); + report_computer(F, f, addresses, ltime); fclose(F); gotit = true; } diff --git a/src/common/kernel/race.c b/src/common/kernel/race.c index 354fb4bec..120de9662 100644 --- a/src/common/kernel/race.c +++ b/src/common/kernel/race.c @@ -852,7 +852,7 @@ tagbegin(struct xml_stack * stack) a->flags = xml_ivalue(tag, "flags"); } else if (strcmp(tag->name, "precombatspell") == 0) { race * rc = state->race; - rc->precombatspell = xml_ivalue(tag, "spell"); + rc->precombatspell = (spellid_t)xml_ivalue(tag, "spell"); } else if (strcmp(tag->name, "function")==0) { race * rc = state->race; const char * name = xml_value(tag, "name"); diff --git a/src/common/kernel/reports.c b/src/common/kernel/reports.c index 5e930e32f..05718055c 100644 --- a/src/common/kernel/reports.c +++ b/src/common/kernel/reports.c @@ -854,16 +854,17 @@ visible_faction(const faction *f, const unit * u) } faction_list * -get_addresses(const faction * f, const seen_region * seenregions) +get_addresses(faction * f) { /* "TODO: travelthru" */ - const seen_region * sr = seenregions; + region *r, *last = lastregion(f); const faction * lastf = NULL; faction_list * flist = calloc(1, sizeof(faction_list)); flist->data = findfaction(f->no); - while (sr!=NULL) { - const region * r = sr->r; + for (r=firstregion(f);r!=last;r=r->next) { const unit * u = r->units; + const seen_region * sr = find_seen(r); + if (sr==NULL) continue; while (u!=NULL) { faction * sf = visible_faction(f, u); boolean ballied = sf && sf!=f && sf!=lastf @@ -883,7 +884,6 @@ get_addresses(const faction * f, const seen_region * seenregions) } u = u->next; } - sr = sr->next; } #ifdef ALLIANCES if(f->alliance != NULL) { diff --git a/src/common/kernel/reports.h b/src/common/kernel/reports.h index f594b0726..15fd03ce0 100644 --- a/src/common/kernel/reports.h +++ b/src/common/kernel/reports.h @@ -74,15 +74,12 @@ enum { }; typedef struct seen_region { - struct seen_region * next; - struct seen_region * prev; struct seen_region * nextHash; const struct region *r; unsigned char mode; boolean disbelieves; } seen_region; -extern struct seen_region * seen; extern struct seen_region * find_seen(const struct region * r); extern const char* resname(resource_t res, int i); @@ -108,7 +105,7 @@ extern const char *neue_gebiete[]; extern const char *coasts[]; extern const char * reportpath(void); extern struct faction * visible_faction(const struct faction *f, const struct unit * u); -extern struct faction_list * get_addresses(const struct faction * f, const struct seen_region * seenregions); +extern struct faction_list * get_addresses(struct faction * f); extern const char * trailinto(const struct region * r, const struct locale * lang); #ifdef __cplusplus