read_referernce takes a gamedata object.

with all the trimmings that requires,
this is for github issue $479
This commit is contained in:
Enno Rehling 2016-02-13 20:38:32 +01:00
parent 2e41c4972c
commit 8a9d617aa3
40 changed files with 99 additions and 98 deletions

View file

@ -128,7 +128,7 @@ static int dict_read(attrib * a, void *owner, gamedata *data)
break; break;
case TBUILDING: case TBUILDING:
result = result =
read_reference(&dd->data.b, store, read_building_reference, read_reference(&dd->data.b, data, read_building_reference,
resolve_building); resolve_building);
if (result == 0 && !dd->data.b) { if (result == 0 && !dd->data.b) {
return AT_READ_FAIL; return AT_READ_FAIL;
@ -136,14 +136,14 @@ static int dict_read(attrib * a, void *owner, gamedata *data)
break; break;
case TUNIT: case TUNIT:
result = 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) { if (result == 0 && !dd->data.u) {
return AT_READ_FAIL; return AT_READ_FAIL;
} }
break; break;
case TFACTION: case TFACTION:
result = result =
read_reference(&dd->data.f, store, read_faction_reference, read_reference(&dd->data.f, data, read_faction_reference,
resolve_faction); resolve_faction);
if (result == 0 && !dd->data.f) { if (result == 0 && !dd->data.f) {
return AT_READ_FAIL; return AT_READ_FAIL;
@ -151,7 +151,7 @@ static int dict_read(attrib * a, void *owner, gamedata *data)
break; break;
case TREGION: case TREGION:
result = result =
read_reference(&dd->data.r, store, read_region_reference, read_reference(&dd->data.r, data, read_region_reference,
RESOLVE_REGION(data->version)); RESOLVE_REGION(data->version));
if (result == 0 && !dd->data.r) { if (result == 0 && !dd->data.r) {
return AT_READ_FAIL; return AT_READ_FAIL;

View file

@ -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) 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; return AT_READ_FAIL;
} }

View file

@ -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) static int read_hate(attrib * a, void *owner, gamedata *data)
{ {
int result = int result = read_reference(&a->data.v, data, read_unit_reference,
read_reference(&a->data.v, data->store, read_unit_reference, resolve_unit); resolve_unit);
if (result == 0 && !a->data.v) { if (result == 0 && !a->data.v) {
return AT_READ_FAIL; return AT_READ_FAIL;
} }

View file

@ -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) static int read_targetregion(attrib * a, void *owner, gamedata *data)
{ {
int result = int result = read_reference(&a->data.v, data, read_region_reference,
read_reference(&a->data.v, data->store, read_region_reference,
RESOLVE_REGION(data->version)); RESOLVE_REGION(data->version));
if (result == 0 && !a->data.v) if (result == 0 && !a->data.v)
return AT_READ_FAIL; return AT_READ_FAIL;

View file

@ -107,7 +107,7 @@ static int lc_read(struct attrib *a, void *owner, gamedata *data)
building *b = (building *)owner; building *b = (building *)owner;
int result = 0; int result = 0;
if (data->version < ATTRIBOWNER_VERSION) { 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); assert(b == owner);
} }
READ_TOK(store, name, sizeof(name)); READ_TOK(store, name, sizeof(name));

View file

@ -386,10 +386,10 @@ int resolve_building(variant id, void *address)
return result; return result;
} }
variant read_building_reference(struct storage * store) variant read_building_reference(gamedata * data)
{ {
variant result; variant result;
READ_INT(store, &result.i); READ_INT(data->store, &result.i);
return result; return result;
} }

View file

@ -158,7 +158,7 @@ extern "C" {
extern int resolve_building(variant data, void *address); extern int resolve_building(variant data, void *address);
extern void write_building_reference(const struct building *b, extern void write_building_reference(const struct building *b,
struct storage *store); 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); extern struct building *findbuilding(int n);

View file

@ -203,10 +203,10 @@ int curse_read(attrib * a, void *owner, gamedata *data)
READ_FLT(store, &flt); READ_FLT(store, &flt);
c->vigour = flt; c->vigour = flt;
if (data->version < INTPAK_VERSION) { 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 { 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) { if (data->version < CURSEFLOAT_VERSION) {
READ_INT(store, &n); READ_INT(store, &n);
@ -230,14 +230,15 @@ int curse_read(attrib * a, void *owner, gamedata *data)
c_clearflag(c, CURSE_ISNEW); c_clearflag(c, CURSE_ISNEW);
} }
if (c->type->read) if (c->type->read) {
c->type->read(store, c, owner); c->type->read(data, c, owner);
}
else if (c->type->typ == CURSETYP_UNIT) { else if (c->type->typ == CURSETYP_UNIT) {
READ_INT(store, &c->data.i); READ_INT(store, &c->data.i);
} }
if (c->type->typ == CURSETYP_REGION) { if (c->type->typ == CURSETYP_REGION) {
int rr = int rr =
read_reference(&c->data.v, store, read_region_reference, read_reference(&c->data.v, data, read_region_reference,
RESOLVE_REGION(data->version)); RESOLVE_REGION(data->version));
if (ur == 0 && rr == 0 && !c->data.v) { if (ur == 0 && rr == 0 && !c->data.v) {
return AT_READ_FAIL; return AT_READ_FAIL;

View file

@ -196,7 +196,7 @@ extern "C" {
struct message *(*curseinfo) (const void *, objtype_t, struct message *(*curseinfo) (const void *, objtype_t,
const struct curse *, int); const struct curse *, int);
void(*change_vigour) (struct curse *, double); void(*change_vigour) (struct curse *, double);
int(*read) (struct storage * store, struct curse *, void *target); int(*read) (struct gamedata *data, struct curse *, void *target);
int(*write) (struct storage *store, const struct curse *, int(*write) (struct storage *store, const struct curse *,
const void *target); const void *target);
int(*cansee) (const struct faction *, const void *, objtype_t, int(*cansee) (const struct faction *, const void *, objtype_t,

View file

@ -135,8 +135,6 @@ static void test_write_flag(CuTest *tc) {
data.strm.api->rewind(data.strm.handle); data.strm.api->rewind(data.strm.handle);
curse_read(fix.r->attribs, fix.r, &data); curse_read(fix.r->attribs, fix.r, &data);
CuAssertIntEquals(tc, 42 | CURSE_ISNEW, ((curse *) fix.r->attribs->data.v)->flags); 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); mstream_done(&data.strm);
gamedata_done(&data); gamedata_done(&data);

View file

@ -325,10 +325,10 @@ bool checkpasswd(const faction * f, const char *passwd)
return true; return true;
} }
variant read_faction_reference(struct storage * store) variant read_faction_reference(gamedata * data)
{ {
variant id; variant id;
READ_INT(store, &id.i); READ_INT(data->store, &id.i);
return id; return id;
} }

View file

@ -133,7 +133,7 @@ extern "C" {
void write_faction_reference(const struct faction *f, void write_faction_reference(const struct faction *f,
struct storage *store); struct storage *store);
variant read_faction_reference(struct storage *store); variant read_faction_reference(struct gamedata *store);
int resolve_faction(variant data, void *addr); int resolve_faction(variant data, void *addr);
void renumber_faction(faction * f, int no); void renumber_faction(faction * f, int no);

View file

@ -236,7 +236,7 @@ void read_groups(gamedata *data, faction * f)
ally *a; ally *a;
variant fid; variant fid;
fid = read_faction_reference(store); fid = read_faction_reference(data);
if (fid.i <= 0) if (fid.i <= 0)
break; break;
a = ally_add(pa, findfaction(fid.i)); a = ally_add(pa, findfaction(fid.i));

View file

@ -1226,10 +1226,11 @@ int resolve_region_id(variant id, void *address)
return 0; return 0;
} }
variant read_region_reference(struct storage * store) variant read_region_reference(gamedata *data)
{ {
struct storage * store = data->store;
variant result; variant result;
if (global.data_version < UIDHASH_VERSION) { if (data->version < UIDHASH_VERSION) {
int n; int n;
READ_INT(store, &n); READ_INT(store, &n);
result.sa[0] = (short)n; result.sa[0] = (short)n;

View file

@ -255,7 +255,7 @@ extern "C" {
void region_set_morale(region * r, int morale, int turn); void region_set_morale(region * r, int morale, int turn);
void write_region_reference(const struct region *r, struct storage *store); 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_coor(variant id, void *address);
int resolve_region_id(variant id, void *address); int resolve_region_id(variant id, void *address);
#define RESOLVE_REGION(version) ((version<UIDHASH_VERSION)?resolve_region_coor:resolve_region_id) #define RESOLVE_REGION(version) ((version<UIDHASH_VERSION)?resolve_region_coor:resolve_region_id)

View file

@ -441,7 +441,7 @@ static void read_alliances(struct gamedata *data)
READ_INT(store, &al->flags); READ_INT(store, &al->flags);
} }
if (data->version >= ALLIANCELEADER_VERSION) { if (data->version >= ALLIANCELEADER_VERSION) {
read_reference(&al->_leader, store, read_faction_reference, read_reference(&al->_leader, data, read_faction_reference,
resolve_faction); resolve_faction);
READ_INT(store, &id); READ_INT(store, &id);
} }
@ -528,7 +528,7 @@ static void read_owner(struct gamedata *data, region_owner ** powner)
else { else {
owner->last_owner = NULL; 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; *powner = owner;
} }
else { else {
@ -1579,9 +1579,9 @@ int readgame(const char *filename, bool backup)
else { else {
/* WATCHERS - eliminated in February 2016, ca. turn 966 */ /* WATCHERS - eliminated in February 2016, ca. turn 966 */
if (gdata.version < NOWATCH_VERSION) { if (gdata.version < NOWATCH_VERSION) {
fno = read_faction_reference(&store); fno = read_faction_reference(&gdata);
while (fno.i) { while (fno.i) {
fno = read_faction_reference(&store); fno = read_faction_reference(&gdata);
} }
} }
} }

View file

@ -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) int a_readsiege(attrib * a, void *owner, gamedata *data)
{ {
struct storage *store = data->store; int result = read_reference(&a->data.v, data, read_building_reference,
int result = read_reference(&a->data.v, store, read_building_reference,
resolve_building); resolve_building);
if (result == 0 && !a->data.v) { if (result == 0 && !a->data.v) {
return AT_READ_FAIL; return AT_READ_FAIL;
@ -701,10 +700,10 @@ int resolve_unit(variant id, void *address)
return 0; return 0;
} }
variant read_unit_reference(struct storage * store) variant read_unit_reference(gamedata *data)
{ {
variant var; variant var;
READ_INT(store, &var.i); READ_INT(data->store, &var.i);
return var; return var;
} }
@ -1283,7 +1282,8 @@ static int att_modification(const unit * u, skill_t sk)
bool allied = alliedunit(c->magician, u->faction, HELP_GUARD); bool allied = alliedunit(c->magician, u->faction, HELP_GUARD);
if (allied) { if (allied) {
if (effect > bonus) bonus = effect; if (effect > bonus) bonus = effect;
} else { }
else {
if (effect < malus) malus = effect; if (effect < malus) malus = effect;
} }
} }

View file

@ -186,7 +186,7 @@ extern "C" {
/* see resolve.h */ /* see resolve.h */
int resolve_unit(variant data, void *address); int resolve_unit(variant data, void *address);
void write_unit_reference(const struct unit *u, struct storage *store); 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 leave(struct unit *u, bool force);
bool can_leave(struct unit *u); bool can_leave(struct unit *u);

View file

@ -2287,9 +2287,8 @@ static int resolve_familiar(variant data, void *addr)
static int read_familiar(attrib * a, void *owner, struct gamedata *data) static int read_familiar(attrib * a, void *owner, struct gamedata *data)
{ {
storage *store = data->store;
int result = 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) { if (result == 0 && a->data.v == NULL) {
return AT_READ_FAIL; 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) static int read_clone(attrib * a, void *owner, struct gamedata *data)
{ {
storage *store = data->store;
int result = 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) { if (result == 0 && a->data.v == NULL) {
return AT_READ_FAIL; 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) static int read_magician(attrib * a, void *owner, struct gamedata *data)
{ {
storage *store = data->store;
int result = 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) { if (result == 0 && a->data.v == NULL) {
return AT_READ_FAIL; return AT_READ_FAIL;
} }

View file

@ -452,7 +452,7 @@ static void caldera_write(const trigger * t, struct storage *store)
static int caldera_read(trigger * t, struct gamedata *data) static int caldera_read(trigger * t, struct gamedata *data)
{ {
int rb = int rb =
read_reference(&t->data.v, data->store, read_building_reference, read_reference(&t->data.v, data, read_building_reference,
resolve_building); resolve_building);
if (rb == 0 && !t->data.v) { if (rb == 0 && !t->data.v) {
return AT_READ_FAIL; return AT_READ_FAIL;

View file

@ -51,7 +51,7 @@ static void xmasgate_write(const trigger * t, struct storage *store)
static int xmasgate_read(trigger * t, struct gamedata *data) static int xmasgate_read(trigger * t, struct gamedata *data)
{ {
int bc = int bc =
read_reference(&t->data.v, data->store, read_building_reference, read_reference(&t->data.v, data, read_building_reference,
resolve_building); resolve_building);
if (bc == 0 && !t->data.v) { if (bc == 0 && !t->data.v) {
return AT_READ_FAIL; return AT_READ_FAIL;

View file

@ -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) static int alp_read(attrib * a, void *owner, struct gamedata *data)
{ {
struct storage *store = data->store;
alp_data *ad = (alp_data *)a->data.v; 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 = 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)) { if (rt == 0 && rm == 0 && (!ad->target || !ad->mage)) {
/* the target or mage disappeared. */ /* the target or mage disappeared. */
return AT_READ_FAIL; return AT_READ_FAIL;

View file

@ -179,7 +179,7 @@ static void wall_read(connection * b, gamedata * data)
static wall_data dummy; static wall_data dummy;
wall_data *fd = b->data.v ? (wall_data *)b->data.v : &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); READ_INT(data->store, &fd->force);
if (data->version >= NOBORDERATTRIBS_VERSION) { if (data->version >= NOBORDERATTRIBS_VERSION) {
READ_INT(data->store, &fd->countdown); READ_INT(data->store, &fd->countdown);

View file

@ -11,6 +11,8 @@
#include <kernel/unit.h> #include <kernel/unit.h>
#include <kernel/ship.h> #include <kernel/ship.h>
#include <util/gamedata.h>
#include <magic.h> #include <magic.h>
#include <spells/shipcurse.h> #include <spells/shipcurse.h>
@ -95,11 +97,11 @@ int sp_flying_ship(castorder * co)
return cast_level; 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; ship *sh = (ship *)target;
c->data.v = sh; c->data.v = sh;
if (global.data_version < FOSS_VERSION) { if (data->version < FOSS_VERSION) {
sh->flags |= SF_FLYING; sh->flags |= SF_FLYING;
return 0; return 0;
} }

View file

@ -25,6 +25,7 @@
#include <kernel/version.h> #include <kernel/version.h>
/* util includes */ /* util includes */
#include <util/gamedata.h>
#include <util/language.h> #include <util/language.h>
#include <util/nrmessage.h> #include <util/nrmessage.h>
#include <util/message.h> #include <util/message.h>
@ -307,10 +308,10 @@ static struct curse_type ct_oldrace = {
* C_SKILL * 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; int skill;
READ_INT(store, &skill); READ_INT(data->store, &skill);
c->data.i = skill; c->data.i = skill;
return 0; return 0;
} }

View file

@ -88,8 +88,8 @@ static int changefaction_read(trigger * t, gamedata *data)
variant var; variant var;
changefaction_data *td = (changefaction_data *)t->data.v; changefaction_data *td = (changefaction_data *)t->data.v;
read_reference(&td->unit, data->store, read_unit_reference, resolve_unit); read_reference(&td->unit, data, read_unit_reference, resolve_unit);
var = read_faction_reference(data->store); var = read_faction_reference(data);
if (var.i == 0) { if (var.i == 0) {
return AT_READ_FAIL; return AT_READ_FAIL;
} }

View file

@ -90,7 +90,7 @@ static void changerace_write(const trigger * t, struct storage *store)
static int changerace_read(trigger * t, gamedata *data) static int changerace_read(trigger * t, gamedata *data)
{ {
changerace_data *td = (changerace_data *)t->data.v; 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->race = (const struct race *)read_race_reference(data->store).v;
td->irace = (const struct race *)read_race_reference(data->store).v; td->irace = (const struct race *)read_race_reference(data->store).v;
return AT_READ_OK; return AT_READ_OK;

View file

@ -72,7 +72,7 @@ static void clonedied_write(const trigger * t, struct storage *store)
static int clonedied_read(trigger * t, gamedata *data) static int clonedied_read(trigger * t, gamedata *data)
{ {
int result = 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) { if (result == 0 && t->data.v == NULL) {
return AT_READ_FAIL; return AT_READ_FAIL;
} }

View file

@ -100,8 +100,8 @@ static int createcurse_read(trigger * t, gamedata *data)
char zText[128]; char zText[128];
float flt; float flt;
read_reference(&td->mage, data->store, read_unit_reference, resolve_unit); read_reference(&td->mage, data, read_unit_reference, resolve_unit);
read_reference(&td->target, data->store, read_unit_reference, resolve_unit); read_reference(&td->target, data, read_unit_reference, resolve_unit);
READ_TOK(data->store, zText, sizeof(zText)); READ_TOK(data->store, zText, sizeof(zText));
td->type = ct_find(zText); td->type = ct_find(zText);

View file

@ -94,7 +94,7 @@ static int createunit_read(trigger * t, gamedata *data)
createunit_data *td = (createunit_data *)t->data.v; createunit_data *td = (createunit_data *)t->data.v;
variant var; variant var;
int result = AT_READ_OK; int result = AT_READ_OK;
var = read_faction_reference(data->store); var = read_faction_reference(data);
if (var.i > 0) { if (var.i > 0) {
td->f = findfaction(var.i); td->f = findfaction(var.i);
if (!td->f) { 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->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)); RESOLVE_REGION(global.data_version));
td->race = (const struct race *)read_race_reference(data->store).v; td->race = (const struct race *)read_race_reference(data->store).v;
if (!td->race) { if (!td->race) {

View file

@ -78,9 +78,9 @@ static int gate_read(trigger * t, gamedata *data)
gate_data *gd = (gate_data *)t->data.v; gate_data *gd = (gate_data *)t->data.v;
int bc = 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 = int rc =
read_reference(&gd->target, data->store, read_region_reference, read_reference(&gd->target, data, read_region_reference,
RESOLVE_REGION(data->version)); RESOLVE_REGION(data->version));
if (bc == 0 && rc == 0) { if (bc == 0 && rc == 0) {

View file

@ -88,7 +88,7 @@ static int giveitem_read(trigger * t, gamedata *data)
giveitem_data *td = (giveitem_data *)t->data.v; giveitem_data *td = (giveitem_data *)t->data.v;
char zText[128]; 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_INT(data->store, &td->number);
READ_TOK(data->store, zText, sizeof(zText)); READ_TOK(data->store, zText, sizeof(zText));

View file

@ -61,8 +61,8 @@ static void killunit_write(const trigger * t, struct storage *store)
static int killunit_read(trigger * t, gamedata *data) static int killunit_read(trigger * t, gamedata *data)
{ {
int result = int result = read_reference(&t->data.v, data, read_unit_reference,
read_reference(&t->data.v, data->store, read_unit_reference, resolve_unit); resolve_unit);
if (result == 0 && t->data.v == NULL) { if (result == 0 && t->data.v == NULL) {
return AT_READ_FAIL; return AT_READ_FAIL;
} }

View file

@ -78,12 +78,16 @@ static void removecurse_write(const trigger * t, struct storage *store)
WRITE_INT(store, td->curse ? td->curse->no : 0); 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) static int removecurse_read(trigger * t, gamedata *data)
{ {
removecurse_data *td = (removecurse_data *)t->data.v; removecurse_data *td = (removecurse_data *)t->data.v;
read_reference(&td->target, data->store, read_unit_reference, resolve_unit); read_reference(&td->target, data, read_unit_reference, resolve_unit);
read_reference(&td->curse, data->store, read_int, resolve_curse); read_reference(&td->curse, data, read_curse_reference, resolve_curse);
return AT_READ_OK; return AT_READ_OK;
} }

View file

@ -129,7 +129,7 @@ static void shock_write(const trigger * t, struct storage *store)
static int shock_read(trigger * t, gamedata *data) static int shock_read(trigger * t, gamedata *data)
{ {
int result = 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) { if (result == 0 && t->data.v == NULL) {
return AT_READ_FAIL; return AT_READ_FAIL;
} }

View file

@ -51,8 +51,7 @@ static void unguard_write(const trigger * t, struct storage *store)
static int unguard_read(trigger * t, gamedata *data) static int unguard_read(trigger * t, gamedata *data)
{ {
int rb = int rb = read_reference(&t->data.v, data, read_building_reference,
read_reference(&t->data.v, data->store, read_building_reference,
resolve_building); resolve_building);
if (rb == 0 && !t->data.v) { if (rb == 0 && !t->data.v) {
return AT_READ_FAIL; return AT_READ_FAIL;

View file

@ -90,8 +90,8 @@ static int unitmessage_read(trigger * t, gamedata *data)
unitmessage_data *td = (unitmessage_data *)t->data.v; unitmessage_data *td = (unitmessage_data *)t->data.v;
char zText[256]; char zText[256];
int result = int result = read_reference(&td->target, data, read_unit_reference,
read_reference(&td->target, data->store, read_unit_reference, resolve_unit); resolve_unit);
READ_TOK(data->store, zText, sizeof(zText)); READ_TOK(data->store, zText, sizeof(zText));
td->string = _strdup(zText); td->string = _strdup(zText);
READ_INT(data->store, &td->type); READ_INT(data->store, &td->type);

View file

@ -45,10 +45,10 @@ variant read_int(struct storage *store)
} }
int int
read_reference(void *address, storage * store, read_fun reader, read_reference(void *address, struct gamedata * data, read_fun reader,
resolve_fun resolver) resolve_fun resolver)
{ {
variant var = reader(store); variant var = reader(data);
int result = resolver(var, address); int result = resolver(var, address);
if (result != 0) { if (result != 0) {
ur_add(var, address, resolver); ur_add(var, address, resolver);

View file

@ -27,8 +27,8 @@ extern "C" {
#endif #endif
typedef int(*resolve_fun) (variant data, void *address); typedef int(*resolve_fun) (variant data, void *address);
typedef variant(*read_fun) (struct storage * store); typedef variant(*read_fun) (struct gamedata * data);
extern int read_reference(void *address, struct storage *store, extern int read_reference(void *address, struct gamedata *data,
read_fun reader, resolve_fun resolver); read_fun reader, resolve_fun resolver);
extern void ur_add(variant data, void *address, resolve_fun fun); extern void ur_add(variant data, void *address, resolve_fun fun);

View file

@ -121,7 +121,7 @@ static int wormhole_read(struct attrib *a, void *owner, struct gamedata *data)
if (data->version < ATTRIBOWNER_VERSION) { if (data->version < ATTRIBOWNER_VERSION) {
READ_INT(store, NULL); 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) { if (!a->data.v) {
return AT_READ_FAIL; return AT_READ_FAIL;
} }