There's a pretty bad problem with watchers in older datafiles.
This commit is contained in:
Enno Rehling 2011-02-15 23:28:09 -08:00
parent f5b4b1ff99
commit 42c5331f1b
2 changed files with 26 additions and 13 deletions

View File

@ -1413,7 +1413,9 @@ readgame(const char * filename, int mode, int backup)
n = store->r_int(store); n = store->r_int(store);
while(--n >= 0) { while(--n >= 0) {
int id = store->r_int(store); int id = store->r_int(store);
variant fno;
plane *pl = getplanebyid(id); plane *pl = getplanebyid(id);
if (pl==NULL) { if (pl==NULL) {
pl = calloc(1, sizeof(plane)); pl = calloc(1, sizeof(plane));
} else { } else {
@ -1428,18 +1430,28 @@ readgame(const char * filename, int mode, int backup)
pl->flags = store->r_int(store); pl->flags = store->r_int(store);
/* read watchers */ /* read watchers */
store->r_str_buf(store, token, sizeof(token)); if (store->version<FIX_WATCHERS_VERSION) {
while (strcmp(token, "end")!=0) { char rname[64];
watcher * w = calloc(sizeof(watcher),1); /* before this version, watcher storage was pretty broken. we are incompatible and don't read them */
variant fno; for (;;) {
fno.i = atoi36(token); store->r_tok_buf(store, rname, sizeof(rname));
w->mode = (unsigned char)store->r_int(store); if (strcmp(rname, "end")==0) {
w->next = pl->watchers; break; /* this is most likely the end of the list */
pl->watchers = w; } else {
ur_add(fno, &w->faction, resolve_faction); log_error(("This datafile contains watchers, but we are unable to read them\n"));
store->r_str_buf(store, token, sizeof(token)); }
}
} else {
fno = read_faction_reference(store);
while (fno.i) {
watcher * w = (watcher *)malloc(sizeof(watcher));
ur_add(fno, &w->faction, resolve_faction);
w->mode = (unsigned char)store->r_int(store);
w->next = pl->watchers;
pl->watchers = w;
fno = read_faction_reference(store);
}
} }
a_read(store, &pl->attribs, pl); a_read(store, &pl->attribs, pl);
addlist(&planes, pl); addlist(&planes, pl);
} }
@ -1715,7 +1727,7 @@ writegame(const char *filename, int mode)
} }
w = w->next; w = w->next;
} }
store->w_tok(store, "end"); write_faction_reference(NULL, store); /* mark the end of the list */
a_write(store, pl->attribs, pl); a_write(store, pl->attribs, pl);
store->w_brk(store); store->w_brk(store);
} }

View File

@ -66,6 +66,7 @@
#define MOURNING_VERSION 335 /* mourning peasants */ #define MOURNING_VERSION 335 /* mourning peasants */
#define FOSS_VERSION 336 /* the open source release */ #define FOSS_VERSION 336 /* the open source release */
#define OWNER_2_VERSION 337 /* region owners contain an alliance */ #define OWNER_2_VERSION 337 /* region owners contain an alliance */
#define FIX_WATCHERS_VERSION 338 /* fixed storage of watchers */
#define MIN_VERSION CURSETYPE_VERSION /* minimal datafile we support */ #define MIN_VERSION CURSETYPE_VERSION /* minimal datafile we support */
#define RELEASE_VERSION OWNER_2_VERSION /* current datafile */ #define RELEASE_VERSION FIX_WATCHERS_VERSION /* current datafile */