diff --git a/src/gamecode/creport.c b/src/gamecode/creport.c index 065fd78de..fbf0af602 100644 --- a/src/gamecode/creport.c +++ b/src/gamecode/creport.c @@ -63,6 +63,7 @@ without prior permission by the authors of Eressea. #include #include #include +#include #include @@ -959,11 +960,12 @@ show_active_spells(const region * r) /* this is a copy of laws.c->find_address output changed. */ static void -cr_find_address(FILE * F, const faction * uf, const faction_list * addresses) +cr_find_address(FILE * F, const faction * uf, quicklist * addresses) { - const faction_list * flist = addresses; - while (flist!=NULL) { - const faction * f = flist->data; + int i = 0; + quicklist * flist = addresses; + while (flist) { + const faction * f = (const faction *)ql_get(flist, i); if (uf!=f) { fprintf(F, "PARTEI %d\n", f->no); fprintf(F, "\"%s\";Parteiname\n", f->name); @@ -974,7 +976,7 @@ cr_find_address(FILE * F, const faction * uf, const faction_list * addresses) fprintf(F, "%d;alliance\n", f->alliance->id); } } - flist = flist->next; + ql_advance(&flist, &i, 1); } } /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ diff --git a/src/gamecode/report.c b/src/gamecode/report.c index 4d9308a41..b32c252b0 100644 --- a/src/gamecode/report.c +++ b/src/gamecode/report.c @@ -76,6 +76,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include @@ -1700,15 +1701,16 @@ rpline(FILE * F) } static void -list_address(FILE * F, const faction * uf, const faction_list * seenfactions) +list_address(FILE * F, const faction * uf, quicklist * seenfactions) { - const faction_list *flist = seenfactions; + int qi = 0; + quicklist * flist = seenfactions; centre(F, LOC(uf->locale, "nr_addresses"), false); rnl(F); while (flist!=NULL) { - const faction * f = flist->data; + const faction * f = (const faction *)ql_get(flist, qi); if (!is_monsters(f)) { char buf[8192]; char label = '-'; @@ -1720,7 +1722,7 @@ list_address(FILE * F, const faction * uf, const faction_list * seenfactions) rparagraph(F, buf, 4, 0, label); } - flist = flist->next; + ql_advance(&flist, &qi, 1); } rnl(F); rpline(F); diff --git a/src/gamecode/xmlreport.c b/src/gamecode/xmlreport.c index f428f9417..2c7646895 100644 --- a/src/gamecode/xmlreport.c +++ b/src/gamecode/xmlreport.c @@ -672,7 +672,8 @@ xml_region(report_context * ctx, seen_region * sr) static xmlNodePtr report_root(report_context * ctx) { - const faction_list * address; + int qi; + quicklist * address; region * r = ctx->first, * rend = ctx->last; xml_context* xct = (xml_context*)ctx->userdata; xmlNodePtr node, child, xmlReport = xmlNewNode(NULL, BAD_CAST "atlantis"); @@ -697,9 +698,9 @@ report_root(report_context * ctx) xmlNewTextChild(node, xct->ns_atl, BAD_CAST "time", (xmlChar *)zText); xmlNewTextChild(node, xct->ns_atl, BAD_CAST "turn", (xmlChar *)itoab(turn, 10)); - - for (address=ctx->addresses;address;address=address->next) { - xmlAddChild(xmlReport, xml_faction(ctx, address->data)); + for (qi=0,address=ctx->addresses;address;ql_advance(&address, &qi, 1)) { + faction * f = (faction *)ql_get(address, qi); + xmlAddChild(xmlReport, xml_faction(ctx, f)); } for (;r!=rend;r=r->next) { diff --git a/src/kernel/reports.c b/src/kernel/reports.c index 27f14128a..7cd973a6c 100644 --- a/src/kernel/reports.c +++ b/src/kernel/reports.c @@ -51,6 +51,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include /* libc includes */ #include @@ -899,6 +900,15 @@ stealth_modifier(int seen_mode) } } +void transfer_seen(quicklist ** dst, faction_list ** src) { + while (*src) { + faction_list * flist = *src; + ql_set_insert(dst, flist->data); + free(flist); + *src = flist->next; + } +} + static void get_addresses(report_context * ctx) { @@ -906,18 +916,21 @@ get_addresses(report_context * ctx) seen_region * sr = NULL; region *r; const faction * lastf = NULL; - faction_list * flist = ctx->f->seen_factions; + quicklist * flist = 0; + + transfer_seen(&flist, &ctx->f->seen_factions); ctx->f->seen_factions = NULL; /* do not delete it twice */ - flist_add(&flist, ctx->f); + ql_push(&flist, ctx->f); if (f_get_alliance(ctx->f)) { faction_list * member = ctx->f->alliance->members; for (;member;member=member->next) { - flist_add(&flist, member->data); + ql_set_insert(&flist, member->data); } } + /* 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); } @@ -931,7 +944,7 @@ get_addresses(report_context * ctx) faction * sf = visible_faction(ctx->f, u); if (lastf!=sf) { if (u->building || u->ship || (stealthmod>INT_MIN && cansee(ctx->f, r, u, stealthmod))) { - flist_add(&flist, sf); + ql_set_insert(&flist, sf); lastf = sf; } } @@ -947,7 +960,7 @@ get_addresses(report_context * ctx) unit * u2 = (unit*)a->data.v; if (u2->faction==ctx->f) { if (cansee_unit(u2, u, stealthmod)) { - flist_add(&flist, sf); + ql_set_insert(&flist, sf); lastf = sf; break; } @@ -965,7 +978,7 @@ get_addresses(report_context * ctx) boolean ballied = sf && sf!=ctx->f && sf!=lastf && !fval(u, UFL_ANON_FACTION) && cansee(ctx->f, r, u, stealthmod); if (ballied || ALLIED(ctx->f, sf)) { - flist_add(&flist, sf); + ql_set_insert(&flist, sf); lastf = sf; } } @@ -978,7 +991,7 @@ get_addresses(report_context * ctx) faction *f2; for (f2 = factions; f2; f2 = f2->next) { if (f2->alliance == ctx->f->alliance) { - flist_add(&flist, f2); + ql_set_insert(&flist, f2); } } } @@ -1393,7 +1406,7 @@ write_reports(faction * f, time_t ltime) if (!gotit) { log_warning(("No report for faction %s!\n", factionid(f))); } - freelist(ctx.addresses); + ql_free(ctx.addresses); seen_done(ctx.seen); return 0; } diff --git a/src/kernel/reports.h b/src/kernel/reports.h index f4082f91c..d97e204df 100644 --- a/src/kernel/reports.h +++ b/src/kernel/reports.h @@ -83,7 +83,7 @@ extern const char * visibility[]; typedef struct report_context { struct faction * f; - struct faction_list * addresses; + struct quicklist * addresses; struct seen_region ** seen; struct region * first, * last; void * userdata;