From 04624179cea458989fad7eca80953ac9b59d74e3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 11 Jan 2016 14:42:36 +0100 Subject: [PATCH] make destroyfaction not have to loop over all factions to clear HELP status. --- src/kernel/ally.c | 3 +++ src/kernel/faction.c | 12 +++++++++--- src/kernel/faction.h | 6 +++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/kernel/ally.c b/src/kernel/ally.c index d53973328..611db8d7b 100644 --- a/src/kernel/ally.c +++ b/src/kernel/ally.c @@ -170,6 +170,9 @@ int alliedgroup(const struct plane *pl, const struct faction *f, const struct faction *f2, const struct ally *sf, int mode) { + if (!(faction_alive(f) && faction_alive(f2))) { + return 0; + } while (sf && sf->faction != f2) sf = sf->next; if (sf == NULL) { diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 87a8e2203..e5f18a18e 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -74,6 +74,9 @@ faction *factions; void free_faction(faction * f) { funhash(f); + if (f->alliance && f->alliance->_leader == f) { + setalliance(f, 0); + } if (f->msgs) { free_messagelist(f->msgs->begin); free(f->msgs); @@ -389,8 +392,9 @@ void destroyfaction(faction ** fp) u = u->nextF; } } - /* no way! f->units = NULL; */ + handle_event(f->attribs, "destroy", f); +/* alliedgroup and others should check sf.faction.alive before using a faction from f.allies for (ff = factions; ff; ff = ff->next) { group *g; ally *sf, **sfp; @@ -417,7 +421,7 @@ void destroyfaction(faction ** fp) } } } - +*/ if (f->alliance && f->alliance->_leader == f) { setalliance(f, 0); } @@ -650,6 +654,8 @@ void remove_empty_factions(void) if (!(f->_alive && f->units!=NULL) && !fval(f, FFL_NOIDLEOUT)) { log_debug("dead: %s", factionname(f)); destroyfaction(fp); + free_faction(f); + free(f); } else { fp = &(*fp)->next; @@ -657,7 +663,7 @@ void remove_empty_factions(void) } } -bool faction_alive(faction *f) { +bool faction_alive(const faction *f) { assert(f); return f->_alive || (f->flags&FFL_NPC); } diff --git a/src/kernel/faction.h b/src/kernel/faction.h index 722904734..6c76f5383 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -82,8 +82,8 @@ extern "C" { int num_total; /* Anzahl Personen mit Monstern */ int options; int no_units; - struct ally *allies; - struct group *groups; + struct ally *allies; /* alliedgroup and others should check sf.faction.alive before using a faction from f.allies */ + struct group *groups; /* alliedgroup and others should check sf.faction.alive before using a faction from f.groups */ int nregions; int money; score_t score; @@ -123,7 +123,7 @@ extern "C" { bool checkpasswd(const faction * f, const char *passwd); void destroyfaction(faction ** f); - bool faction_alive(struct faction *f); + bool faction_alive(const struct faction *f); void set_alliance(struct faction *a, struct faction *b, int status); int get_alliance(const struct faction *a, const struct faction *b);