diff --git a/src/attributes/dict.c b/src/attributes/dict.c index ca8208f51..fa65d1f3d 100644 --- a/src/attributes/dict.c +++ b/src/attributes/dict.c @@ -128,22 +128,22 @@ static int dict_read(attrib * a, void *owner, gamedata *data) break; case TBUILDING: result = - read_reference(&dd->data.b, store, read_building_reference, - resolve_building); + read_reference(&dd->data.b, data, read_building_reference, + resolve_building); if (result == 0 && !dd->data.b) { return AT_READ_FAIL; } break; case TUNIT: result = - read_reference(&dd->data.u, store, read_unit_reference, resolve_unit); + read_reference(&dd->data.u, data, read_unit_reference, resolve_unit); if (result == 0 && !dd->data.u) { return AT_READ_FAIL; } break; case TFACTION: result = - read_reference(&dd->data.f, store, read_faction_reference, + read_reference(&dd->data.f, data, read_faction_reference, resolve_faction); if (result == 0 && !dd->data.f) { return AT_READ_FAIL; @@ -151,7 +151,7 @@ static int dict_read(attrib * a, void *owner, gamedata *data) break; case TREGION: result = - read_reference(&dd->data.r, store, read_region_reference, + read_reference(&dd->data.r, data, read_region_reference, RESOLVE_REGION(data->version)); if (result == 0 && !dd->data.r) { return AT_READ_FAIL; diff --git a/src/attributes/follow.c b/src/attributes/follow.c index 719d3fc03..d68fcaebd 100644 --- a/src/attributes/follow.c +++ b/src/attributes/follow.c @@ -30,7 +30,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. static int read_follow(attrib * a, void *owner, gamedata *data) { - read_unit_reference(data->store); /* skip it */ + read_unit_reference(data); /* skip it */ return AT_READ_FAIL; } diff --git a/src/attributes/hate.c b/src/attributes/hate.c index 0d21bc97b..3d9a2fb0a 100644 --- a/src/attributes/hate.c +++ b/src/attributes/hate.c @@ -46,8 +46,8 @@ write_hate(const attrib * a, const void *owner, struct storage *store) static int read_hate(attrib * a, void *owner, gamedata *data) { - int result = - read_reference(&a->data.v, data->store, read_unit_reference, resolve_unit); + int result = read_reference(&a->data.v, data, read_unit_reference, + resolve_unit); if (result == 0 && !a->data.v) { return AT_READ_FAIL; } diff --git a/src/attributes/targetregion.c b/src/attributes/targetregion.c index f180ec70e..b293b458c 100644 --- a/src/attributes/targetregion.c +++ b/src/attributes/targetregion.c @@ -38,8 +38,7 @@ write_targetregion(const attrib * a, const void *owner, struct storage *store) static int read_targetregion(attrib * a, void *owner, gamedata *data) { - int result = - read_reference(&a->data.v, data->store, read_region_reference, + int result = read_reference(&a->data.v, data, read_region_reference, RESOLVE_REGION(data->version)); if (result == 0 && !a->data.v) return AT_READ_FAIL; diff --git a/src/building_action.c b/src/building_action.c index daf23224b..b6ce0f72c 100644 --- a/src/building_action.c +++ b/src/building_action.c @@ -107,7 +107,7 @@ static int lc_read(struct attrib *a, void *owner, gamedata *data) building *b = (building *)owner; int result = 0; if (data->version < ATTRIBOWNER_VERSION) { - result = read_reference(&b, store, read_building_reference, resolve_building); + result = read_reference(&b, data, read_building_reference, resolve_building); assert(b == owner); } READ_TOK(store, name, sizeof(name)); diff --git a/src/kernel/building.c b/src/kernel/building.c index 609b000c8..f0e46cc7e 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -386,10 +386,10 @@ int resolve_building(variant id, void *address) return result; } -variant read_building_reference(struct storage * store) +variant read_building_reference(gamedata * data) { variant result; - READ_INT(store, &result.i); + READ_INT(data->store, &result.i); return result; } diff --git a/src/kernel/building.h b/src/kernel/building.h index 4d08ae647..082cdb99f 100644 --- a/src/kernel/building.h +++ b/src/kernel/building.h @@ -158,7 +158,7 @@ extern "C" { extern int resolve_building(variant data, void *address); extern void write_building_reference(const struct building *b, struct storage *store); - extern variant read_building_reference(struct storage *store); + extern variant read_building_reference(struct gamedata *data); extern struct building *findbuilding(int n); diff --git a/src/kernel/curse.c b/src/kernel/curse.c index c62cd722d..66890475e 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -203,10 +203,10 @@ int curse_read(attrib * a, void *owner, gamedata *data) READ_FLT(store, &flt); c->vigour = flt; if (data->version < INTPAK_VERSION) { - ur = read_reference(&c->magician, store, read_int, resolve_unit); + ur = resolve_unit(read_int(data->store), &c->magician); } else { - ur = read_reference(&c->magician, store, read_unit_reference, resolve_unit); + ur = read_reference(&c->magician, data, read_unit_reference, resolve_unit); } if (data->version < CURSEFLOAT_VERSION) { READ_INT(store, &n); @@ -230,14 +230,15 @@ int curse_read(attrib * a, void *owner, gamedata *data) c_clearflag(c, CURSE_ISNEW); } - if (c->type->read) - c->type->read(store, c, owner); + if (c->type->read) { + c->type->read(data, c, owner); + } else if (c->type->typ == CURSETYP_UNIT) { READ_INT(store, &c->data.i); } if (c->type->typ == CURSETYP_REGION) { int rr = - read_reference(&c->data.v, store, read_region_reference, + read_reference(&c->data.v, data, read_region_reference, RESOLVE_REGION(data->version)); if (ur == 0 && rr == 0 && !c->data.v) { return AT_READ_FAIL; diff --git a/src/kernel/curse.h b/src/kernel/curse.h index 1aff1c2a1..77da43451 100644 --- a/src/kernel/curse.h +++ b/src/kernel/curse.h @@ -196,8 +196,8 @@ extern "C" { struct message *(*curseinfo) (const void *, objtype_t, const struct curse *, int); void(*change_vigour) (struct curse *, double); - int(*read) (struct storage * store, struct curse *, void *target); - int(*write) (struct storage * store, const struct curse *, + int(*read) (struct gamedata *data, struct curse *, void *target); + int(*write) (struct storage *store, const struct curse *, const void *target); int(*cansee) (const struct faction *, const void *, objtype_t, const struct curse *, int); diff --git a/src/kernel/curse.test.c b/src/kernel/curse.test.c index ae9e8576c..b8d765f72 100644 --- a/src/kernel/curse.test.c +++ b/src/kernel/curse.test.c @@ -135,8 +135,6 @@ 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; // FIXME: should not need this! - CuAssertIntEquals(tc, RELEASE_VERSION, global.data_version); mstream_done(&data.strm); gamedata_done(&data); diff --git a/src/kernel/faction.c b/src/kernel/faction.c index f8d240503..a330e6878 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -325,10 +325,10 @@ bool checkpasswd(const faction * f, const char *passwd) return true; } -variant read_faction_reference(struct storage * store) +variant read_faction_reference(gamedata * data) { variant id; - READ_INT(store, &id.i); + READ_INT(data->store, &id.i); return id; } diff --git a/src/kernel/faction.h b/src/kernel/faction.h index 6369444f5..8038cf640 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -133,7 +133,7 @@ extern "C" { void write_faction_reference(const struct faction *f, struct storage *store); - variant read_faction_reference(struct storage *store); + variant read_faction_reference(struct gamedata *store); int resolve_faction(variant data, void *addr); void renumber_faction(faction * f, int no); diff --git a/src/kernel/group.c b/src/kernel/group.c index 9cad91d6a..9a4de33de 100755 --- a/src/kernel/group.c +++ b/src/kernel/group.c @@ -236,7 +236,7 @@ void read_groups(gamedata *data, faction * f) ally *a; variant fid; - fid = read_faction_reference(store); + fid = read_faction_reference(data); if (fid.i <= 0) break; a = ally_add(pa, findfaction(fid.i)); diff --git a/src/kernel/region.c b/src/kernel/region.c index 85f677653..c3d0559bf 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -1226,10 +1226,11 @@ int resolve_region_id(variant id, void *address) return 0; } -variant read_region_reference(struct storage * store) +variant read_region_reference(gamedata *data) { + struct storage * store = data->store; variant result; - if (global.data_version < UIDHASH_VERSION) { + if (data->version < UIDHASH_VERSION) { int n; READ_INT(store, &n); result.sa[0] = (short)n; diff --git a/src/kernel/region.h b/src/kernel/region.h index 72496193b..7d250874e 100644 --- a/src/kernel/region.h +++ b/src/kernel/region.h @@ -255,7 +255,7 @@ extern "C" { void region_set_morale(region * r, int morale, int turn); void write_region_reference(const struct region *r, struct storage *store); - variant read_region_reference(struct storage *store); + variant read_region_reference(struct gamedata *data); int resolve_region_coor(variant id, void *address); int resolve_region_id(variant id, void *address); #define RESOLVE_REGION(version) ((versionflags); } if (data->version >= ALLIANCELEADER_VERSION) { - read_reference(&al->_leader, store, read_faction_reference, + read_reference(&al->_leader, data, read_faction_reference, resolve_faction); READ_INT(store, &id); } @@ -528,7 +528,7 @@ static void read_owner(struct gamedata *data, region_owner ** powner) else { owner->last_owner = NULL; } - read_reference(owner, data->store, &read_faction_reference, &resolve_owner); + read_reference(owner, data, &read_faction_reference, &resolve_owner); *powner = owner; } else { @@ -1579,9 +1579,9 @@ int readgame(const char *filename, bool backup) else { /* WATCHERS - eliminated in February 2016, ca. turn 966 */ if (gdata.version < NOWATCH_VERSION) { - fno = read_faction_reference(&store); + fno = read_faction_reference(&gdata); while (fno.i) { - fno = read_faction_reference(&store); + fno = read_faction_reference(&gdata); } } } diff --git a/src/kernel/unit.c b/src/kernel/unit.c index e6a69da09..5fc797e25 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -117,9 +117,9 @@ unit *findunitr(const region * r, int n) { unit *u; /* findunit regional! */ - assert(n>0); + assert(n > 0); u = ufindhash(n); - return (u && u->region==r)?u:0; + return (u && u->region == r) ? u : 0; } // TODO: deprecated, replace with findunit(n) @@ -583,8 +583,7 @@ void a_writesiege(const attrib * a, const void *owner, struct storage *store) int a_readsiege(attrib * a, void *owner, gamedata *data) { - struct storage *store = data->store; - int result = read_reference(&a->data.v, store, read_building_reference, + int result = read_reference(&a->data.v, data, read_building_reference, resolve_building); if (result == 0 && !a->data.v) { return AT_READ_FAIL; @@ -659,7 +658,7 @@ bool ucontact(const unit * u, const unit * u2) /* Explizites KONTAKTIERE */ for (ru = a_find(u->attribs, &at_contact); ru && ru->type == &at_contact; - ru = ru->next) { + ru = ru->next) { if (((unit *)ru->data.v) == u2) { return true; } @@ -701,10 +700,10 @@ int resolve_unit(variant id, void *address) return 0; } -variant read_unit_reference(struct storage * store) +variant read_unit_reference(gamedata *data) { variant var; - READ_INT(store, &var.i); + READ_INT(data->store, &var.i); return var; } @@ -833,7 +832,7 @@ bool can_leave(unit * u) rule_leave = config_get_int("rules.move.owner_leave", 0); - if (rule_leave!=0 && u->building && u == building_owner(u->building)) { + if (rule_leave != 0 && u->building && u == building_owner(u->building)) { return false; } return true; @@ -1004,7 +1003,7 @@ void transfermen(unit * u, unit * dst, int n) set_leftship(dst, sh); dst->flags |= u->flags & (UFL_LONGACTION | UFL_NOTMOVING | UFL_HUNGER | UFL_MOVED | - UFL_ENTER); + UFL_ENTER); if (u->attribs) { transfer_curse(u, dst, n); } @@ -1135,8 +1134,8 @@ bool learn_skill(unit * u, skill_t sk, double learn_chance) { skill *sv = u->skills; if (learn_chance < 1.0 && rng_int() % 10000 >= learn_chance * 10000) - if (!chance(learn_chance)) - return false; + if (!chance(learn_chance)) + return false; while (sv != u->skills + u->skill_size) { assert(sv->weeks > 0); if (sv->id == sk) { @@ -1283,7 +1282,8 @@ static int att_modification(const unit * u, skill_t sk) bool allied = alliedunit(c->magician, u->faction, HELP_GUARD); if (allied) { if (effect > bonus) bonus = effect; - } else { + } + else { if (effect < malus) malus = effect; } } @@ -1332,7 +1332,7 @@ int eff_skill(const unit * u, const skill *sv, const region *r) { assert(u); if (!r) r = u->region; - if (sv && sv->level>0) { + if (sv && sv->level > 0) { int mlevel = sv->level + get_modifier(u, sv->id, sv->level, r, false); if (mlevel > 0) { @@ -1421,10 +1421,10 @@ void default_name(const unit *u, char name[], int len) { static const char * prefix[MAXLOCALES]; int i = locale_index(lang); /*if (!prefix[i]) {*/ - prefix[i] = LOC(lang, "unitdefault"); - if (!prefix[i]) { - prefix[i] = parameters[P_UNIT]; - } + prefix[i] = LOC(lang, "unitdefault"); + if (!prefix[i]) { + prefix[i] = parameters[P_UNIT]; + } /*}*/ result = prefix[i]; } @@ -1736,7 +1736,7 @@ void scale_number(unit * u, int n) } if (u->number > 0) { for (a = a_find(u->attribs, &at_effect); a && a->type == &at_effect; - a = a->next) { + a = a->next) { effect_data *data = (effect_data *)a->data.v; int snew = data->value / u->number * n; if (n) { @@ -1896,7 +1896,7 @@ static double produceexp_chance(void) { return config_get_flt("study.from_use", 1.0 / 3); } -void produceexp_ex(struct unit *u, skill_t sk, int n, bool (*learn)(unit *, skill_t, double)) +void produceexp_ex(struct unit *u, skill_t sk, int n, bool(*learn)(unit *, skill_t, double)) { if (n != 0 && (is_monsters(u->faction) || playerrace(u_race(u)))) { double chance = produceexp_chance(); diff --git a/src/kernel/unit.h b/src/kernel/unit.h index e2dac5abe..ca2d52310 100644 --- a/src/kernel/unit.h +++ b/src/kernel/unit.h @@ -186,7 +186,7 @@ extern "C" { /* see resolve.h */ int resolve_unit(variant data, void *address); void write_unit_reference(const struct unit *u, struct storage *store); - variant read_unit_reference(struct storage *store); + variant read_unit_reference(struct gamedata *data); bool leave(struct unit *u, bool force); bool can_leave(struct unit *u); diff --git a/src/magic.c b/src/magic.c index 38e4157c6..e7d94ac25 100644 --- a/src/magic.c +++ b/src/magic.c @@ -2287,9 +2287,8 @@ static int resolve_familiar(variant data, void *addr) static int read_familiar(attrib * a, void *owner, struct gamedata *data) { - storage *store = data->store; int result = - read_reference(&a->data.v, store, read_unit_reference, resolve_familiar); + read_reference(&a->data.v, data, read_unit_reference, resolve_familiar); if (result == 0 && a->data.v == NULL) { return AT_READ_FAIL; } @@ -2372,9 +2371,8 @@ static int resolve_clone(variant data, void *addr) static int read_clone(attrib * a, void *owner, struct gamedata *data) { - storage *store = data->store; int result = - read_reference(&a->data.v, store, read_unit_reference, resolve_clone); + read_reference(&a->data.v, data, read_unit_reference, resolve_clone); if (result == 0 && a->data.v == NULL) { return AT_READ_FAIL; } @@ -2400,9 +2398,8 @@ static int resolve_mage(variant data, void *addr) static int read_magician(attrib * a, void *owner, struct gamedata *data) { - storage *store = data->store; int result = - read_reference(&a->data.v, store, read_unit_reference, resolve_mage); + read_reference(&a->data.v, data, read_unit_reference, resolve_mage); if (result == 0 && a->data.v == NULL) { return AT_READ_FAIL; } diff --git a/src/modules/arena.c b/src/modules/arena.c index f7ec90f07..97488218a 100644 --- a/src/modules/arena.c +++ b/src/modules/arena.c @@ -452,7 +452,7 @@ static void caldera_write(const trigger * t, struct storage *store) static int caldera_read(trigger * t, struct gamedata *data) { int rb = - read_reference(&t->data.v, data->store, read_building_reference, + read_reference(&t->data.v, data, read_building_reference, resolve_building); if (rb == 0 && !t->data.v) { return AT_READ_FAIL; diff --git a/src/modules/xmas.c b/src/modules/xmas.c index 657d97f8a..4b90af68e 100644 --- a/src/modules/xmas.c +++ b/src/modules/xmas.c @@ -51,7 +51,7 @@ static void xmasgate_write(const trigger * t, struct storage *store) static int xmasgate_read(trigger * t, struct gamedata *data) { int bc = - read_reference(&t->data.v, data->store, read_building_reference, + read_reference(&t->data.v, data, read_building_reference, resolve_building); if (bc == 0 && !t->data.v) { return AT_READ_FAIL; diff --git a/src/spells/alp.c b/src/spells/alp.c index fae9c468a..61c60df03 100644 --- a/src/spells/alp.c +++ b/src/spells/alp.c @@ -79,11 +79,10 @@ alp_write(const attrib * a, const void *owner, struct storage *store) static int alp_read(attrib * a, void *owner, struct gamedata *data) { - struct storage *store = data->store; alp_data *ad = (alp_data *)a->data.v; - int rm = read_reference(&ad->mage, store, read_unit_reference, resolve_unit); + int rm = read_reference(&ad->mage, data, read_unit_reference, resolve_unit); int rt = - read_reference(&ad->target, store, read_unit_reference, resolve_unit); + read_reference(&ad->target, data, read_unit_reference, resolve_unit); if (rt == 0 && rm == 0 && (!ad->target || !ad->mage)) { /* the target or mage disappeared. */ return AT_READ_FAIL; diff --git a/src/spells/borders.c b/src/spells/borders.c index 898632d4b..2c222a9dd 100644 --- a/src/spells/borders.c +++ b/src/spells/borders.c @@ -179,7 +179,7 @@ static void wall_read(connection * b, gamedata * data) static wall_data dummy; wall_data *fd = b->data.v ? (wall_data *)b->data.v : &dummy; - read_reference(&fd->mage, data->store, read_unit_reference, resolve_unit); + read_reference(&fd->mage, data, read_unit_reference, resolve_unit); READ_INT(data->store, &fd->force); if (data->version >= NOBORDERATTRIBS_VERSION) { READ_INT(data->store, &fd->countdown); diff --git a/src/spells/flyingship.c b/src/spells/flyingship.c index e8574db2b..c58ec270c 100644 --- a/src/spells/flyingship.c +++ b/src/spells/flyingship.c @@ -11,6 +11,8 @@ #include #include +#include + #include #include @@ -95,11 +97,11 @@ int sp_flying_ship(castorder * co) return cast_level; } -static int flyingship_read(storage * store, curse * c, void *target) +static int flyingship_read(gamedata * data, curse * c, void *target) { ship *sh = (ship *)target; c->data.v = sh; - if (global.data_version < FOSS_VERSION) { + if (data->version < FOSS_VERSION) { sh->flags |= SF_FLYING; return 0; } diff --git a/src/spells/unitcurse.c b/src/spells/unitcurse.c index 73925a55a..c29935479 100644 --- a/src/spells/unitcurse.c +++ b/src/spells/unitcurse.c @@ -25,6 +25,7 @@ #include /* util includes */ +#include #include #include #include @@ -307,10 +308,10 @@ static struct curse_type ct_oldrace = { * C_SKILL */ -static int read_skill(struct storage *store, curse * c, void *target) +static int read_skill(gamedata *data, curse * c, void *target) { int skill; - READ_INT(store, &skill); + READ_INT(data->store, &skill); c->data.i = skill; return 0; } diff --git a/src/triggers/changefaction.c b/src/triggers/changefaction.c index dd0440435..13785dfb9 100644 --- a/src/triggers/changefaction.c +++ b/src/triggers/changefaction.c @@ -88,8 +88,8 @@ static int changefaction_read(trigger * t, gamedata *data) variant var; changefaction_data *td = (changefaction_data *)t->data.v; - read_reference(&td->unit, data->store, read_unit_reference, resolve_unit); - var = read_faction_reference(data->store); + read_reference(&td->unit, data, read_unit_reference, resolve_unit); + var = read_faction_reference(data); if (var.i == 0) { return AT_READ_FAIL; } diff --git a/src/triggers/changerace.c b/src/triggers/changerace.c index 9ed3bbf39..0e7fc997e 100644 --- a/src/triggers/changerace.c +++ b/src/triggers/changerace.c @@ -90,7 +90,7 @@ static void changerace_write(const trigger * t, struct storage *store) static int changerace_read(trigger * t, gamedata *data) { changerace_data *td = (changerace_data *)t->data.v; - read_reference(&td->u, data->store, read_unit_reference, resolve_unit); + read_reference(&td->u, data, read_unit_reference, resolve_unit); td->race = (const struct race *)read_race_reference(data->store).v; td->irace = (const struct race *)read_race_reference(data->store).v; return AT_READ_OK; diff --git a/src/triggers/clonedied.c b/src/triggers/clonedied.c index 96b6d76f4..37693fdbf 100644 --- a/src/triggers/clonedied.c +++ b/src/triggers/clonedied.c @@ -72,7 +72,7 @@ static void clonedied_write(const trigger * t, struct storage *store) static int clonedied_read(trigger * t, gamedata *data) { int result = - read_reference(&t->data.v, data->store, read_unit_reference, resolve_unit); + read_reference(&t->data.v, data, read_unit_reference, resolve_unit); if (result == 0 && t->data.v == NULL) { return AT_READ_FAIL; } diff --git a/src/triggers/createcurse.c b/src/triggers/createcurse.c index 53be8b6a9..d0d65571b 100644 --- a/src/triggers/createcurse.c +++ b/src/triggers/createcurse.c @@ -100,8 +100,8 @@ static int createcurse_read(trigger * t, gamedata *data) char zText[128]; float flt; - read_reference(&td->mage, data->store, read_unit_reference, resolve_unit); - read_reference(&td->target, data->store, read_unit_reference, resolve_unit); + read_reference(&td->mage, data, read_unit_reference, resolve_unit); + read_reference(&td->target, data, read_unit_reference, resolve_unit); READ_TOK(data->store, zText, sizeof(zText)); td->type = ct_find(zText); diff --git a/src/triggers/createunit.c b/src/triggers/createunit.c index 6628777f4..31dfaaf7b 100644 --- a/src/triggers/createunit.c +++ b/src/triggers/createunit.c @@ -94,7 +94,7 @@ static int createunit_read(trigger * t, gamedata *data) createunit_data *td = (createunit_data *)t->data.v; variant var; int result = AT_READ_OK; - var = read_faction_reference(data->store); + var = read_faction_reference(data); if (var.i > 0) { td->f = findfaction(var.i); if (!td->f) { @@ -106,7 +106,7 @@ static int createunit_read(trigger * t, gamedata *data) } // read_reference(&td->f, store, read_faction_reference, resolve_faction); - read_reference(&td->r, data->store, read_region_reference, + read_reference(&td->r, data, read_region_reference, RESOLVE_REGION(global.data_version)); td->race = (const struct race *)read_race_reference(data->store).v; if (!td->race) { diff --git a/src/triggers/gate.c b/src/triggers/gate.c index 7f7123b9a..2a9c5693d 100644 --- a/src/triggers/gate.c +++ b/src/triggers/gate.c @@ -13,7 +13,7 @@ #include #include "gate.h" -/* kernel includes */ + /* kernel includes */ #include #include #include @@ -78,10 +78,10 @@ static int gate_read(trigger * t, gamedata *data) gate_data *gd = (gate_data *)t->data.v; int bc = - read_reference(&gd->gate, data->store, read_building_reference, resolve_building); + read_reference(&gd->gate, data, read_building_reference, resolve_building); int rc = - read_reference(&gd->target, data->store, read_region_reference, - RESOLVE_REGION(data->version)); + read_reference(&gd->target, data, read_region_reference, + RESOLVE_REGION(data->version)); if (bc == 0 && rc == 0) { if (!gd->gate || !gd->target) diff --git a/src/triggers/giveitem.c b/src/triggers/giveitem.c index 7cb11869f..d4a56162b 100644 --- a/src/triggers/giveitem.c +++ b/src/triggers/giveitem.c @@ -88,7 +88,7 @@ static int giveitem_read(trigger * t, gamedata *data) giveitem_data *td = (giveitem_data *)t->data.v; char zText[128]; - int result = read_reference(&td->u, data->store, read_unit_reference, resolve_unit); + int result = read_reference(&td->u, data, read_unit_reference, resolve_unit); READ_INT(data->store, &td->number); READ_TOK(data->store, zText, sizeof(zText)); diff --git a/src/triggers/killunit.c b/src/triggers/killunit.c index 25a990dbe..23275a6af 100644 --- a/src/triggers/killunit.c +++ b/src/triggers/killunit.c @@ -61,8 +61,8 @@ static void killunit_write(const trigger * t, struct storage *store) static int killunit_read(trigger * t, gamedata *data) { - int result = - read_reference(&t->data.v, data->store, read_unit_reference, resolve_unit); + int result = read_reference(&t->data.v, data, read_unit_reference, + resolve_unit); if (result == 0 && t->data.v == NULL) { return AT_READ_FAIL; } diff --git a/src/triggers/removecurse.c b/src/triggers/removecurse.c index 97655ed5e..d44f9dc22 100644 --- a/src/triggers/removecurse.c +++ b/src/triggers/removecurse.c @@ -78,12 +78,16 @@ static void removecurse_write(const trigger * t, struct storage *store) WRITE_INT(store, td->curse ? td->curse->no : 0); } +static variant read_curse_reference(struct gamedata *data) { + return read_int(data->store); +} + static int removecurse_read(trigger * t, gamedata *data) { removecurse_data *td = (removecurse_data *)t->data.v; - read_reference(&td->target, data->store, read_unit_reference, resolve_unit); - read_reference(&td->curse, data->store, read_int, resolve_curse); + read_reference(&td->target, data, read_unit_reference, resolve_unit); + read_reference(&td->curse, data, read_curse_reference, resolve_curse); return AT_READ_OK; } diff --git a/src/triggers/shock.c b/src/triggers/shock.c index 1cfabc6c1..75904e346 100644 --- a/src/triggers/shock.c +++ b/src/triggers/shock.c @@ -129,7 +129,7 @@ static void shock_write(const trigger * t, struct storage *store) static int shock_read(trigger * t, gamedata *data) { int result = - read_reference(&t->data.v, data->store, read_unit_reference, resolve_unit); + read_reference(&t->data.v, data, read_unit_reference, resolve_unit); if (result == 0 && t->data.v == NULL) { return AT_READ_FAIL; } diff --git a/src/triggers/unguard.c b/src/triggers/unguard.c index 7ee306e4c..e6471f977 100644 --- a/src/triggers/unguard.c +++ b/src/triggers/unguard.c @@ -51,8 +51,7 @@ static void unguard_write(const trigger * t, struct storage *store) static int unguard_read(trigger * t, gamedata *data) { - int rb = - read_reference(&t->data.v, data->store, read_building_reference, + int rb = read_reference(&t->data.v, data, read_building_reference, resolve_building); if (rb == 0 && !t->data.v) { return AT_READ_FAIL; diff --git a/src/triggers/unitmessage.c b/src/triggers/unitmessage.c index 849cfd357..2d869fc49 100644 --- a/src/triggers/unitmessage.c +++ b/src/triggers/unitmessage.c @@ -90,8 +90,8 @@ static int unitmessage_read(trigger * t, gamedata *data) unitmessage_data *td = (unitmessage_data *)t->data.v; char zText[256]; - int result = - read_reference(&td->target, data->store, read_unit_reference, resolve_unit); + int result = read_reference(&td->target, data, read_unit_reference, + resolve_unit); READ_TOK(data->store, zText, sizeof(zText)); td->string = _strdup(zText); READ_INT(data->store, &td->type); diff --git a/src/util/resolve.c b/src/util/resolve.c index e8dd0c17a..63ef5d933 100644 --- a/src/util/resolve.c +++ b/src/util/resolve.c @@ -45,10 +45,10 @@ variant read_int(struct storage *store) } int -read_reference(void *address, storage * store, read_fun reader, -resolve_fun resolver) +read_reference(void *address, struct gamedata * data, read_fun reader, + resolve_fun resolver) { - variant var = reader(store); + variant var = reader(data); int result = resolver(var, address); if (result != 0) { ur_add(var, address, resolver); diff --git a/src/util/resolve.h b/src/util/resolve.h index 8d24cc359..c9292a356 100644 --- a/src/util/resolve.h +++ b/src/util/resolve.h @@ -27,8 +27,8 @@ extern "C" { #endif typedef int(*resolve_fun) (variant data, void *address); - typedef variant(*read_fun) (struct storage * store); - extern int read_reference(void *address, struct storage *store, + typedef variant(*read_fun) (struct gamedata * data); + extern int read_reference(void *address, struct gamedata *data, read_fun reader, resolve_fun resolver); extern void ur_add(variant data, void *address, resolve_fun fun); diff --git a/src/wormhole.c b/src/wormhole.c index 0944abd44..36e04e9e0 100644 --- a/src/wormhole.c +++ b/src/wormhole.c @@ -121,7 +121,7 @@ static int wormhole_read(struct attrib *a, void *owner, struct gamedata *data) if (data->version < ATTRIBOWNER_VERSION) { READ_INT(store, NULL); } - if (read_reference(&a->data.v, store, reader, resolver) == 0) { + if (read_reference(&a->data.v, data, reader, resolver) == 0) { if (!a->data.v) { return AT_READ_FAIL; }