From d6a92a517d93b1f1ea83931c57623a261b41ced4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 10 Feb 2024 16:29:26 +0100 Subject: [PATCH] No alliances to dead factions (#1054) * do not show alliances to dead factions. * do not save alliances to dead factions --- src/creport.c | 3 +- src/kernel/ally.c | 2 +- src/report.c | 130 ++++++++++++++++++++++++---------------------- 3 files changed, 70 insertions(+), 65 deletions(-) diff --git a/src/creport.c b/src/creport.c index d7542ea48..76706088b 100644 --- a/src/creport.c +++ b/src/creport.c @@ -996,10 +996,9 @@ struct print_ally_s { }; static int print_ally_cb(struct allies *al, faction *af, int status, void *udata) { - struct print_ally_s *data = (struct print_ally_s *)udata; - UNUSED_ARG(al); if (af && faction_alive(af)) { + struct print_ally_s *data = (struct print_ally_s *)udata; int mode = alliance_status(data->f, af, status); print_ally(data->f, af, mode, data->F); } diff --git a/src/kernel/ally.c b/src/kernel/ally.c index 003dcd3b7..0e1a32302 100644 --- a/src/kernel/ally.c +++ b/src/kernel/ally.c @@ -117,7 +117,7 @@ void write_allies(gamedata * data, const allies *alist) int i; for (i = 0; i != al->num; ++i) { const faction * f = al->factions[i]; - if (f && f->_alive) { + if (f && faction_alive(f)) { write_faction_reference(f, data->store); assert(al->status[i] > 0); WRITE_INT(data->store, al->status[i]); diff --git a/src/report.c b/src/report.c index 4c36080fb..7c0acad93 100644 --- a/src/report.c +++ b/src/report.c @@ -1406,10 +1406,13 @@ int write_template(const char* filename, const char* bom, const faction* f, cons return 0; } -static int count_allies_cb(struct allies *all, faction *af, int status, void *udata) { - int *num = (int *)udata; - if (status > 0) { - ++*num; +static int count_allies_cb(struct allies *al, faction *af, int status, void *udata) { + (void)al; + if (af && faction_alive(af)) { + int *num = (int *)udata; + if (status > 0) { + ++*num; + } } return 0; } @@ -1480,70 +1483,73 @@ void pump_paragraph(sbstring *sbp, stream *out, size_t maxlen, bool isfinal) } } -static int show_allies_cb(struct allies *all, faction *af, int status, void *udata) { - struct show_s * show = (struct show_s *)udata; - const faction * f = show->f; - sbstring *sbp = &show->sbs; - int mode = alliance_status(f, af, status); +static int show_allies_cb(struct allies *al, faction *af, int status, void *udata) { + (void)al; + if (af && faction_alive(af)) { + struct show_s *show = (struct show_s *)udata; + const faction *f = show->f; + sbstring *sbp = &show->sbs; + int mode = alliance_status(f, af, status); - if (show->num_listed++ != 0) { - if (show->num_listed == show->num_allies) { - /* last entry */ - sbs_strcat(sbp, LOC(f->locale, "list_and")); - } - else { - /* neither first entry nor last*/ - sbs_strcat(sbp, ", "); + if (show->num_listed++ != 0) { + if (show->num_listed == show->num_allies) { + /* last entry */ + sbs_strcat(sbp, LOC(f->locale, "list_and")); + } + else { + /* neither first entry nor last*/ + sbs_strcat(sbp, ", "); + } } - } - sbs_strcat(sbp, factionname(af)); - pump_paragraph(sbp, show->out, show->maxlen, false); - sbs_strcat(sbp, " ("); - if ((mode & HELP_ALL) == HELP_ALL) { - sbs_strcat(sbp, param_name(P_ANY, f->locale)); - } - else if (mode > 0) { - int h, hh = 0; - for (h = 1; h <= HELP_TRAVEL; h *= 2) { - int p = MAXPARAMS; - if ((mode & h) == h) { - switch (h) { - case HELP_TRAVEL: - p = P_TRAVEL; - break; - case HELP_MONEY: - p = P_MONEY; - break; - case HELP_FIGHT: - p = P_FIGHT; - break; - case HELP_GIVE: - p = P_GIVE; - break; - case HELP_GUARD: - p = P_GUARD; - break; - case HELP_FSTEALTH: - p = P_FACTIONSTEALTH; - break; + sbs_strcat(sbp, factionname(af)); + pump_paragraph(sbp, show->out, show->maxlen, false); + sbs_strcat(sbp, " ("); + if ((mode & HELP_ALL) == HELP_ALL) { + sbs_strcat(sbp, param_name(P_ANY, f->locale)); + } + else if (mode > 0) { + int h, hh = 0; + for (h = 1; h <= HELP_TRAVEL; h *= 2) { + int p = MAXPARAMS; + if ((mode & h) == h) { + switch (h) { + case HELP_TRAVEL: + p = P_TRAVEL; + break; + case HELP_MONEY: + p = P_MONEY; + break; + case HELP_FIGHT: + p = P_FIGHT; + break; + case HELP_GIVE: + p = P_GIVE; + break; + case HELP_GUARD: + p = P_GUARD; + break; + case HELP_FSTEALTH: + p = P_FACTIONSTEALTH; + break; + } } - } - if (p != MAXPARAMS) { - if (hh) { - sbs_strcat(sbp, ", "); + if (p != MAXPARAMS) { + if (hh) { + sbs_strcat(sbp, ", "); + } + sbs_strcat(sbp, param_name(p, f->locale)); + hh = 1; } - sbs_strcat(sbp, param_name(p, f->locale)); - hh = 1; } } - } - if (show->num_allies == show->num_listed) { - sbs_strcat(sbp, ").\n"); - pump_paragraph(sbp, show->out, show->maxlen, true); - } - else { - sbs_strcat(sbp, ")"); - pump_paragraph(sbp, show->out, show->maxlen, false); + if (show->num_allies == show->num_listed) { + sbs_strcat(sbp, ").\n"); + pump_paragraph(sbp, show->out, show->maxlen, true); + } + else { + sbs_strcat(sbp, ")"); + pump_paragraph(sbp, show->out, show->maxlen, false); + } } return 0; }