Data format change reflects that id 0 is now illegal (so we use that instead of -1)

This commit is contained in:
Enno Rehling 2008-05-16 22:37:13 +00:00
parent 5b5fc0063c
commit d0022db79a
11 changed files with 48 additions and 231 deletions

View File

@ -59,8 +59,12 @@ a_readgive(attrib * a, struct storage * store)
char zText[32]; char zText[32];
var.i = store->r_id(store); var.i = store->r_id(store);
gdata->building = findbuilding(var.i); if (var.i>0) {
if (gdata->building==NULL) ur_add(var, (void**)&gdata->building, resolve_building); gdata->building = findbuilding(var.i);
if (gdata->building==NULL) ur_add(var, (void**)&gdata->building, resolve_building);
} else {
gdata->building=NULL;
}
for (;;) { for (;;) {
int i; int i;
store->r_tok_buf(store, zText, sizeof(zText)); store->r_tok_buf(store, zText, sizeof(zText));

View File

@ -377,23 +377,23 @@ resolve_building(variant id) {
void void
write_building_reference(const struct building * b, struct storage * store) write_building_reference(const struct building * b, struct storage * store)
{ {
store->w_id(store, b?b->no:-1); store->w_id(store, b?b->no:0);
} }
int int
read_building_reference(struct building ** b, struct storage * store) read_building_reference(struct building ** b, struct storage * store)
{ {
variant var; variant var;
var.i = store->r_id(store); var.i = store->r_id(store);
if (var.i<=0) { if (var.i<=0) {
*b = NULL; *b = NULL;
return AT_READ_FAIL; return AT_READ_FAIL;
} }
else { else {
*b = findbuilding(var.i); *b = findbuilding(var.i);
if (*b==NULL) ur_add(var, (void**)b, resolve_building); if (*b==NULL) ur_add(var, (void**)b, resolve_building);
return AT_READ_OK; return AT_READ_OK;
} }
} }
void void

View File

@ -208,7 +208,7 @@ read_faction_reference(faction ** f, struct storage * store)
{ {
variant id; variant id;
id.i = store->r_id(store); id.i = store->r_id(store);
if (id.i<0) { if (id.i<=0 && (store->version>=NOZEROIDS_VERSION || id.i<0)) {
*f = NULL; *f = NULL;
return AT_READ_FAIL; return AT_READ_FAIL;
} }
@ -220,7 +220,7 @@ read_faction_reference(faction ** f, struct storage * store)
void void
write_faction_reference(const faction * f, struct storage * store) write_faction_reference(const faction * f, struct storage * store)
{ {
store->w_id(store, f?f->no:-1); store->w_id(store, f?f->no:0);
} }
void void

View File

@ -191,7 +191,7 @@ write_groups(struct storage * store, group * g)
store->w_int(store, a->status); store->w_int(store, a->status);
} }
} }
store->w_id(store, -1); store->w_id(store, 0);
a_write(store, g->attribs); a_write(store, g->attribs);
store->w_brk(store); store->w_brk(store);
g=g->next; g=g->next;

View File

@ -2224,10 +2224,10 @@ resolve_familiar(variant data)
static int static int
read_familiar(attrib * a, struct storage * store) read_familiar(attrib * a, struct storage * store)
{ {
variant id; variant id;
id.i = store->r_id(store); id.i = store->r_id(store);
ur_add(id, &a->data.v, resolve_familiar); ur_add(id, &a->data.v, resolve_familiar);
return AT_READ_OK; return AT_READ_OK;
} }
/* clones */ /* clones */
@ -2300,10 +2300,10 @@ resolve_clone(variant data)
static int static int
read_clone(attrib * a, struct storage * store) read_clone(attrib * a, struct storage * store)
{ {
variant id; variant id;
id.i = store->r_id(store); id.i = store->r_id(store);
ur_add(id, &a->data.v, resolve_clone); ur_add(id, &a->data.v, resolve_clone);
return AT_READ_OK; return AT_READ_OK;
} }
/* mages */ /* mages */

View File

@ -241,155 +241,6 @@ fwritestr(FILE * F, const char * str)
return nwrite + 2; return nwrite + 2;
} }
#if 0
#define store->r_id(store) ri36(F)
static void
rds(struct storage * store, char **ds)
{
static char buffer[DISPLAYSIZE + 1]; /*Platz für null-char nicht vergessen!*/
char *s = &buffer[0];
int c = getc(F);
while (c != '"') {
if (c == EOF) {
*s = 0;
fprintf(stderr, "Die Datei bricht vorzeitig ab.\n");
abort();
}
c = getc(F);
}
c = getc(F);
while (c != '"') {
if (c == EOF) {
*s = 0;
fprintf(stderr, "Die Datei bricht vorzeitig ab.\n");
abort();
}
if (s - buffer < DISPLAYSIZE) {
*s++ = (char)c;
}
c = getc(F);
}
c = getc(F);
*s = 0;
if (ds) {
*ds = realloc(*ds, sizeof(char) * (strlen(buffer) + 1));
strcpy(*ds, buffer);
}
}
static void
xrds(struct storage * store, char **ds, int encoding)
{
static char buffer[DISPLAYSIZE + 1]; /*Platz für null-char nicht vergessen!*/
int len = store->r_str_buf(store, buffer, sizeof(buffer));
if (len>=0) {
if (ds) {
*ds = realloc(*ds, sizeof(char) * (len + 1));
strcpy(*ds, buffer);
}
}
}
#define rcf(F) (getc(F));
void
rsf(struct storage * store, char *s, size_t len)
{
char * begin = s;
int c;
do {
c = getc(F);;
if (c == EOF) {
puts("Die Datei bricht vorzeitig ab.");
abort();
}
} while (c != '"');
for (;;) {
c = getc(F);
if (c == '"') break;
else if (c == EOF) {
puts("Die Datei bricht vorzeitig ab.");
abort();
}
if (s-begin<(int)len-1)
*s++ = (char)c;
}
*s = 0;
}
static void
rs(struct storage * store, char *s)
{
boolean apos = false;
int c = getc(F);
while (isspace(c)) c = getc(F);
if (c=='"') {
apos = true;
c = getc(F);
}
for (;;) {
if (c=='"') {
c = getc(F);
break;
} else if (!apos && isspace(c)) break;
*s++ = (char)c;
c = getc(F);
}
*s = 0;
}
#define store->r_str_buf(store, buf, size) store->r_tok_buf(store, buf) /* should check size but doesn't */
static int
ri(struct storage * store)
{
int i = 0, vz = 1;
int c = getc(F);
while (!xisdigit(c)) {
if (c == EOF) {
puts("Die Datei bricht vorzeitig ab.");
abort();
}
c = getc(F);
}
while (xisdigit(c)) {
if (c == '-')
vz = -1;
else
i = 10 * i + (c - '0');
c = getc(F);
}
return i * vz;
}
static int
ri36(struct storage * store)
{
char buf[16];
int i = 0;
int c = getc(F);
while (!isalnum(c)) c = getc(F);
while (isalnum(c)) {
if (i+1<sizeof(buf)) {
buf[i++]=(char)c;
}
c = getc(F);
}
buf[i]=0;
i = atoi36(buf);
return i;
}
#endif
#ifdef ENEMIES #ifdef ENEMIES
static void static void
read_enemies(struct storage * store, faction * f) read_enemies(struct storage * store, faction * f)
@ -398,7 +249,7 @@ read_enemies(struct storage * store, faction * f)
f->enemies = NULL; f->enemies = NULL;
for (;;) { for (;;) {
int fno = store->r_id(store); int fno = store->r_id(store);
if (fno<0) break; if (fno<=0) break;
else { else {
faction_list * flist = malloc(sizeof(faction_list)); faction_list * flist = malloc(sizeof(faction_list));
flist->next = f->enemies; flist->next = f->enemies;
@ -414,7 +265,7 @@ write_enemies(struct storage * store, const faction_list * flist)
while (flist) { while (flist) {
write_faction_reference(flist->data, store); write_faction_reference(flist->data, store);
} }
store->w_id(store, -1); store->w_id(store, 0);
} }
#endif #endif
@ -735,47 +586,6 @@ read_alliances(struct storage * store)
} }
} }
#if 0
#define wc(F, c) putc(c, F);
#define wnl(F) putc('\n', F);
#define whs(F, s) fputs(s, F); putc(' ', F)
size_t
wsn(struct storage * store, const char *s)
{
size_t n = 0;
if (!s)
return 0;
while (*s) {
wc(F, *s++);
++n;
}
return n;
}
size_t
ws(struct storage * store, const char *s)
{
size_t n;
fputc('"', F);
n = wsn(F, s);
fputs("\" ", F);
return n+3;
}
static int
wi(struct storage * store, int n)
{
return fprintf(F, "%d ", n);
}
static int
wi36(struct storage * store, int n)
{
return fprintf(F, "%s ", itoa36(n));
}
#endif
void void
write_alliances(struct storage * store) write_alliances(struct storage * store)
{ {
@ -850,6 +660,7 @@ readunit(struct storage * store)
int number, n, p; int number, n, p;
order ** orderp; order ** orderp;
char obuf[1024]; char obuf[1024];
faction * f;
n = store->r_id(store); n = store->r_id(store);
u = findunit(n); u = findunit(n);
@ -865,11 +676,11 @@ readunit(struct storage * store)
u->skill_size = 0; u->skill_size = 0;
u_setfaction(u, NULL); u_setfaction(u, NULL);
} }
{
int n = store->r_id(store); n = store->r_id(store);
faction * f = findfaction(n); f = findfaction(n);
if (f!=u->faction) u_setfaction(u, f); if (f!=u->faction) u_setfaction(u, f);
}
u->name = store->r_str(store); u->name = store->r_str(store);
if (lomem) { if (lomem) {
store->r_str_buf(store, NULL, 0); store->r_str_buf(store, NULL, 0);
@ -934,10 +745,10 @@ readunit(struct storage * store)
set_number(u, number); set_number(u, number);
n = store->r_id(store); n = store->r_id(store);
if (n>=0) u->building = findbuilding(n); if (n>0) u->building = findbuilding(n);
n = store->r_id(store); n = store->r_id(store);
if (n>=0) u->ship = findship(n); if (n>0) u->ship = findship(n);
if (store->version <= 73) { if (store->version <= 73) {
if (store->r_int(store)) { if (store->r_int(store)) {
@ -1370,7 +1181,7 @@ readfaction(struct storage * store)
if (alliances!=NULL) { if (alliances!=NULL) {
int allianceid = store->r_id(store); int allianceid = store->r_id(store);
if (allianceid>=0) f->alliance = findalliance(allianceid); if (allianceid>0) f->alliance = findalliance(allianceid);
if (f->alliance) { if (f->alliance) {
faction_list * flist = malloc(sizeof(faction_list)); faction_list * flist = malloc(sizeof(faction_list));
flist->data = f; flist->data = f;
@ -1493,7 +1304,7 @@ writefaction(struct storage * store, const faction * f)
store->w_int(store, f->subscription); store->w_int(store, f->subscription);
if (alliances!=NULL) { if (alliances!=NULL) {
if (f->alliance) store->w_id(store, f->alliance->id); if (f->alliance) store->w_id(store, f->alliance->id);
else store->w_id(store, -1); else store->w_id(store, 0);
} }
store->w_str(store, (const char *)f->name); store->w_str(store, (const char *)f->name);
@ -1540,7 +1351,7 @@ writefaction(struct storage * store, const faction * f)
store->w_int(store, sf->status); store->w_int(store, sf->status);
} }
} }
store->w_id(store, -1); store->w_id(store, 0);
store->w_brk(store); store->w_brk(store);
write_groups(store, f->groups); write_groups(store, f->groups);
#ifdef ENEMIES #ifdef ENEMIES

View File

@ -283,7 +283,7 @@ shipowner(const ship * sh)
void void
write_ship_reference(const struct ship * sh, struct storage * store) write_ship_reference(const struct ship * sh, struct storage * store)
{ {
store->w_id(store, sh?sh->no:-1); store->w_id(store, sh?sh->no:0);
} }
void void

View File

@ -597,7 +597,7 @@ free_units(void)
void void
write_unit_reference(const unit * u, struct storage * store) write_unit_reference(const unit * u, struct storage * store)
{ {
store->w_id(store, u?u->no:-1); store->w_id(store, u?u->no:0);
} }
void * void *

View File

@ -55,6 +55,7 @@
#define UID_VERSION 327 /* regions have a unique id */ #define UID_VERSION 327 /* regions have a unique id */
#define STORAGE_VERSION 328 /* with storage.h, some things are stored smarter (ids as base36, fractions as float) */ #define STORAGE_VERSION 328 /* with storage.h, some things are stored smarter (ids as base36, fractions as float) */
#define INTPAK_VERSION 329 /* in binary, ints can get packed */ #define INTPAK_VERSION 329 /* in binary, ints can get packed */
#define NOZEROIDS_VERSION 330 /* zero is not a valid ID for anything (including factions) */
#define MIN_VERSION CURSETYPE_VERSION /* minimal datafile we support */ #define MIN_VERSION CURSETYPE_VERSION /* minimal datafile we support */
#define RELEASE_VERSION INTPAK_VERSION /* current datafile */ #define RELEASE_VERSION NOZEROIDS_VERSION /* current datafile */

View File

@ -3399,6 +3399,7 @@ sp_chaossuction(castorder *co)
return 0; return 0;
} }
/* TODO: implement with a building */
create_special_direction(r, rt, 2, "vortex_desc", "vortex"); create_special_direction(r, rt, 2, "vortex_desc", "vortex");
create_special_direction(rt, r, 2, "vortex_desc", "vortex"); create_special_direction(rt, r, 2, "vortex_desc", "vortex");
new_border(&bt_chaosgate, r, rt); new_border(&bt_chaosgate, r, rt);

View File

@ -12,7 +12,7 @@ end
test_locales() test_locales()
local now = os.clock() local now = os.clock()
read_game("567.dat", "binary") read_game("571.new", "binary")
--read_game("566.txt", "text") --read_game("566.txt", "text")
--write_game("566.txt", "text") --write_game("566.txt", "text")
local elapsed = os.clock() - now local elapsed = os.clock() - now
@ -23,6 +23,6 @@ print(elapsed)
f = get_faction(0) f = get_faction(0)
--renumber(f, 666) --renumber(f, 666)
--write_game("566.dat", "binary") -- write_game("571.new", "binary")
--io.stdin:read("*line") io.stdin:read("*line")