Skip to content

Commit

Permalink
No alliances to dead factions (#1054)
Browse files Browse the repository at this point in the history
* do not show alliances to dead factions.

* do not save alliances to dead factions
  • Loading branch information
ennorehling committed Mar 1, 2024
1 parent efe35b3 commit d6a92a5
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 65 deletions.
3 changes: 1 addition & 2 deletions src/creport.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/ally.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
130 changes: 68 additions & 62 deletions src/report.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit d6a92a5

Please sign in to comment.