forked from github/server
resolve a TODO, make attribute (and data) a little bit smaller.
This commit is contained in:
parent
33d1521bfd
commit
fc86de85f1
|
@ -28,7 +28,6 @@ without prior permission by the authors of Eressea.
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
typedef struct building_action {
|
typedef struct building_action {
|
||||||
struct building *b; // TODO: remove, use attribute-owner?
|
|
||||||
char *fname;
|
char *fname;
|
||||||
char *param;
|
char *param;
|
||||||
} building_action;
|
} building_action;
|
||||||
|
@ -38,11 +37,10 @@ static int lc_age(struct attrib *a, void *owner)
|
||||||
building_action *data = (building_action *)a->data.v;
|
building_action *data = (building_action *)a->data.v;
|
||||||
const char *fname = data->fname;
|
const char *fname = data->fname;
|
||||||
const char *fparam = data->param;
|
const char *fparam = data->param;
|
||||||
building *b = data->b;
|
building *b = (building *)owner;
|
||||||
int result = -1;
|
int result = -1;
|
||||||
|
|
||||||
assert(b != NULL);
|
assert(b != NULL);
|
||||||
assert(owner == b);
|
|
||||||
if (fname != NULL) {
|
if (fname != NULL) {
|
||||||
lua_State *L = (lua_State *)global.vm_state;
|
lua_State *L = (lua_State *)global.vm_state;
|
||||||
|
|
||||||
|
@ -94,9 +92,10 @@ lc_write(const struct attrib *a, const void *owner, struct storage *store)
|
||||||
building_action *data = (building_action *)a->data.v;
|
building_action *data = (building_action *)a->data.v;
|
||||||
const char *fname = data->fname;
|
const char *fname = data->fname;
|
||||||
const char *fparam = data->param;
|
const char *fparam = data->param;
|
||||||
building *b = data->b;
|
|
||||||
|
|
||||||
write_building_reference(b, store);
|
#if RELEASE_VERSION < ATTRIBOWNER_VERSION
|
||||||
|
write_building_reference((building *)owner, store);
|
||||||
|
#endif
|
||||||
WRITE_TOK(store, fname);
|
WRITE_TOK(store, fname);
|
||||||
WRITE_TOK(store, fparam ? fparam : NULLSTRING);
|
WRITE_TOK(store, fparam ? fparam : NULLSTRING);
|
||||||
}
|
}
|
||||||
|
@ -105,13 +104,17 @@ static int lc_read(struct attrib *a, void *owner, struct storage *store)
|
||||||
{
|
{
|
||||||
char name[NAMESIZE];
|
char name[NAMESIZE];
|
||||||
building_action *data = (building_action *)a->data.v;
|
building_action *data = (building_action *)a->data.v;
|
||||||
int result =
|
building *b = (building *)owner;
|
||||||
read_reference(&data->b, store, read_building_reference, resolve_building);
|
int result = 0;
|
||||||
|
if (global.data_version < ATTRIBOWNER_VERSION) {
|
||||||
|
result = read_reference(&b, store, read_building_reference, resolve_building);
|
||||||
|
assert(b == owner);
|
||||||
|
}
|
||||||
READ_TOK(store, name, sizeof(name));
|
READ_TOK(store, name, sizeof(name));
|
||||||
if (strcmp(name, "tunnel_action") == 0) {
|
if (strcmp(name, "tunnel_action") == 0) {
|
||||||
/* E2: Weltentor has a new module, doesn't need this any longer */
|
/* E2: Weltentor has a new module, doesn't need this any longer */
|
||||||
result = 0;
|
result = 0;
|
||||||
data->b = 0;
|
b = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
data->fname = _strdup(name);
|
data->fname = _strdup(name);
|
||||||
|
@ -120,14 +123,14 @@ static int lc_read(struct attrib *a, void *owner, struct storage *store)
|
||||||
if (strcmp(name, "tnnL") == 0) {
|
if (strcmp(name, "tnnL") == 0) {
|
||||||
/* tunnel_action was the old Weltentore, their code has changed. ignore this object */
|
/* tunnel_action was the old Weltentore, their code has changed. ignore this object */
|
||||||
result = 0;
|
result = 0;
|
||||||
data->b = 0;
|
b = 0;
|
||||||
}
|
}
|
||||||
if (strcmp(name, NULLSTRING) == 0)
|
if (strcmp(name, NULLSTRING) == 0)
|
||||||
data->param = 0;
|
data->param = 0;
|
||||||
else {
|
else {
|
||||||
data->param = _strdup(name);
|
data->param = _strdup(name);
|
||||||
}
|
}
|
||||||
if (result == 0 && !data->b) {
|
if (result == 0 && !b) {
|
||||||
return AT_READ_FAIL;
|
return AT_READ_FAIL;
|
||||||
}
|
}
|
||||||
return AT_READ_OK;
|
return AT_READ_OK;
|
||||||
|
@ -144,7 +147,6 @@ void building_addaction(building * b, const char *fname, const char *param)
|
||||||
{
|
{
|
||||||
attrib *a = a_add(&b->attribs, a_new(&at_building_action));
|
attrib *a = a_add(&b->attribs, a_new(&at_building_action));
|
||||||
building_action *data = (building_action *)a->data.v;
|
building_action *data = (building_action *)a->data.v;
|
||||||
data->b = b;
|
|
||||||
data->fname = _strdup(fname);
|
data->fname = _strdup(fname);
|
||||||
if (param) {
|
if (param) {
|
||||||
data->param = _strdup(param);
|
data->param = _strdup(param);
|
||||||
|
|
|
@ -32,8 +32,9 @@
|
||||||
#define EXPLICIT_CURSE_ISNEW_VERSION 347 /* CURSE_ISNEW is not reset in read/write, but in age() */
|
#define EXPLICIT_CURSE_ISNEW_VERSION 347 /* CURSE_ISNEW is not reset in read/write, but in age() */
|
||||||
#define SPELL_LEVEL_VERSION 348 /* f->max_spelllevel gets stored, not calculated */
|
#define SPELL_LEVEL_VERSION 348 /* f->max_spelllevel gets stored, not calculated */
|
||||||
#define OWNER_3_VERSION 349 /* regions store last owner, not last alliance */
|
#define OWNER_3_VERSION 349 /* regions store last owner, not last alliance */
|
||||||
|
#define ATTRIBOWNER_VERSION 350 /* all attrib_type functions know who owns the attribute */
|
||||||
|
|
||||||
#define RELEASE_VERSION OWNER_3_VERSION /* current datafile */
|
#define RELEASE_VERSION ATTRIBOWNER_VERSION /* current datafile */
|
||||||
#define MIN_VERSION INTPAK_VERSION /* minimal datafile we support */
|
#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 MAX_VERSION RELEASE_VERSION /* change this if we can need to read the future datafile, and we can do so */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue