forked from github/server
extract read_planes into a separate function.
This commit is contained in:
parent
851ae00835
commit
0c6defad91
|
@ -134,7 +134,7 @@ extern "C" {
|
|||
|
||||
void write_faction_reference(const struct faction *f,
|
||||
struct storage *store);
|
||||
variant read_faction_reference(struct gamedata *store);
|
||||
variant read_faction_reference(struct gamedata *data);
|
||||
int resolve_faction(variant data, void *addr);
|
||||
|
||||
void renumber_faction(faction * f, int no);
|
||||
|
|
|
@ -452,6 +452,88 @@ static void read_alliances(struct gamedata *data)
|
|||
}
|
||||
}
|
||||
|
||||
void read_planes(gamedata *data) {
|
||||
struct storage *store = data->store;
|
||||
int nread;
|
||||
char name[32];
|
||||
|
||||
/* Planes */
|
||||
planes = NULL;
|
||||
READ_INT(store, &nread);
|
||||
while (--nread >= 0) {
|
||||
int id;
|
||||
variant fno;
|
||||
plane *pl;
|
||||
|
||||
READ_INT(store, &id);
|
||||
pl = getplanebyid(id);
|
||||
|
||||
if (pl == NULL) {
|
||||
pl = calloc(1, sizeof(plane));
|
||||
}
|
||||
else {
|
||||
log_warning("the plane with id=%d already exists.", id);
|
||||
}
|
||||
pl->id = id;
|
||||
READ_STR(store, name, sizeof(name));
|
||||
pl->name = _strdup(name);
|
||||
READ_INT(store, &pl->minx);
|
||||
READ_INT(store, &pl->maxx);
|
||||
READ_INT(store, &pl->miny);
|
||||
READ_INT(store, &pl->maxy);
|
||||
READ_INT(store, &pl->flags);
|
||||
|
||||
/* read watchers */
|
||||
if (data->version < FIX_WATCHERS_VERSION) {
|
||||
char rname[64];
|
||||
/* before this version, watcher storage was pretty broken. we are incompatible and don't read them */
|
||||
for (;;) {
|
||||
READ_TOK(store, rname, sizeof(rname));
|
||||
if (strcmp(rname, "end") == 0) {
|
||||
break; /* this is most likely the end of the list */
|
||||
}
|
||||
else {
|
||||
log_error(
|
||||
("This datafile contains watchers, but we are unable to read them."));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* WATCHERS - eliminated in February 2016, ca. turn 966 */
|
||||
if (data->version < NOWATCH_VERSION) {
|
||||
fno = read_faction_reference(data);
|
||||
while (fno.i) {
|
||||
fno = read_faction_reference(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
read_attribs(data, &pl->attribs, pl);
|
||||
if (pl->id != 1094969858) { // Regatta
|
||||
addlist(&planes, pl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void write_planes(storage *store) {
|
||||
plane *pl;
|
||||
/* Write planes */
|
||||
WRITE_INT(store, listlen(planes));
|
||||
for (pl = planes; pl; pl = pl->next) {
|
||||
WRITE_INT(store, pl->id);
|
||||
WRITE_STR(store, pl->name);
|
||||
WRITE_INT(store, pl->minx);
|
||||
WRITE_INT(store, pl->maxx);
|
||||
WRITE_INT(store, pl->miny);
|
||||
WRITE_INT(store, pl->maxy);
|
||||
WRITE_INT(store, pl->flags);
|
||||
#if RELEASE_VERSION < NOWATCH_VERSION
|
||||
write_faction_reference(NULL, store); /* mark the end of pl->watchers (gone since T966) */
|
||||
#endif
|
||||
a_write(store, pl->attribs, pl);
|
||||
WRITE_SECTION(store);
|
||||
}
|
||||
}
|
||||
|
||||
void write_alliances(struct gamedata *data)
|
||||
{
|
||||
alliance *al = alliances;
|
||||
|
@ -1554,63 +1636,7 @@ int read_game(gamedata *data) {
|
|||
READ_INT(store, NULL); /* max_unique_id = ignore */
|
||||
READ_INT(store, &nextborder);
|
||||
|
||||
/* Planes */
|
||||
planes = NULL;
|
||||
READ_INT(store, &nread);
|
||||
while (--nread >= 0) {
|
||||
int id;
|
||||
variant fno;
|
||||
plane *pl;
|
||||
|
||||
READ_INT(store, &id);
|
||||
pl = getplanebyid(id);
|
||||
|
||||
if (pl == NULL) {
|
||||
pl = calloc(1, sizeof(plane));
|
||||
}
|
||||
else {
|
||||
log_warning("the plane with id=%d already exists.", id);
|
||||
}
|
||||
pl->id = id;
|
||||
READ_STR(store, name, sizeof(name));
|
||||
pl->name = _strdup(name);
|
||||
READ_INT(store, &pl->minx);
|
||||
READ_INT(store, &pl->maxx);
|
||||
READ_INT(store, &pl->miny);
|
||||
READ_INT(store, &pl->maxy);
|
||||
READ_INT(store, &pl->flags);
|
||||
|
||||
/* read watchers */
|
||||
if (data->version < FIX_WATCHERS_VERSION) {
|
||||
char rname[64];
|
||||
/* before this version, watcher storage was pretty broken. we are incompatible and don't read them */
|
||||
for (;;) {
|
||||
READ_TOK(store, rname, sizeof(rname));
|
||||
if (strcmp(rname, "end") == 0) {
|
||||
break; /* this is most likely the end of the list */
|
||||
}
|
||||
else {
|
||||
log_error(
|
||||
("This datafile contains watchers, but we are unable to read them."));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* WATCHERS - eliminated in February 2016, ca. turn 966 */
|
||||
if (data->version < NOWATCH_VERSION) {
|
||||
fno = read_faction_reference(data);
|
||||
while (fno.i) {
|
||||
fno = read_faction_reference(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
read_attribs(data, &pl->attribs, pl);
|
||||
if (pl->id != 1094969858) { // Regatta
|
||||
addlist(&planes, pl);
|
||||
}
|
||||
}
|
||||
|
||||
/* Read factions */
|
||||
read_planes(data);
|
||||
read_alliances(data);
|
||||
READ_INT(store, &nread);
|
||||
log_debug(" - Einzulesende Parteien: %d\n", nread);
|
||||
|
@ -1866,24 +1892,6 @@ int writegame(const char *filename)
|
|||
return n;
|
||||
}
|
||||
|
||||
void write_planes(storage *store) {
|
||||
plane *pl;
|
||||
for (pl = planes; pl; pl = pl->next) {
|
||||
WRITE_INT(store, pl->id);
|
||||
WRITE_STR(store, pl->name);
|
||||
WRITE_INT(store, pl->minx);
|
||||
WRITE_INT(store, pl->maxx);
|
||||
WRITE_INT(store, pl->miny);
|
||||
WRITE_INT(store, pl->maxy);
|
||||
WRITE_INT(store, pl->flags);
|
||||
#if RELEASE_VERSION < NOWATCH_VERSION
|
||||
write_faction_reference(NULL, store); /* mark the end of pl->watchers (gone since T966) */
|
||||
#endif
|
||||
a_write(store, pl->attribs, pl);
|
||||
WRITE_SECTION(store);
|
||||
}
|
||||
}
|
||||
|
||||
int write_game(gamedata *data) {
|
||||
storage * store = data->store;
|
||||
region *r;
|
||||
|
@ -1903,11 +1911,6 @@ int write_game(gamedata *data) {
|
|||
WRITE_INT(store, 0 /* max_unique_id */);
|
||||
WRITE_INT(store, nextborder);
|
||||
|
||||
/* Write planes */
|
||||
WRITE_SECTION(store);
|
||||
WRITE_INT(store, listlen(planes));
|
||||
WRITE_SECTION(store);
|
||||
|
||||
write_planes(store);
|
||||
write_alliances(data);
|
||||
n = listlen(factions);
|
||||
|
|
Loading…
Reference in New Issue