forked from github/server
attrib.read gets a gamedata object (remove dependency on global.data_version)
This commit is contained in:
parent
d1fdd9a89c
commit
7f6ced99b9
40 changed files with 225 additions and 175 deletions
|
@ -33,6 +33,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/log.h>
|
||||
#include <util/rand.h>
|
||||
|
@ -301,8 +302,9 @@ a_writeeffect(const attrib * a, const void *owner, struct storage *store)
|
|||
WRITE_INT(store, edata->value);
|
||||
}
|
||||
|
||||
static int a_readeffect(attrib * a, void *owner, struct storage *store)
|
||||
static int a_readeffect(attrib * a, void *owner, struct gamedata *data)
|
||||
{
|
||||
struct storage *store = data->store;
|
||||
int power;
|
||||
const resource_type *rtype;
|
||||
effect_data *edata = (effect_data *)a->data.v;
|
||||
|
|
|
@ -57,6 +57,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/event.h>
|
||||
#include <util/gamedata.h>
|
||||
|
||||
#include <storage.h>
|
||||
|
||||
|
@ -64,12 +65,12 @@ attrib_type at_unitdissolve = {
|
|||
"unitdissolve", NULL, NULL, NULL, a_writechars, a_readchars
|
||||
};
|
||||
|
||||
static int read_ext(attrib * a, void *owner, struct storage *store)
|
||||
static int read_ext(attrib * a, void *owner, gamedata *data)
|
||||
{
|
||||
int len;
|
||||
|
||||
READ_INT(store, &len);
|
||||
store->api->r_bin(store->handle, NULL, (size_t)len);
|
||||
READ_INT(data->store, &len);
|
||||
data->store->api->r_bin(data->store->handle, NULL, (size_t)len);
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/resolve.h>
|
||||
|
||||
#include <storage.h>
|
||||
|
@ -95,63 +96,64 @@ dict_write(const attrib * a, const void *owner, struct storage *store)
|
|||
}
|
||||
}
|
||||
|
||||
static int dict_read(attrib * a, void *owner, struct storage *store)
|
||||
static int dict_read(attrib * a, void *owner, gamedata *data)
|
||||
{
|
||||
storage *store = data->store;
|
||||
char name[NAMESIZE];
|
||||
dict_data *data = (dict_data *)a->data.v;
|
||||
dict_data *dd = (dict_data *)a->data.v;
|
||||
int result, n;
|
||||
float flt;
|
||||
|
||||
READ_STR(store, name, sizeof(name));
|
||||
data->name = _strdup(name);
|
||||
dd->name = _strdup(name);
|
||||
READ_INT(store, &n);
|
||||
data->type = (dict_type)n;
|
||||
switch (data->type) {
|
||||
dd->type = (dict_type)n;
|
||||
switch (dd->type) {
|
||||
case TINTEGER:
|
||||
READ_INT(store, &data->data.i);
|
||||
READ_INT(store, &dd->data.i);
|
||||
break;
|
||||
case TREAL:
|
||||
READ_FLT(store, &flt);
|
||||
if ((int)flt == flt) {
|
||||
data->type = TINTEGER;
|
||||
data->data.i = (int)flt;
|
||||
dd->type = TINTEGER;
|
||||
dd->data.i = (int)flt;
|
||||
}
|
||||
else {
|
||||
data->data.real = flt;
|
||||
dd->data.real = flt;
|
||||
}
|
||||
break;
|
||||
case TSTRING:
|
||||
READ_STR(store, name, sizeof(name));
|
||||
data->data.str = _strdup(name);
|
||||
dd->data.str = _strdup(name);
|
||||
break;
|
||||
case TBUILDING:
|
||||
result =
|
||||
read_reference(&data->data.b, store, read_building_reference,
|
||||
read_reference(&dd->data.b, store, read_building_reference,
|
||||
resolve_building);
|
||||
if (result == 0 && !data->data.b) {
|
||||
if (result == 0 && !dd->data.b) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
break;
|
||||
case TUNIT:
|
||||
result =
|
||||
read_reference(&data->data.u, store, read_unit_reference, resolve_unit);
|
||||
if (result == 0 && !data->data.u) {
|
||||
read_reference(&dd->data.u, store, read_unit_reference, resolve_unit);
|
||||
if (result == 0 && !dd->data.u) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
break;
|
||||
case TFACTION:
|
||||
result =
|
||||
read_reference(&data->data.f, store, read_faction_reference,
|
||||
read_reference(&dd->data.f, store, read_faction_reference,
|
||||
resolve_faction);
|
||||
if (result == 0 && !data->data.f) {
|
||||
if (result == 0 && !dd->data.f) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
break;
|
||||
case TREGION:
|
||||
result =
|
||||
read_reference(&data->data.r, store, read_region_reference,
|
||||
read_reference(&dd->data.r, store, read_region_reference,
|
||||
RESOLVE_REGION(global.data_version));
|
||||
if (result == 0 && !data->data.r) {
|
||||
if (result == 0 && !dd->data.r) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -23,13 +23,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/unit.h>
|
||||
|
||||
#include <util/attrib.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/variant.h>
|
||||
|
||||
#include <storage.h>
|
||||
|
||||
static int read_follow(attrib * a, void *owner, struct storage *store)
|
||||
static int read_follow(attrib * a, void *owner, gamedata *data)
|
||||
{
|
||||
read_unit_reference(store); /* skip it */
|
||||
read_unit_reference(data->store); /* skip it */
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/version.h>
|
||||
|
||||
#include <util/attrib.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/resolve.h>
|
||||
|
||||
#include <storage.h>
|
||||
|
@ -43,10 +44,10 @@ write_hate(const attrib * a, const void *owner, struct storage *store)
|
|||
write_unit_reference((unit *)a->data.v, store);
|
||||
}
|
||||
|
||||
static int read_hate(attrib * a, void *owner, struct storage *store)
|
||||
static int read_hate(attrib * a, void *owner, gamedata *data)
|
||||
{
|
||||
int result =
|
||||
read_reference(&a->data.v, store, read_unit_reference, resolve_unit);
|
||||
read_reference(&a->data.v, data->store, read_unit_reference, resolve_unit);
|
||||
if (result == 0 && !a->data.v) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
#include <kernel/save.h>
|
||||
#include <util/attrib.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <storage.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -35,20 +36,20 @@ static void a_writekeys(const attrib *a, const void *o, storage *store) {
|
|||
}
|
||||
}
|
||||
|
||||
static int a_readkeys(attrib * a, void *owner, struct storage *store) {
|
||||
static int a_readkeys(attrib * a, void *owner, gamedata *data) {
|
||||
int i, *p = 0;
|
||||
READ_INT(store, &i);
|
||||
READ_INT(data->store, &i);
|
||||
assert(i < 4096 && i>0);
|
||||
a->data.v = p = malloc(sizeof(int)*(i + 1));
|
||||
*p++ = i;
|
||||
while (i--) {
|
||||
READ_INT(store, p++);
|
||||
READ_INT(data->store, p++);
|
||||
}
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
static int a_readkey(attrib *a, void *owner, struct storage *store) {
|
||||
int res = a_readint(a, owner, store);
|
||||
static int a_readkey(attrib *a, void *owner, struct gamedata *data) {
|
||||
int res = a_readint(a, owner, data);
|
||||
return (res != AT_READ_FAIL) ? AT_READ_DEPR : res;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include "moved.h"
|
||||
|
||||
#include <util/attrib.h>
|
||||
#include <util/gamedata.h>
|
||||
|
||||
#include <storage.h>
|
||||
|
||||
|
@ -37,9 +38,9 @@ write_moved(const attrib * a, const void *owner, struct storage *store)
|
|||
WRITE_INT(store, a->data.i);
|
||||
}
|
||||
|
||||
static int read_moved(attrib * a, void *owner, struct storage *store)
|
||||
static int read_moved(attrib * a, void *owner, gamedata *data)
|
||||
{
|
||||
READ_INT(store, &a->data.i);
|
||||
READ_INT(data->store, &a->data.i);
|
||||
if (a->data.i != 0)
|
||||
return AT_READ_OK;
|
||||
else
|
||||
|
|
|
@ -22,6 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
#include <kernel/save.h>
|
||||
#include <util/attrib.h>
|
||||
#include <util/gamedata.h>
|
||||
|
||||
#include <storage.h>
|
||||
|
||||
|
@ -34,9 +35,9 @@ write_movement(const attrib * a, const void *owner, struct storage *store)
|
|||
WRITE_INT(store, a->data.i);
|
||||
}
|
||||
|
||||
static int read_movement(attrib * a, void *owner, struct storage *store)
|
||||
static int read_movement(attrib * a, void *owner, gamedata *data)
|
||||
{
|
||||
READ_INT(store, &a->data.i);
|
||||
READ_INT(data->store, &a->data.i);
|
||||
if (a->data.i != 0)
|
||||
return AT_READ_OK;
|
||||
else
|
||||
|
|
|
@ -24,6 +24,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/faction.h>
|
||||
#include <kernel/unit.h>
|
||||
#include <util/attrib.h>
|
||||
#include <util/gamedata.h>
|
||||
|
||||
#include <storage.h>
|
||||
#include <assert.h>
|
||||
|
@ -38,11 +39,11 @@ void write_of(const struct attrib *a, const void *owner, struct storage *store)
|
|||
WRITE_INT(store, f->no);
|
||||
}
|
||||
|
||||
int read_of(struct attrib *a, void *owner, struct storage *store)
|
||||
int read_of(struct attrib *a, void *owner, gamedata *data)
|
||||
{ /* return 1 on success, 0 if attrib needs removal */
|
||||
int of;
|
||||
|
||||
READ_INT(store, &of);
|
||||
READ_INT(data->store, &of);
|
||||
if (rule_stealth_other()) {
|
||||
a->data.v = findfaction(of);
|
||||
if (a->data.v) {
|
||||
|
|
|
@ -25,6 +25,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/version.h>
|
||||
|
||||
#include <util/attrib.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/resolve.h>
|
||||
|
||||
#include <storage.h>
|
||||
|
@ -35,10 +36,10 @@ write_targetregion(const attrib * a, const void *owner, struct storage *store)
|
|||
write_region_reference((region *)a->data.v, store);
|
||||
}
|
||||
|
||||
static int read_targetregion(attrib * a, void *owner, struct storage *store)
|
||||
static int read_targetregion(attrib * a, void *owner, gamedata *data)
|
||||
{
|
||||
int result =
|
||||
read_reference(&a->data.v, store, read_region_reference,
|
||||
read_reference(&a->data.v, data->store, read_region_reference,
|
||||
RESOLVE_REGION(global.data_version));
|
||||
if (result == 0 && !a->data.v)
|
||||
return AT_READ_FAIL;
|
||||
|
|
|
@ -15,6 +15,7 @@ without prior permission by the authors of Eressea.
|
|||
#include <kernel/building.h>
|
||||
#include <kernel/version.h>
|
||||
#include <util/attrib.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/log.h>
|
||||
#include <util/resolve.h>
|
||||
|
||||
|
@ -98,10 +99,11 @@ lc_write(const struct attrib *a, const void *owner, struct storage *store)
|
|||
WRITE_TOK(store, fparam ? fparam : NULLSTRING);
|
||||
}
|
||||
|
||||
static int lc_read(struct attrib *a, void *owner, struct storage *store)
|
||||
static int lc_read(struct attrib *a, void *owner, gamedata *data)
|
||||
{
|
||||
struct storage *store = data->store;
|
||||
char name[NAMESIZE];
|
||||
building_action *data = (building_action *)a->data.v;
|
||||
building_action *bd = (building_action *)a->data.v;
|
||||
building *b = (building *)owner;
|
||||
int result = 0;
|
||||
if (global.data_version < ATTRIBOWNER_VERSION) {
|
||||
|
@ -115,7 +117,7 @@ static int lc_read(struct attrib *a, void *owner, struct storage *store)
|
|||
b = 0;
|
||||
}
|
||||
else {
|
||||
data->fname = _strdup(name);
|
||||
bd->fname = _strdup(name);
|
||||
}
|
||||
READ_TOK(store, name, sizeof(name));
|
||||
if (strcmp(name, "tnnL") == 0) {
|
||||
|
@ -124,9 +126,9 @@ static int lc_read(struct attrib *a, void *owner, struct storage *store)
|
|||
b = 0;
|
||||
}
|
||||
if (strcmp(name, NULLSTRING) == 0)
|
||||
data->param = 0;
|
||||
bd->param = 0;
|
||||
else {
|
||||
data->param = _strdup(name);
|
||||
bd->param = _strdup(name);
|
||||
}
|
||||
if (result == 0 && !b) {
|
||||
return AT_READ_FAIL;
|
||||
|
|
|
@ -28,6 +28,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
#include <util/attrib.h>
|
||||
#include <util/bsdstring.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <quicklist.h>
|
||||
|
@ -601,8 +602,9 @@ void write_borders(struct storage *store)
|
|||
WRITE_TOK(store, "end");
|
||||
}
|
||||
|
||||
int read_borders(struct storage *store)
|
||||
int read_borders(gamedata *data)
|
||||
{
|
||||
struct storage *store = data->store;
|
||||
for (;;) {
|
||||
int bid = 0;
|
||||
char zText[32];
|
||||
|
@ -613,7 +615,7 @@ int read_borders(struct storage *store)
|
|||
if (!strcmp(zText, "end"))
|
||||
break;
|
||||
READ_INT(store, &bid);
|
||||
if (global.data_version < UIDHASH_VERSION) {
|
||||
if (data->version < UIDHASH_VERSION) {
|
||||
int fx, fy, tx, ty;
|
||||
READ_INT(store, &fx);
|
||||
READ_INT(store, &fy);
|
||||
|
@ -659,7 +661,7 @@ int read_borders(struct storage *store)
|
|||
type->read(b, store);
|
||||
if (global.data_version < NOBORDERATTRIBS_VERSION) {
|
||||
attrib *a = NULL;
|
||||
int result = read_attribs(store, &a, b);
|
||||
int result = read_attribs(data, &a, b);
|
||||
if (border_convert_cb) {
|
||||
border_convert_cb(b, a);
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ extern "C" {
|
|||
struct faction;
|
||||
struct region;
|
||||
struct storage;
|
||||
struct gamedata;
|
||||
struct unit;
|
||||
|
||||
extern int nextborder;
|
||||
|
@ -113,7 +114,7 @@ extern "C" {
|
|||
void register_bordertype(border_type * type);
|
||||
/* register a new bordertype */
|
||||
|
||||
int read_borders(struct storage *store);
|
||||
int read_borders(struct gamedata *store);
|
||||
void write_borders(struct storage *store);
|
||||
void age_borders(void);
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
|
@ -184,8 +185,9 @@ static int read_ccompat(const char *cursename, struct storage *store)
|
|||
return -1;
|
||||
}
|
||||
|
||||
int curse_read(attrib * a, void *owner, struct storage *store)
|
||||
int curse_read(attrib * a, void *owner, gamedata *data)
|
||||
{
|
||||
storage *store = data->store;
|
||||
curse *c = (curse *)a->data.v;
|
||||
int ur;
|
||||
char cursename[64];
|
||||
|
@ -200,13 +202,13 @@ int curse_read(attrib * a, void *owner, struct storage *store)
|
|||
READ_INT(store, &c->duration);
|
||||
READ_FLT(store, &flt);
|
||||
c->vigour = flt;
|
||||
if (global.data_version < INTPAK_VERSION) {
|
||||
if (data->version < INTPAK_VERSION) {
|
||||
ur = read_reference(&c->magician, store, read_int, resolve_unit);
|
||||
}
|
||||
else {
|
||||
ur = read_reference(&c->magician, store, read_unit_reference, resolve_unit);
|
||||
}
|
||||
if (global.data_version < CURSEFLOAT_VERSION) {
|
||||
if (data->version < CURSEFLOAT_VERSION) {
|
||||
READ_INT(store, &n);
|
||||
c->effect = (float)n;
|
||||
}
|
||||
|
@ -224,7 +226,7 @@ int curse_read(attrib * a, void *owner, struct storage *store)
|
|||
return AT_READ_FAIL;
|
||||
}
|
||||
c->flags = flags;
|
||||
if (global.data_version < EXPLICIT_CURSE_ISNEW_VERSION) {
|
||||
if (data->version < EXPLICIT_CURSE_ISNEW_VERSION) {
|
||||
c_clearflag(c, CURSE_ISNEW);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@ extern "C" {
|
|||
|
||||
struct curse;
|
||||
struct curse_type;
|
||||
struct gamedata;
|
||||
struct storage;
|
||||
|
||||
/* Sprueche in der struct region und auf Einheiten, Schiffen oder Burgen
|
||||
* (struct attribute)
|
||||
|
@ -93,7 +95,7 @@ extern "C" {
|
|||
*
|
||||
* */
|
||||
|
||||
#include <util/variant.h>
|
||||
extern struct attrib_type at_curse;
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
/* Zauberwirkungen */
|
||||
|
@ -216,10 +218,9 @@ extern "C" {
|
|||
|
||||
void free_curses(void); /* de-register all curse-types */
|
||||
|
||||
extern struct attrib_type at_curse;
|
||||
void curse_write(const struct attrib *a, const void *owner,
|
||||
struct storage *store);
|
||||
int curse_read(struct attrib *a, void *owner, struct storage *store);
|
||||
struct storage *store);
|
||||
int curse_read(struct attrib *a, void *owner, struct gamedata *store);
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
/* Kommentare:
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <kernel/unit.h>
|
||||
#include <kernel/version.h>
|
||||
#include <util/attrib.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/message.h>
|
||||
#include <binarystore.h>
|
||||
#include <filestream.h>
|
||||
|
@ -122,29 +123,23 @@ static void test_memstream(CuTest *tc) {
|
|||
|
||||
static void test_write_flag(CuTest *tc) {
|
||||
curse_fixture fix;
|
||||
gamedata data;
|
||||
storage store;
|
||||
char buf[1024];
|
||||
stream out = { 0 };
|
||||
size_t len;
|
||||
|
||||
mstream_init(&out);
|
||||
binstore_init(&store, &out);
|
||||
store.handle.data = &out;
|
||||
mstream_init(&data.strm);
|
||||
gamedata_init(&data, &store, RELEASE_VERSION);
|
||||
|
||||
setup_curse(&fix, "gbdream");
|
||||
fix.c->flags = 42 | CURSE_ISNEW;
|
||||
curse_write(fix.r->attribs, fix.r, &store);
|
||||
out.api->rewind(out.handle);
|
||||
len = out.api->read(out.handle, buf, sizeof(buf));
|
||||
buf[len] = '\0';
|
||||
out.api->rewind(out.handle);
|
||||
curse_read(fix.r->attribs, fix.r, &store);
|
||||
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;
|
||||
CuAssertIntEquals(tc, RELEASE_VERSION, global.data_version);
|
||||
|
||||
mstream_done(&out);
|
||||
binstore_done(&store);
|
||||
mstream_done(&data.strm);
|
||||
gamedata_done(&data);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/resolve.h>
|
||||
#include <util/unicode.h>
|
||||
|
||||
|
@ -95,8 +96,9 @@ static group *find_group(int gid)
|
|||
return g;
|
||||
}
|
||||
|
||||
static int read_group(attrib * a, void *owner, struct storage *store)
|
||||
static int read_group(attrib * a, void *owner, gamedata *data)
|
||||
{
|
||||
struct storage *store = data->store;
|
||||
group *g;
|
||||
int gid;
|
||||
|
||||
|
@ -215,8 +217,9 @@ void write_groups(struct storage *store, const faction * f)
|
|||
WRITE_INT(store, 0);
|
||||
}
|
||||
|
||||
void read_groups(struct storage *store, faction * f)
|
||||
void read_groups(gamedata *data, faction * f)
|
||||
{
|
||||
struct storage *store = data->store;
|
||||
for (;;) {
|
||||
ally **pa;
|
||||
group *g;
|
||||
|
@ -241,6 +244,6 @@ void read_groups(struct storage *store, faction * f)
|
|||
if (!a->faction)
|
||||
ur_add(fid, &a->faction, resolve_faction);
|
||||
}
|
||||
read_attribs(store, &g->attribs, g);
|
||||
read_attribs(data, &g->attribs, g);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ extern "C" {
|
|||
struct group *new_group(struct faction * f, const char *name, int gid);
|
||||
|
||||
extern void write_groups(struct storage *data, const struct faction *f);
|
||||
extern void read_groups(struct storage *data, struct faction *f);
|
||||
extern void read_groups(struct gamedata *data, struct faction *f);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -5,8 +5,13 @@
|
|||
#include "faction.h"
|
||||
#include "unit.h"
|
||||
#include "region.h"
|
||||
#include "save.h"
|
||||
#include "version.h"
|
||||
|
||||
#include <util/gamedata.h>
|
||||
#include <util/attrib.h>
|
||||
#include <attributes/key.h>
|
||||
|
||||
#include <stream.h>
|
||||
#include <filestream.h>
|
||||
#include <storage.h>
|
||||
|
@ -21,35 +26,29 @@ static void test_group_readwrite(CuTest * tc)
|
|||
faction * f;
|
||||
group *g;
|
||||
ally *al;
|
||||
storage store;
|
||||
FILE *F;
|
||||
stream strm;
|
||||
int i;
|
||||
gamedata *data;
|
||||
|
||||
F = fopen("test.dat", "wb");
|
||||
fstream_init(&strm, F);
|
||||
binstore_init(&store, &strm);
|
||||
test_cleanup();
|
||||
test_create_world();
|
||||
data = gamedata_open("test.dat", "wb", RELEASE_VERSION);
|
||||
f = test_create_faction(0);
|
||||
g = new_group(f, "NW", 42);
|
||||
g = new_group(f, "Egoisten", 43);
|
||||
key_set(&g->attribs, 44);
|
||||
al = ally_add(&g->allies, f);
|
||||
al->status = HELP_GIVE;
|
||||
write_groups(&store, f);
|
||||
WRITE_INT(&store, 47);
|
||||
binstore_done(&store);
|
||||
fstream_done(&strm);
|
||||
write_groups(data->store, f);
|
||||
WRITE_INT(data->store, 47);
|
||||
binstore_done(data->store);
|
||||
gamedata_close(data);
|
||||
|
||||
F = fopen("test.dat", "rb");
|
||||
fstream_init(&strm, F);
|
||||
binstore_init(&store, &strm);
|
||||
f->groups = 0;
|
||||
read_groups(&store, f);
|
||||
READ_INT(&store, &i);
|
||||
binstore_done(&store);
|
||||
fstream_done(&strm);
|
||||
free_group(g);
|
||||
data = gamedata_open("test.dat", "rb", RELEASE_VERSION);
|
||||
read_groups(data, f);
|
||||
READ_INT(data->store, &i);
|
||||
gamedata_close(data);
|
||||
|
||||
CuAssertIntEquals(tc, 47, i);
|
||||
CuAssertPtrNotNull(tc, f->groups);
|
||||
|
|
|
@ -42,6 +42,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/bsdstring.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
|
@ -176,12 +177,12 @@ void a_initmoveblock(attrib * a)
|
|||
a->data.v = calloc(1, sizeof(moveblock));
|
||||
}
|
||||
|
||||
int a_readmoveblock(attrib * a, void *owner, struct storage *store)
|
||||
int a_readmoveblock(attrib * a, void *owner, gamedata *data)
|
||||
{
|
||||
moveblock *m = (moveblock *)(a->data.v);
|
||||
int i;
|
||||
|
||||
READ_INT(store, &i);
|
||||
READ_INT(data->store, &i);
|
||||
m->dir = (direction_t)i;
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/bsdstring.h>
|
||||
#include <util/event.h>
|
||||
#include <util/filereader.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/language.h>
|
||||
|
@ -582,12 +583,12 @@ writeorder(struct gamedata *data, const struct order *ord,
|
|||
WRITE_STR(data->store, obuf);
|
||||
}
|
||||
|
||||
int read_attribs(storage *store, attrib **alist, void *owner) {
|
||||
if (global.data_version < ATHASH_VERSION) {
|
||||
return a_read_orig(store, alist, owner);
|
||||
int read_attribs(gamedata *data, attrib **alist, void *owner) {
|
||||
if (data->version < ATHASH_VERSION) {
|
||||
return a_read_orig(data, alist, owner);
|
||||
}
|
||||
else {
|
||||
return a_read(store, alist, owner);
|
||||
return a_read(data, alist, owner);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -771,7 +772,7 @@ unit *read_unit(struct gamedata *data)
|
|||
log_error("Einheit %s hat %u Personen, und %u Trefferpunkte\n", itoa36(u->no), u->number, u->hp);
|
||||
u->hp = u->number;
|
||||
}
|
||||
read_attribs(data->store, &u->attribs, u);
|
||||
read_attribs(data, &u->attribs, u);
|
||||
return u;
|
||||
}
|
||||
|
||||
|
@ -1005,7 +1006,7 @@ static region *readregion(struct gamedata *data, int x, int y)
|
|||
read_owner(data, &r->land->ownership);
|
||||
}
|
||||
}
|
||||
read_attribs(data->store, &r->attribs, r);
|
||||
read_attribs(data, &r->attribs, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -1327,7 +1328,7 @@ faction *readfaction(struct gamedata * data)
|
|||
}
|
||||
}
|
||||
|
||||
read_attribs(data->store, &f->attribs, f);
|
||||
read_attribs(data, &f->attribs, f);
|
||||
read_items(data->store, &f->items);
|
||||
for (;;) {
|
||||
READ_TOK(data->store, name, sizeof(name));
|
||||
|
@ -1370,7 +1371,7 @@ faction *readfaction(struct gamedata * data)
|
|||
break;
|
||||
}
|
||||
}
|
||||
read_groups(data->store, f);
|
||||
read_groups(data, f);
|
||||
f->spellbook = 0;
|
||||
if (data->version >= REGIONOWNER_VERSION) {
|
||||
read_spellbook(FactionSpells() ? &f->spellbook : 0, data->store, get_spell_level_faction, (void *)f);
|
||||
|
@ -1501,7 +1502,7 @@ int readgame(const char *filename, bool backup)
|
|||
fstream_init(&strm, F);
|
||||
binstore_init(&store, &strm);
|
||||
gdata.store = &store;
|
||||
global.data_version = gdata.version; /* HACK: attribute::read does not have access to gamedata, only storage */
|
||||
global.data_version = gdata.version; /* FIXME: hack! attribute::read does not have access to gamedata, only storage */
|
||||
|
||||
if (gdata.version >= BUILDNO_VERSION) {
|
||||
int build;
|
||||
|
@ -1526,7 +1527,7 @@ int readgame(const char *filename, bool backup)
|
|||
else {
|
||||
READ_STR(&store, NULL, 0);
|
||||
}
|
||||
read_attribs(&store, &global.attribs, NULL);
|
||||
read_attribs(&gdata, &global.attribs, NULL);
|
||||
READ_INT(&store, &turn);
|
||||
global.data_turn = turn;
|
||||
log_debug(" - reading turn %d\n", turn);
|
||||
|
@ -1584,7 +1585,7 @@ int readgame(const char *filename, bool backup)
|
|||
}
|
||||
}
|
||||
}
|
||||
read_attribs(&store, &pl->attribs, pl);
|
||||
read_attribs(&gdata, &pl->attribs, pl);
|
||||
if (pl->id != 1094969858) { // Regatta
|
||||
addlist(&planes, pl);
|
||||
}
|
||||
|
@ -1652,7 +1653,7 @@ int readgame(const char *filename, bool backup)
|
|||
READ_STR(&store, name, sizeof(name));
|
||||
b->type = bt_find(name);
|
||||
b->region = r;
|
||||
read_attribs(&store, &b->attribs, b);
|
||||
read_attribs(&gdata, &b->attribs, b);
|
||||
if (b->type == bt_lighthouse) {
|
||||
r->flags |= RF_LIGHTHOUSE;
|
||||
}
|
||||
|
@ -1699,7 +1700,7 @@ int readgame(const char *filename, bool backup)
|
|||
if (sh->type->flags & SFL_NOCOAST) {
|
||||
sh->coast = NODIRECTION;
|
||||
}
|
||||
read_attribs(&store, &sh->attribs, sh);
|
||||
read_attribs(&gdata, &sh->attribs, sh);
|
||||
}
|
||||
|
||||
*shp = 0;
|
||||
|
@ -1727,7 +1728,7 @@ int readgame(const char *filename, bool backup)
|
|||
update_interval(u->faction, u->region);
|
||||
}
|
||||
}
|
||||
read_borders(&store);
|
||||
read_borders(&gdata);
|
||||
|
||||
binstore_done(&store);
|
||||
fstream_done(&strm);
|
||||
|
@ -1955,10 +1956,10 @@ int writegame(const char *filename)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int a_readint(attrib * a, void *owner, struct storage *store)
|
||||
int a_readint(attrib * a, void *owner, struct gamedata *data)
|
||||
{
|
||||
/* assert(sizeof(int)==sizeof(a->data)); */
|
||||
READ_INT(store, &a->data.i);
|
||||
READ_INT(data->store, &a->data.i);
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
|
@ -1967,12 +1968,12 @@ void a_writeint(const attrib * a, const void *owner, struct storage *store)
|
|||
WRITE_INT(store, a->data.i);
|
||||
}
|
||||
|
||||
int a_readshorts(attrib * a, void *owner, struct storage *store)
|
||||
int a_readshorts(attrib * a, void *owner, struct gamedata *data)
|
||||
{
|
||||
int n;
|
||||
READ_INT(store, &n);
|
||||
READ_INT(data->store, &n);
|
||||
a->data.sa[0] = (short)n;
|
||||
READ_INT(store, &n);
|
||||
READ_INT(data->store, &n);
|
||||
a->data.sa[1] = (short)n;
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
@ -1983,12 +1984,12 @@ void a_writeshorts(const attrib * a, const void *owner, struct storage *store)
|
|||
WRITE_INT(store, a->data.sa[1]);
|
||||
}
|
||||
|
||||
int a_readchars(attrib * a, void *owner, struct storage *store)
|
||||
int a_readchars(attrib * a, void *owner, struct gamedata *data)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i != 4; ++i) {
|
||||
int n;
|
||||
READ_INT(store, &n);
|
||||
READ_INT(data->store, &n);
|
||||
a->data.ca[i] = (char)n;
|
||||
}
|
||||
return AT_READ_OK;
|
||||
|
@ -2003,7 +2004,7 @@ void a_writechars(const attrib * a, const void *owner, struct storage *store)
|
|||
}
|
||||
}
|
||||
|
||||
int a_readvoid(attrib * a, void *owner, struct storage *store)
|
||||
int a_readvoid(attrib * a, void *owner, struct gamedata *data)
|
||||
{
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
@ -2012,14 +2013,14 @@ void a_writevoid(const attrib * a, const void *owner, struct storage *store)
|
|||
{
|
||||
}
|
||||
|
||||
int a_readstring(attrib * a, void *owner, struct storage *store)
|
||||
int a_readstring(attrib * a, void *owner, struct gamedata *data)
|
||||
{
|
||||
char buf[DISPLAYSIZE];
|
||||
char * result = 0;
|
||||
int e;
|
||||
size_t len = 0;
|
||||
do {
|
||||
e = READ_STR(store, buf, sizeof(buf));
|
||||
e = READ_STR(data->store, buf, sizeof(buf));
|
||||
if (result) {
|
||||
result = realloc(result, len + DISPLAYSIZE - 1);
|
||||
strcpy(result + len, buf);
|
||||
|
|
|
@ -31,6 +31,7 @@ extern "C" {
|
|||
struct spell;
|
||||
struct spellbook;
|
||||
struct unit;
|
||||
struct gamedata;
|
||||
|
||||
#define MAX_INPUT_SIZE DISPLAYSIZE*2
|
||||
/* Nach MAX_INPUT_SIZE brechen wir das Einlesen der Zeile ab und nehmen an,
|
||||
|
@ -53,26 +54,26 @@ extern "C" {
|
|||
void write_spellbook(const struct spellbook *book, struct storage *store);
|
||||
|
||||
void write_attribs(struct storage *store, struct attrib *alist, const void *owner);
|
||||
int read_attribs(struct storage *store, struct attrib **alist, void *owner);
|
||||
int read_attribs(struct gamedata *store, struct attrib **alist, void *owner);
|
||||
|
||||
void write_unit(struct gamedata *data, const struct unit *u);
|
||||
struct unit *read_unit(struct gamedata *data);
|
||||
|
||||
int a_readint(struct attrib *a, void *owner, struct storage *store);
|
||||
int a_readint(struct attrib *a, void *owner, struct gamedata *);
|
||||
void a_writeint(const struct attrib *a, const void *owner,
|
||||
struct storage *store);
|
||||
int a_readshorts(struct attrib *a, void *owner, struct storage *store);
|
||||
int a_readshorts(struct attrib *a, void *owner, struct gamedata *);
|
||||
void a_writeshorts(const struct attrib *a, const void *owner,
|
||||
struct storage *store);
|
||||
int a_readchars(struct attrib *a, void *owner, struct storage *store);
|
||||
int a_readchars(struct attrib *a, void *owner, struct gamedata *);
|
||||
void a_writechars(const struct attrib *a, const void *owner,
|
||||
struct storage *store);
|
||||
int a_readvoid(struct attrib *a, void *owner, struct storage *store);
|
||||
int a_readvoid(struct attrib *a, void *owner, struct gamedata *);
|
||||
void a_writevoid(const struct attrib *a, const void *owner,
|
||||
struct storage *store);
|
||||
int a_readstring(struct attrib *a, void *owner, struct storage *store);
|
||||
struct storage *);
|
||||
int a_readstring(struct attrib *a, void *owner, struct gamedata *);
|
||||
void a_writestring(const struct attrib *a, const void *owner,
|
||||
struct storage *store);
|
||||
struct storage *);
|
||||
void a_finalizestring(struct attrib *a);
|
||||
|
||||
void create_backup(char *file);
|
||||
|
|
|
@ -68,6 +68,7 @@ static void test_readwrite_unit(CuTest * tc)
|
|||
renumber_faction(f, fno);
|
||||
gamedata_init(&data, &store, RELEASE_VERSION);
|
||||
u = read_unit(&data);
|
||||
mstream_done(&data.strm);
|
||||
gamedata_done(&data);
|
||||
|
||||
CuAssertPtrNotNull(tc, u);
|
||||
|
@ -92,9 +93,9 @@ static void test_readwrite_attrib(CuTest *tc) {
|
|||
CuAssertPtrEquals(tc, 0, a);
|
||||
|
||||
data.strm.api->rewind(data.strm.handle);
|
||||
read_attribs(data.store, &a, NULL);
|
||||
gamedata_done(&data);
|
||||
read_attribs(&data, &a, NULL);
|
||||
mstream_done(&data.strm);
|
||||
gamedata_done(&data);
|
||||
CuAssertTrue(tc, key_get(a, 41));
|
||||
CuAssertTrue(tc, key_get(a, 42));
|
||||
a_removeall(&a, NULL);
|
||||
|
|
|
@ -52,6 +52,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/base36.h>
|
||||
#include <util/bsdstring.h>
|
||||
#include <util/event.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
|
@ -443,8 +444,9 @@ int ualias(const unit * u)
|
|||
return a->data.i;
|
||||
}
|
||||
|
||||
int a_readprivate(attrib * a, void *owner, struct storage *store)
|
||||
int a_readprivate(attrib * a, void *owner, gamedata *data)
|
||||
{
|
||||
struct storage *store = data->store;
|
||||
char lbuf[DISPLAYSIZE];
|
||||
READ_STR(store, lbuf, sizeof(lbuf));
|
||||
a->data.v = _strdup(lbuf);
|
||||
|
@ -579,8 +581,9 @@ void a_writesiege(const attrib * a, const void *owner, struct storage *store)
|
|||
write_building_reference(b, store);
|
||||
}
|
||||
|
||||
int a_readsiege(attrib * a, 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,
|
||||
resolve_building);
|
||||
if (result == 0 && !a->data.v) {
|
||||
|
|
|
@ -40,5 +40,3 @@
|
|||
#define RELEASE_VERSION ATHASH_VERSION /* current datafile */
|
||||
#define MIN_VERSION INTPAK_VERSION /* minimal datafile we support */
|
||||
#define MAX_VERSION RELEASE_VERSION /* change this if we can need to read the future datafile, and we can do so */
|
||||
|
||||
#define STREAM_VERSION 2 /* internal encoding of binary files */
|
||||
|
|
27
src/magic.c
27
src/magic.c
|
@ -54,7 +54,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <critbit.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
|
@ -67,6 +67,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/base36.h>
|
||||
#include <util/event.h>
|
||||
|
||||
#include <critbit.h>
|
||||
#include <storage.h>
|
||||
|
||||
/* libc includes */
|
||||
|
@ -128,16 +129,17 @@ typedef struct icastle_data {
|
|||
int time;
|
||||
} icastle_data;
|
||||
|
||||
static int a_readicastle(attrib * a, void *owner, struct storage *store)
|
||||
static int a_readicastle(attrib * a, void *owner, struct gamedata *data)
|
||||
{
|
||||
icastle_data *data = (icastle_data *)a->data.v;
|
||||
storage *store = data->store;
|
||||
icastle_data *idata = (icastle_data *)a->data.v;
|
||||
char token[32];
|
||||
READ_TOK(store, token, sizeof(token));
|
||||
if (global.data_version < ATTRIBOWNER_VERSION) {
|
||||
READ_INT(store, NULL);
|
||||
}
|
||||
READ_INT(store, &data->time);
|
||||
data->type = bt_find(token);
|
||||
READ_INT(store, &idata->time);
|
||||
idata->type = bt_find(token);
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
|
@ -254,8 +256,9 @@ int get_spell_level_mage(const spell * sp, void * cbdata)
|
|||
return sbe ? sbe->level : 0;
|
||||
}
|
||||
|
||||
static int read_mage(attrib * a, void *owner, struct storage *store)
|
||||
static int read_mage(attrib * a, void *owner, struct gamedata *data)
|
||||
{
|
||||
storage *store = data->store;
|
||||
int i, mtype;
|
||||
sc_mage *mage = (sc_mage *)a->data.v;
|
||||
char spname[64];
|
||||
|
@ -362,8 +365,9 @@ sc_mage *get_mage(const unit * u)
|
|||
* Spruch zu seiner List-of-known-spells hinzugefügt werden.
|
||||
*/
|
||||
|
||||
static int read_seenspell(attrib * a, void *owner, struct storage *store)
|
||||
static int read_seenspell(attrib * a, void *owner, struct gamedata *data)
|
||||
{
|
||||
storage *store = data->store;
|
||||
int i;
|
||||
spell *sp = 0;
|
||||
char token[32];
|
||||
|
@ -2281,8 +2285,9 @@ static int resolve_familiar(variant data, void *addr)
|
|||
return result;
|
||||
}
|
||||
|
||||
static int read_familiar(attrib * a, void *owner, struct storage *store)
|
||||
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);
|
||||
if (result == 0 && a->data.v == NULL) {
|
||||
|
@ -2365,8 +2370,9 @@ static int resolve_clone(variant data, void *addr)
|
|||
return result;
|
||||
}
|
||||
|
||||
static int read_clone(attrib * a, void *owner, struct storage *store)
|
||||
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);
|
||||
if (result == 0 && a->data.v == NULL) {
|
||||
|
@ -2392,8 +2398,9 @@ static int resolve_mage(variant data, void *addr)
|
|||
return result;
|
||||
}
|
||||
|
||||
static int read_magician(attrib * a, void *owner, struct storage *store)
|
||||
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);
|
||||
if (result == 0 && a->data.v == NULL) {
|
||||
|
|
|
@ -48,6 +48,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/event.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/functions.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/lists.h>
|
||||
|
@ -248,10 +249,10 @@ write_hurting(const attrib * a, const void *owner, struct storage *store)
|
|||
WRITE_INT(store, b->no);
|
||||
}
|
||||
|
||||
static int read_hurting(attrib * a, void *owner, struct storage *store)
|
||||
static int read_hurting(attrib * a, void *owner, struct gamedata *data)
|
||||
{
|
||||
int i;
|
||||
READ_INT(store, &i);
|
||||
READ_INT(data->store, &i);
|
||||
a->data.v = (void *)findbuilding(i);
|
||||
if (a->data.v == NULL) {
|
||||
log_error("temple of pain is broken\n");
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
|
||||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/gamedata.h>
|
||||
|
||||
#include <storage.h>
|
||||
|
||||
/* libc includes */
|
||||
|
@ -43,18 +45,18 @@
|
|||
#include <limits.h>
|
||||
#include <assert.h>
|
||||
|
||||
static int read_permissions(attrib * a, void *owner, struct storage *store)
|
||||
static int read_permissions(attrib * a, void *owner, struct gamedata *data)
|
||||
{
|
||||
assert(!a);
|
||||
a_read(store, &a, owner);
|
||||
a_read(data, &a, owner);
|
||||
a_remove(&a, a);
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
static int read_gmcreate(attrib * a, void *owner, struct storage *store)
|
||||
static int read_gmcreate(attrib * a, void *owner, struct gamedata *data)
|
||||
{
|
||||
char zText[32];
|
||||
READ_TOK(store, zText, sizeof(zText));
|
||||
READ_TOK(data->store, zText, sizeof(zText));
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/functions.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/language.h>
|
||||
|
||||
|
@ -79,11 +80,11 @@ struct storage *store)
|
|||
}
|
||||
|
||||
static int
|
||||
a_readmuseumgivebackcookie(attrib * a, void *owner, struct storage *store)
|
||||
a_readmuseumgivebackcookie(attrib * a, void *owner, gamedata *data)
|
||||
{
|
||||
museumgivebackcookie *gbc = (museumgivebackcookie *)a->data.v;
|
||||
READ_INT(store, &gbc->warden_no);
|
||||
READ_INT(store, &gbc->cookie);
|
||||
READ_INT(data->store, &gbc->warden_no);
|
||||
READ_INT(data->store, &gbc->cookie);
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
|
@ -121,11 +122,11 @@ struct storage *store)
|
|||
write_items(store, gb->items);
|
||||
}
|
||||
|
||||
static int a_readmuseumgiveback(attrib * a, void *owner, struct storage *store)
|
||||
static int a_readmuseumgiveback(attrib * a, void *owner, struct gamedata *data)
|
||||
{
|
||||
museumgiveback *gb = (museumgiveback *)a->data.v;
|
||||
READ_INT(store, &gb->cookie);
|
||||
read_items(store, &gb->items);
|
||||
READ_INT(data->store, &gb->cookie);
|
||||
read_items(data->store, &gb->items);
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/bsdstring.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
|
@ -154,8 +155,9 @@ static int shiptrail_age(attrib * a, void *owner)
|
|||
return (t->age > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
||||
}
|
||||
|
||||
static int shiptrail_read(attrib * a, void *owner, struct storage *store)
|
||||
static int shiptrail_read(attrib * a, void *owner, struct gamedata *data)
|
||||
{
|
||||
storage *store = data->store;
|
||||
int n;
|
||||
traveldir *t = (traveldir *)(a->data.v);
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/event.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/language.h>
|
||||
#include <util/message.h>
|
||||
#include <util/parser.h>
|
||||
|
@ -2866,9 +2867,10 @@ static curse *mk_deathcloud(unit * mage, region * r, double force, int duration)
|
|||
|
||||
#define COMPAT_DEATHCLOUD
|
||||
#ifdef COMPAT_DEATHCLOUD
|
||||
static int dc_read_compat(struct attrib *a, void *target, struct storage * store)
|
||||
static int dc_read_compat(struct attrib *a, void *target, gamedata *data)
|
||||
/* return AT_READ_OK on success, AT_READ_FAIL if attrib needs removal */
|
||||
{
|
||||
struct storage *store = data->store;
|
||||
region *r = NULL;
|
||||
unit *u;
|
||||
variant var;
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/event.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/resolve.h>
|
||||
#include <util/umlaut.h>
|
||||
|
||||
|
@ -76,8 +77,9 @@ alp_write(const attrib * a, const void *owner, struct storage *store)
|
|||
write_unit_reference(ad->target, store);
|
||||
}
|
||||
|
||||
static int alp_read(attrib * a, 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 rt =
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <kernel/version.h>
|
||||
|
||||
#include <util/attrib.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/language.h>
|
||||
#include <util/rand.h>
|
||||
#include <util/rng.h>
|
||||
|
@ -51,8 +52,9 @@ typedef struct bresolve {
|
|||
|
||||
static int resolve_buddy(variant data, void *addr);
|
||||
|
||||
static int cw_read(attrib * a, void *target, storage * store)
|
||||
static int cw_read(attrib * a, void *target, gamedata *data)
|
||||
{
|
||||
storage *store = data->store;
|
||||
bresolve *br = calloc(sizeof(bresolve), 1);
|
||||
curse *c = (curse *)a->data.v;
|
||||
wallcurse *wc = (wallcurse *)c->data.v;
|
||||
|
|
|
@ -23,6 +23,7 @@ dice.c
|
|||
event.c
|
||||
filereader.c
|
||||
functions.c
|
||||
gamedata.c
|
||||
goodies.c
|
||||
gamedata.c
|
||||
language.c
|
||||
|
|
|
@ -22,6 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include "log.h"
|
||||
#include "storage.h"
|
||||
|
||||
#include <util/gamedata.h>
|
||||
#include <critbit.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
@ -279,10 +280,10 @@ static critbit_tree cb_deprecated = { 0 };
|
|||
|
||||
typedef struct deprecated_s {
|
||||
unsigned int hash;
|
||||
int(*reader)(attrib *, void *, struct storage *);
|
||||
int(*reader)(attrib *, void *, struct gamedata *);
|
||||
} deprecated_t;
|
||||
|
||||
void at_deprecate(const char * name, int(*reader)(attrib *, void *, struct storage *))
|
||||
void at_deprecate(const char * name, int(*reader)(attrib *, void *, struct gamedata *))
|
||||
{
|
||||
deprecated_t value;
|
||||
|
||||
|
@ -291,9 +292,9 @@ void at_deprecate(const char * name, int(*reader)(attrib *, void *, struct stora
|
|||
cb_insert(&cb_deprecated, &value, sizeof(value));
|
||||
}
|
||||
|
||||
static int a_read_i(struct storage *store, attrib ** attribs, void *owner, unsigned int key) {
|
||||
static int a_read_i(gamedata *data, attrib ** attribs, void *owner, unsigned int key) {
|
||||
int retval = AT_READ_OK;
|
||||
int(*reader)(attrib *, void *, struct storage *) = 0;
|
||||
int(*reader)(attrib *, void *, struct gamedata *) = 0;
|
||||
attrib_type *at = at_find(key);
|
||||
attrib * na = 0;
|
||||
|
||||
|
@ -313,7 +314,7 @@ static int a_read_i(struct storage *store, attrib ** attribs, void *owner, unsig
|
|||
}
|
||||
}
|
||||
if (reader) {
|
||||
int ret = reader(na, owner, store);
|
||||
int ret = reader(na, owner, data);
|
||||
if (na) {
|
||||
switch (ret) {
|
||||
case AT_READ_DEPR:
|
||||
|
@ -336,13 +337,14 @@ static int a_read_i(struct storage *store, attrib ** attribs, void *owner, unsig
|
|||
return retval;
|
||||
}
|
||||
|
||||
int a_read(struct storage *store, attrib ** attribs, void *owner) {
|
||||
int a_read(gamedata *data, attrib ** attribs, void *owner) {
|
||||
struct storage *store = data->store;
|
||||
int key, retval = AT_READ_OK;
|
||||
|
||||
key = -1;
|
||||
READ_INT(store, &key);
|
||||
while (key > 0) {
|
||||
int ret = a_read_i(store, attribs, owner, key);
|
||||
int ret = a_read_i(data, attribs, owner, key);
|
||||
if (ret == AT_READ_DEPR) {
|
||||
retval = AT_READ_DEPR;
|
||||
}
|
||||
|
@ -361,14 +363,14 @@ int a_read(struct storage *store, attrib ** attribs, void *owner) {
|
|||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
int a_read_orig(struct storage *store, attrib ** attribs, void *owner)
|
||||
int a_read_orig(gamedata *data, attrib ** attribs, void *owner)
|
||||
{
|
||||
int key, retval = AT_READ_OK;
|
||||
char zText[128];
|
||||
|
||||
zText[0] = 0;
|
||||
key = -1;
|
||||
READ_TOK(store, zText, sizeof(zText));
|
||||
READ_TOK(data->store, zText, sizeof(zText));
|
||||
if (strcmp(zText, "end") == 0) {
|
||||
return retval;
|
||||
}
|
||||
|
@ -376,8 +378,8 @@ int a_read_orig(struct storage *store, attrib ** attribs, void *owner)
|
|||
key = __at_hashkey(zText);
|
||||
}
|
||||
while (key > 0) {
|
||||
retval = a_read_i(store, attribs, owner, key);
|
||||
READ_TOK(store, zText, sizeof(zText));
|
||||
retval = a_read_i(data, attribs, owner, key);
|
||||
READ_TOK(data->store, zText, sizeof(zText));
|
||||
if (!strcmp(zText, "end"))
|
||||
break;
|
||||
key = __at_hashkey(zText);
|
||||
|
|
|
@ -55,7 +55,7 @@ extern "C" {
|
|||
int(*age) (struct attrib *, void *owner);
|
||||
/* age returns 0 if the attribute needs to be removed, !=0 otherwise */
|
||||
void(*write) (const struct attrib *, const void *owner, struct storage *);
|
||||
int(*read) (struct attrib *, void *owner, struct storage *); /* return AT_READ_OK on success, AT_READ_FAIL if attrib needs removal */
|
||||
int(*read) (struct attrib *, void *owner, struct gamedata *); /* return AT_READ_OK on success, AT_READ_FAIL if attrib needs removal */
|
||||
void(*upgrade) (struct attrib **alist, struct attrib *a);
|
||||
unsigned int flags;
|
||||
/* ---- internal data, do not modify: ---- */
|
||||
|
@ -64,7 +64,7 @@ extern "C" {
|
|||
} attrib_type;
|
||||
|
||||
extern void at_register(attrib_type * at);
|
||||
extern void at_deprecate(const char * name, int(*reader)(attrib *, void *, struct storage *));
|
||||
extern void at_deprecate(const char * name, int(*reader)(attrib *, void *, struct gamedata *));
|
||||
|
||||
extern attrib *a_select(attrib * a, const void *data,
|
||||
bool(*compare) (const attrib *, const void *));
|
||||
|
@ -75,10 +75,10 @@ extern "C" {
|
|||
extern attrib *a_new(const attrib_type * at);
|
||||
int a_age(attrib ** attribs, void *owner);
|
||||
|
||||
int a_read_orig(struct storage *store, attrib ** attribs, void *owner);
|
||||
int a_read_orig(struct gamedata *data, attrib ** attribs, void *owner);
|
||||
void a_write_orig(struct storage *store, const attrib * attribs, const void *owner);
|
||||
|
||||
int a_read(struct storage *store, attrib ** attribs, void *owner);
|
||||
int a_read(struct gamedata *data, attrib ** attribs, void *owner);
|
||||
void a_write(struct storage *store, const attrib * attribs, const void *owner);
|
||||
|
||||
void free_attribs(void);
|
||||
|
|
|
@ -21,6 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
/* util includes */
|
||||
#include "attrib.h"
|
||||
#include "gamedata.h"
|
||||
#include "log.h"
|
||||
#include "storage.h"
|
||||
|
||||
|
@ -143,8 +144,9 @@ write_handler(const attrib * a, const void *owner, struct storage *store)
|
|||
write_triggers(store, hi->triggers);
|
||||
}
|
||||
|
||||
static int read_handler(attrib * a, void *owner, struct storage *store)
|
||||
static int read_handler(attrib * a, void *owner, gamedata *data)
|
||||
{
|
||||
struct storage *store = data->store;
|
||||
char zText[128];
|
||||
handler_info *hi = (handler_info *)a->data.v;
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ static const char * password_hash_i(const char * passwd, const char *input, int
|
|||
memcpy(salt, input, salt_len);
|
||||
salt[salt_len] = 0;
|
||||
} else {
|
||||
input = password_gensalt(salt, sizeof(salt));
|
||||
input = password_gensalt(salt, SALTLEN);
|
||||
}
|
||||
if (algo == PASSWORD_MD5) {
|
||||
return md5_crypt_r(passwd, input, result, len);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <kernel/region.h>
|
||||
|
||||
#include <util/attrib.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <util/umlaut.h>
|
||||
|
@ -74,8 +75,9 @@ static int a_agedirection(attrib * a, void *owner)
|
|||
return (d->duration > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
||||
}
|
||||
|
||||
static int a_readdirection(attrib * a, void *owner, struct storage *store)
|
||||
static int a_readdirection(attrib * a, void *owner, struct gamedata *data)
|
||||
{
|
||||
struct storage *store = data->store;
|
||||
spec_direction *d = (spec_direction *)(a->data.v);
|
||||
char lbuf[32];
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/language.h>
|
||||
#include <util/resolve.h>
|
||||
#include <util/rng.h>
|
||||
|
@ -109,8 +110,9 @@ static int resolve_exit(variant id, void *address)
|
|||
return -1;
|
||||
}
|
||||
|
||||
static int wormhole_read(struct attrib *a, void *owner, struct storage *store)
|
||||
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_exit : resolve_region_id;
|
||||
read_fun reader = (global.data_version < UIDHASH_VERSION)
|
||||
|
|
Loading…
Reference in a new issue