make destroyfaction not have to loop over all factions to clear HELP status.

This commit is contained in:
Enno Rehling 2016-01-11 14:42:36 +01:00
parent 8742317979
commit 04624179ce
3 changed files with 15 additions and 6 deletions

View File

@ -170,6 +170,9 @@ int
alliedgroup(const struct plane *pl, const struct faction *f, alliedgroup(const struct plane *pl, const struct faction *f,
const struct faction *f2, const struct ally *sf, int mode) const struct faction *f2, const struct ally *sf, int mode)
{ {
if (!(faction_alive(f) && faction_alive(f2))) {
return 0;
}
while (sf && sf->faction != f2) while (sf && sf->faction != f2)
sf = sf->next; sf = sf->next;
if (sf == NULL) { if (sf == NULL) {

View File

@ -74,6 +74,9 @@ faction *factions;
void free_faction(faction * f) void free_faction(faction * f)
{ {
funhash(f); funhash(f);
if (f->alliance && f->alliance->_leader == f) {
setalliance(f, 0);
}
if (f->msgs) { if (f->msgs) {
free_messagelist(f->msgs->begin); free_messagelist(f->msgs->begin);
free(f->msgs); free(f->msgs);
@ -389,8 +392,9 @@ void destroyfaction(faction ** fp)
u = u->nextF; u = u->nextF;
} }
} }
/* no way! f->units = NULL; */
handle_event(f->attribs, "destroy", f); 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) { for (ff = factions; ff; ff = ff->next) {
group *g; group *g;
ally *sf, **sfp; ally *sf, **sfp;
@ -417,7 +421,7 @@ void destroyfaction(faction ** fp)
} }
} }
} }
*/
if (f->alliance && f->alliance->_leader == f) { if (f->alliance && f->alliance->_leader == f) {
setalliance(f, 0); setalliance(f, 0);
} }
@ -650,6 +654,8 @@ void remove_empty_factions(void)
if (!(f->_alive && f->units!=NULL) && !fval(f, FFL_NOIDLEOUT)) { if (!(f->_alive && f->units!=NULL) && !fval(f, FFL_NOIDLEOUT)) {
log_debug("dead: %s", factionname(f)); log_debug("dead: %s", factionname(f));
destroyfaction(fp); destroyfaction(fp);
free_faction(f);
free(f);
} }
else { else {
fp = &(*fp)->next; 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); assert(f);
return f->_alive || (f->flags&FFL_NPC); return f->_alive || (f->flags&FFL_NPC);
} }

View File

@ -82,8 +82,8 @@ extern "C" {
int num_total; /* Anzahl Personen mit Monstern */ int num_total; /* Anzahl Personen mit Monstern */
int options; int options;
int no_units; int no_units;
struct ally *allies; struct ally *allies; /* alliedgroup and others should check sf.faction.alive before using a faction from f.allies */
struct group *groups; struct group *groups; /* alliedgroup and others should check sf.faction.alive before using a faction from f.groups */
int nregions; int nregions;
int money; int money;
score_t score; score_t score;
@ -123,7 +123,7 @@ extern "C" {
bool checkpasswd(const faction * f, const char *passwd); bool checkpasswd(const faction * f, const char *passwd);
void destroyfaction(faction ** f); 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); void set_alliance(struct faction *a, struct faction *b, int status);
int get_alliance(const struct faction *a, const struct faction *b); int get_alliance(const struct faction *a, const struct faction *b);