forked from github/server
attrib.read gets a gamedata object
stop using global.data_version for github issue #479
This commit is contained in:
parent
7f6ced99b9
commit
3e584245c0
|
@ -152,7 +152,7 @@ static int dict_read(attrib * a, void *owner, gamedata *data)
|
|||
case TREGION:
|
||||
result =
|
||||
read_reference(&dd->data.r, store, read_region_reference,
|
||||
RESOLVE_REGION(global.data_version));
|
||||
RESOLVE_REGION(data->version));
|
||||
if (result == 0 && !dd->data.r) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ static int read_targetregion(attrib * a, void *owner, gamedata *data)
|
|||
{
|
||||
int result =
|
||||
read_reference(&a->data.v, data->store, read_region_reference,
|
||||
RESOLVE_REGION(global.data_version));
|
||||
RESOLVE_REGION(data->version));
|
||||
if (result == 0 && !a->data.v)
|
||||
return AT_READ_FAIL;
|
||||
return AT_READ_OK;
|
||||
|
|
|
@ -106,7 +106,7 @@ static int lc_read(struct attrib *a, void *owner, gamedata *data)
|
|||
building_action *bd = (building_action *)a->data.v;
|
||||
building *b = (building *)owner;
|
||||
int result = 0;
|
||||
if (global.data_version < ATTRIBOWNER_VERSION) {
|
||||
if (data->version < ATTRIBOWNER_VERSION) {
|
||||
result = read_reference(&b, store, read_building_reference, resolve_building);
|
||||
assert(b == owner);
|
||||
}
|
||||
|
|
|
@ -659,7 +659,7 @@ int read_borders(gamedata *data)
|
|||
assert(bid <= nextborder);
|
||||
if (type->read)
|
||||
type->read(b, store);
|
||||
if (global.data_version < NOBORDERATTRIBS_VERSION) {
|
||||
if (data->version < NOBORDERATTRIBS_VERSION) {
|
||||
attrib *a = NULL;
|
||||
int result = read_attribs(data, &a, b);
|
||||
if (border_convert_cb) {
|
||||
|
|
|
@ -238,7 +238,7 @@ int curse_read(attrib * a, void *owner, gamedata *data)
|
|||
if (c->type->typ == CURSETYP_REGION) {
|
||||
int rr =
|
||||
read_reference(&c->data.v, store, read_region_reference,
|
||||
RESOLVE_REGION(global.data_version));
|
||||
RESOLVE_REGION(data->version));
|
||||
if (ur == 0 && rr == 0 && !c->data.v) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
|
@ -255,12 +255,11 @@ void curse_write(const attrib * a, const void *owner, struct storage *store)
|
|||
unit *mage = (c->magician && c->magician->number) ? c->magician : NULL;
|
||||
|
||||
/* copied from c_clearflag */
|
||||
if (global.data_version < EXPLICIT_CURSE_ISNEW_VERSION) {
|
||||
flags = (c->flags & ~CURSE_ISNEW) | (c->type->flags & CURSE_ISNEW);
|
||||
}
|
||||
else {
|
||||
flags = c->flags | c->type->flags;
|
||||
}
|
||||
#if RELEASE_VERSION < EXPLICIT_CURSE_ISNEW_VERSION
|
||||
flags = (c->flags & ~CURSE_ISNEW) | (c->type->flags & CURSE_ISNEW);
|
||||
#else
|
||||
flags = c->flags | c->type->flags;
|
||||
#endif
|
||||
|
||||
WRITE_INT(store, c->no);
|
||||
WRITE_TOK(store, ct->cname);
|
||||
|
|
|
@ -135,7 +135,7 @@ static void test_write_flag(CuTest *tc) {
|
|||
data.strm.api->rewind(data.strm.handle);
|
||||
curse_read(fix.r->attribs, fix.r, &data);
|
||||
CuAssertIntEquals(tc, 42 | CURSE_ISNEW, ((curse *) fix.r->attribs->data.v)->flags);
|
||||
global.data_version = RELEASE_VERSION;
|
||||
global.data_version = RELEASE_VERSION; // FIXME: should not need this!
|
||||
CuAssertIntEquals(tc, RELEASE_VERSION, global.data_version);
|
||||
|
||||
mstream_done(&data.strm);
|
||||
|
|
|
@ -1759,7 +1759,7 @@ int readgame(const char *filename, bool backup)
|
|||
}
|
||||
else {
|
||||
for (u = f->units; u; u = u->nextF) {
|
||||
if (global.data_version < SPELL_LEVEL_VERSION) {
|
||||
if (gdata.version < SPELL_LEVEL_VERSION) {
|
||||
sc_mage *mage = get_mage(u);
|
||||
if (mage) {
|
||||
faction *f = u->faction;
|
||||
|
@ -1778,12 +1778,12 @@ int readgame(const char *filename, bool backup)
|
|||
}
|
||||
if (u->number > 0) {
|
||||
f->_alive = true;
|
||||
if (global.data_version >= SPELL_LEVEL_VERSION) {
|
||||
if (gdata.version >= SPELL_LEVEL_VERSION) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (global.data_version < SPELL_LEVEL_VERSION && f->spellbook) {
|
||||
if (gdata.version < SPELL_LEVEL_VERSION && f->spellbook) {
|
||||
spellbook_foreach(f->spellbook, cb_sb_maxlevel, f);
|
||||
}
|
||||
}
|
||||
|
@ -1836,7 +1836,7 @@ int writegame(const char *filename)
|
|||
gdata.store = &store;
|
||||
gdata.encoding = enc_gamedata;
|
||||
gdata.version = RELEASE_VERSION;
|
||||
global.data_version = RELEASE_VERSION;
|
||||
global.data_version = RELEASE_VERSION; // FIXME: no code that is writing should need this
|
||||
n = STREAM_VERSION;
|
||||
fwrite(&gdata.version, sizeof(int), 1, F);
|
||||
fwrite(&n, sizeof(int), 1, F);
|
||||
|
|
|
@ -135,7 +135,7 @@ static int a_readicastle(attrib * a, void *owner, struct gamedata *data)
|
|||
icastle_data *idata = (icastle_data *)a->data.v;
|
||||
char token[32];
|
||||
READ_TOK(store, token, sizeof(token));
|
||||
if (global.data_version < ATTRIBOWNER_VERSION) {
|
||||
if (data->version < ATTRIBOWNER_VERSION) {
|
||||
READ_INT(store, NULL);
|
||||
}
|
||||
READ_INT(store, &idata->time);
|
||||
|
@ -378,7 +378,7 @@ static int read_seenspell(attrib * a, void *owner, struct gamedata *data)
|
|||
sp = find_spellbyid((unsigned int)i);
|
||||
}
|
||||
else {
|
||||
if (global.data_version < UNIQUE_SPELLS_VERSION) {
|
||||
if (data->version < UNIQUE_SPELLS_VERSION) {
|
||||
READ_INT(store, 0); /* ignore mtype */
|
||||
}
|
||||
sp = find_spell(token);
|
||||
|
|
|
@ -113,12 +113,12 @@ static int resolve_exit(variant id, void *address)
|
|||
static int wormhole_read(struct attrib *a, void *owner, struct gamedata *data)
|
||||
{
|
||||
storage *store = data->store;
|
||||
resolve_fun resolver = (global.data_version < UIDHASH_VERSION)
|
||||
resolve_fun resolver = (data->version < UIDHASH_VERSION)
|
||||
? resolve_exit : resolve_region_id;
|
||||
read_fun reader = (global.data_version < UIDHASH_VERSION)
|
||||
read_fun reader = (data->version < UIDHASH_VERSION)
|
||||
? read_building_reference : read_region_reference;
|
||||
|
||||
if (global.data_version < ATTRIBOWNER_VERSION) {
|
||||
if (data->version < ATTRIBOWNER_VERSION) {
|
||||
READ_INT(store, NULL);
|
||||
}
|
||||
if (read_reference(&a->data.v, store, reader, resolver) == 0) {
|
||||
|
|
Loading…
Reference in New Issue