extract read_regions from read_game.

This commit is contained in:
Enno Rehling 2019-08-25 17:55:04 +02:00
parent cf7971bcfc
commit 827532dd49
1 changed files with 60 additions and 51 deletions

View File

@ -1473,58 +1473,11 @@ static void fix_familiars(void (*callback)(unit *)) {
} }
} }
int read_game(gamedata *data) void read_regions(gamedata *data) {
{
int p, nread;
faction *f, **fp;
region *r;
unit *u;
storage * store = data->store; storage * store = data->store;
const struct building_type *bt_lighthouse = bt_find("lighthouse"); const struct building_type *bt_lighthouse = bt_find("lighthouse");
const struct race *rc_spell = rc_find("spell"); const struct race *rc_spell = rc_find("spell");
int nread;
if (data->version >= SAVEGAMEID_VERSION) {
int gameid;
READ_INT(store, &gameid);
if (gameid != game_id()) {
log_warning("game mismatch: datafile contains game %d, but config is for %d", gameid, game_id());
}
}
else {
READ_STR(store, NULL, 0);
}
if (data->version < FIXATKEYS_VERSION) {
attrib *a = NULL;
read_attribs(data, &a, NULL);
a_removeall(&a, NULL);
}
READ_INT(store, &turn);
log_debug(" - reading turn %d", turn);
rng_init(turn + config_get_int("game.seed", 0));
READ_INT(store, NULL); /* max_unique_id = ignore */
READ_INT(store, &nextborder);
read_planes(data);
read_alliances(data);
READ_INT(store, &nread);
log_debug(" - Einzulesende Parteien: %d\n", nread);
fp = &factions;
while (*fp) {
fp = &(*fp)->next;
}
while (--nread >= 0) {
faction *f = read_faction(data);
*fp = f;
fp = &f->next;
}
*fp = 0;
/* Regionen */
READ_INT(store, &nread); READ_INT(store, &nread);
assert(nread < MAXREGIONS && nread >= 0); assert(nread < MAXREGIONS && nread >= 0);
@ -1535,6 +1488,8 @@ int read_game(gamedata *data)
unit **up; unit **up;
building **bp; building **bp;
ship **shp; ship **shp;
region *r;
int p;
r = read_region(data); r = read_region(data);
@ -1595,6 +1550,60 @@ int read_game(gamedata *data)
} }
} }
} }
}
int read_game(gamedata *data)
{
storage * store = data->store;
int nread;
faction *f, **fp;
region *r;
unit *u;
if (data->version >= SAVEGAMEID_VERSION) {
int gameid;
READ_INT(store, &gameid);
if (gameid != game_id()) {
log_warning("game mismatch: datafile contains game %d, but config is for %d", gameid, game_id());
}
}
else {
READ_STR(store, NULL, 0);
}
if (data->version < FIXATKEYS_VERSION) {
attrib *a = NULL;
read_attribs(data, &a, NULL);
a_removeall(&a, NULL);
}
READ_INT(store, &turn);
log_debug(" - reading turn %d", turn);
rng_init(turn + config_get_int("game.seed", 0));
READ_INT(store, NULL); /* max_unique_id = ignore */
READ_INT(store, &nextborder);
read_planes(data);
read_alliances(data);
READ_INT(store, &nread);
log_debug(" - Einzulesende Parteien: %d\n", nread);
fp = &factions;
while (*fp) {
fp = &(*fp)->next;
}
while (--nread >= 0) {
faction *f = read_faction(data);
*fp = f;
fp = &f->next;
}
*fp = 0;
/* Regionen */
read_regions(data);
read_borders(data); read_borders(data);
log_debug("updating area information for lighthouses."); log_debug("updating area information for lighthouses.");