From ed77af52619bf353b4d94fc4e0c46ad3cd9440ae Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 12 Oct 2010 23:17:35 -0700 Subject: [PATCH] http://bugs.eressea.de/view.php?id=1784 espionage should show the faction of the spied unit in the report. --- src/gamecode/spy.c | 1 + src/kernel/faction.c | 16 ++++++++++++++++ src/kernel/faction.h | 2 ++ src/kernel/reports.c | 32 +++++++++----------------------- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/gamecode/spy.c b/src/gamecode/spy.c index f42caecc5..164c3b2b1 100644 --- a/src/gamecode/spy.c +++ b/src/gamecode/spy.c @@ -73,6 +73,7 @@ spy_message(int spy, const unit *u, const unit *target) if (fv && fv!=target->faction) { /* wahre Partei */ ADDMSG(&u->faction->msgs, msg_message("spyreport_faction", "target faction", target, target->faction)); + flist_add(&u->faction->seen_factions, target->faction); } } if (spy > 0) { diff --git a/src/kernel/faction.c b/src/kernel/faction.c index f5ac32f3c..44873ac24 100644 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -505,3 +505,19 @@ f_get_alliance(const struct faction * f) } return NULL; } + +void +flist_add(faction_list ** flist, faction * sf) +{ + faction_list ** fnew = flist; + while (*fnew && (*fnew)->data->no < sf->no) { + fnew =&(*fnew)->next; + } + if ((*fnew==NULL) || (*fnew)->data!=sf) { + faction_list * finsert = malloc(sizeof(faction_list)); + finsert->next = *fnew; + *fnew = finsert; + finsert->data = sf; + } +} + diff --git a/src/kernel/faction.h b/src/kernel/faction.h index faa552581..910929937 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -108,6 +108,7 @@ typedef struct faction { } * battles; struct item * items; /* items this faction can claim */ struct seen_region ** seen; + struct faction_list * seen_factions; } faction; extern struct faction *factions; @@ -117,6 +118,7 @@ typedef struct faction_list { struct faction * data; } faction_list; +void flist_add(struct faction_list ** flist, struct faction * sf); extern const struct unit * random_unit_in_faction(const struct faction *f); extern const char * factionname(const struct faction * f); extern struct unit * addplayer(struct region *r, faction * f); diff --git a/src/kernel/reports.c b/src/kernel/reports.c index dadad6481..b04cb9b0c 100644 --- a/src/kernel/reports.c +++ b/src/kernel/reports.c @@ -883,21 +883,6 @@ ucansee(const struct faction *f, const struct unit *u, const struct unit *x) return x; } -static void -add_faction(faction_list ** flist, faction * sf) -{ - faction_list ** fnew = flist; - while (*fnew && (*fnew)->data->no < sf->no) { - fnew =&(*fnew)->next; - } - if ((*fnew==NULL) || (*fnew)->data!=sf) { - faction_list * finsert = malloc(sizeof(faction_list)); - finsert->next = *fnew; - *fnew = finsert; - finsert->data = sf; - } -} - int stealth_modifier(int seen_mode) { @@ -921,14 +906,15 @@ get_addresses(report_context * ctx) seen_region * sr = NULL; region *r; const faction * lastf = NULL; - faction_list * flist = calloc(1, sizeof(faction_list)); - - flist->data = ctx->f; + faction_list * flist = ctx->f->seen_factions; + + ctx->f->seen_factions = NULL; /* do not delete it twice */ + flist_add(&flist, ctx->f); if (f_get_alliance(ctx->f)) { faction_list * member = ctx->f->alliance->members; for (;member;member=member->next) { - add_faction(&flist, member->data); + flist_add(&flist, member->data); } } @@ -945,7 +931,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))) { - add_faction(&flist, sf); + flist_add(&flist, sf); lastf = sf; } } @@ -961,7 +947,7 @@ get_addresses(report_context * ctx) unit * u2 = (unit*)a->data.v; if (u2->faction==ctx->f) { if (cansee_unit(u2, u, stealthmod)) { - add_faction(&flist, sf); + flist_add(&flist, sf); lastf = sf; break; } @@ -979,7 +965,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)) { - add_faction(&flist, sf); + flist_add(&flist, sf); lastf = sf; } } @@ -992,7 +978,7 @@ get_addresses(report_context * ctx) faction *f2; for (f2 = factions; f2; f2 = f2->next) { if (f2->alliance == ctx->f->alliance) { - add_faction(&flist, f2); + flist_add(&flist, f2); } } }