From 3e584245c05b8aba5b9ea3e1822b9544f570b7a7 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 13 Feb 2016 14:09:36 +0100 Subject: [PATCH] attrib.read gets a gamedata object stop using global.data_version for github issue #479 --- src/attributes/dict.c | 2 +- src/attributes/targetregion.c | 2 +- src/building_action.c | 2 +- src/kernel/connection.c | 2 +- src/kernel/curse.c | 13 ++++++------- src/kernel/curse.test.c | 2 +- src/kernel/save.c | 8 ++++---- src/magic.c | 4 ++-- src/wormhole.c | 6 +++--- 9 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/attributes/dict.c b/src/attributes/dict.c index 1a125ab53..ca8208f51 100644 --- a/src/attributes/dict.c +++ b/src/attributes/dict.c @@ -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; } diff --git a/src/attributes/targetregion.c b/src/attributes/targetregion.c index 2cb9d7571..f180ec70e 100644 --- a/src/attributes/targetregion.c +++ b/src/attributes/targetregion.c @@ -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; diff --git a/src/building_action.c b/src/building_action.c index 14e807c21..daf23224b 100644 --- a/src/building_action.c +++ b/src/building_action.c @@ -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); } diff --git a/src/kernel/connection.c b/src/kernel/connection.c index 1f47e7311..c1d6c26b6 100644 --- a/src/kernel/connection.c +++ b/src/kernel/connection.c @@ -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) { diff --git a/src/kernel/curse.c b/src/kernel/curse.c index 40da4a332..c62cd722d 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -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); diff --git a/src/kernel/curse.test.c b/src/kernel/curse.test.c index cb81e9388..ae9e8576c 100644 --- a/src/kernel/curse.test.c +++ b/src/kernel/curse.test.c @@ -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); diff --git a/src/kernel/save.c b/src/kernel/save.c index fc7c79ade..9cde4710a 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -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); diff --git a/src/magic.c b/src/magic.c index c7a31ccf6..b2cda2e18 100644 --- a/src/magic.c +++ b/src/magic.c @@ -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); diff --git a/src/wormhole.c b/src/wormhole.c index 5974d7ee0..0944abd44 100644 --- a/src/wormhole.c +++ b/src/wormhole.c @@ -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) {