create referenced factions early instead of read_faction_reference.

This commit is contained in:
Enno Rehling 2018-10-30 06:30:32 +01:00
parent ed6a6b4cf2
commit 253849416a
4 changed files with 12 additions and 4 deletions

View file

@ -28,7 +28,7 @@ void read_allies(gamedata * data, ally **sfp)
ally * al = ally_add(sfp, NULL); ally * al = ally_add(sfp, NULL);
int state; int state;
if ((al->faction = findfaction(aid)) == NULL) { if ((al->faction = findfaction(aid)) == NULL) {
ur_add(RESOLVE_FACTION | aid, (void **)&al->faction, NULL); al->faction = faction_create(aid);
} }
READ_INT(data->store, &state); READ_INT(data->store, &state);
al->status = state & HELP_ALL; al->status = state & HELP_ALL;

View file

@ -875,3 +875,11 @@ void free_factions(void) {
free_flist(&factions); free_flist(&factions);
free_flist(&dead_factions); free_flist(&dead_factions);
} }
faction *faction_create(int no)
{
faction *f = (faction *)calloc(1, sizeof(faction));
f->no = no;
fhash(f);
return f;
}

View file

@ -127,6 +127,7 @@ extern "C" {
void destroyfaction(faction ** f); void destroyfaction(faction ** f);
bool faction_alive(const struct faction *f); bool faction_alive(const struct faction *f);
struct faction *faction_create(int no);
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);

View file

@ -957,8 +957,7 @@ faction *read_faction(gamedata * data)
assert(n > 0); assert(n > 0);
f = findfaction(n); f = findfaction(n);
if (f == NULL) { if (f == NULL) {
f = (faction *)calloc(1, sizeof(faction)); f = faction_create(n);
f->no = n;
} }
else { else {
f->allies = NULL; /* FIXME: mem leak */ f->allies = NULL; /* FIXME: mem leak */
@ -1415,7 +1414,6 @@ int read_game(gamedata *data)
*fp = f; *fp = f;
fp = &f->next; fp = &f->next;
fhash(f);
} }
*fp = 0; *fp = 0;
@ -1515,6 +1513,7 @@ int read_game(gamedata *data)
} }
} }
else { else {
assert(f->units);
for (u = f->units; u; u = u->nextF) { for (u = f->units; u; u = u->nextF) {
if (data->version < SPELL_LEVEL_VERSION) { if (data->version < SPELL_LEVEL_VERSION) {
sc_mage *mage = get_mage_depr(u); sc_mage *mage = get_mage_depr(u);