From 74d8b53ba8e6489cdca619e53fb511b68304a884 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 17 Dec 2015 12:59:12 +0100 Subject: [PATCH] fix a TODO, reduce size of icastle_data --- src/building_action.c | 4 +--- src/magic.c | 31 +++++++++++++++++++++---------- src/magic.h | 7 ++----- src/reports.c | 3 +-- src/spells.c | 9 +-------- 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/building_action.c b/src/building_action.c index 4b0c21246..29c20a99d 100644 --- a/src/building_action.c +++ b/src/building_action.c @@ -93,9 +93,7 @@ lc_write(const struct attrib *a, const void *owner, struct storage *store) const char *fname = data->fname; const char *fparam = data->param; -#if RELEASE_VERSION < ATTRIBOWNER_VERSION - write_building_reference((building *)owner, store); -#endif + unused_arg(owner); WRITE_TOK(store, fname); WRITE_TOK(store, fparam ? fparam : NULLSTRING); } diff --git a/src/magic.c b/src/magic.c index 949565c31..dc6d6e9dc 100644 --- a/src/magic.c +++ b/src/magic.c @@ -124,19 +124,20 @@ static double MagicPower(double force) return 0; } +typedef struct icastle_data { + const struct building_type *type; + int time; +} icastle_data; + static int a_readicastle(attrib * a, void *owner, struct storage *store) { icastle_data *data = (icastle_data *)a->data.v; - variant bno; char token[32]; READ_TOK(store, token, sizeof(token)); - READ_INT(store, &bno.i); - READ_INT(store, &data->time); - data->building = findbuilding(bno.i); - if (!data->building) { - /* this shouldn't happen, but just in case it does: */ - ur_add(bno, &data->building, resolve_building); + if (global.data_version < ATTRIBOWNER_VERSION) { + READ_INT(store, NULL); } + READ_INT(store, &data->time); data->type = bt_find(token); return AT_READ_OK; } @@ -145,9 +146,8 @@ static void a_writeicastle(const attrib * a, const void *owner, struct storage *store) { icastle_data *data = (icastle_data *)a->data.v; - assert(owner == data->building); + unused_arg(owner); WRITE_TOK(store, data->type->_name); - WRITE_INT(store, data->building->no); WRITE_INT(store, data->time); } @@ -155,7 +155,7 @@ static int a_ageicastle(struct attrib *a, void *owner) { icastle_data *data = (icastle_data *)a->data.v; if (data->time <= 0) { - building *b = data->building; // TODO: use owner + building *b = (building *)owner; region *r = b->region; assert(owner == b); ADDMSG(&r->msgs, msg_message("icastle_dissolve", "building", b)); @@ -187,6 +187,17 @@ attrib_type at_icastle = { a_readicastle }; +void make_icastle(building *b, const building_type *btype, int timeout) { + attrib *a = a_add(&b->attribs, a_new(&at_icastle)); + icastle_data *data = (icastle_data *)a->data.v; + data->type = btype; + data->time = timeout; +} + +const building_type *icastle_type(const struct attrib *a) { + icastle_data *icastle = (icastle_data *)a->data.v; + return icastle->type; +} /* ------------------------------------------------------------- */ extern int dice(int count, int value); diff --git a/src/magic.h b/src/magic.h index 3a1854cfb..257ba11c4 100644 --- a/src/magic.h +++ b/src/magic.h @@ -206,11 +206,8 @@ extern "C" { extern struct attrib_type at_reportspell; extern struct attrib_type at_icastle; - typedef struct icastle_data { - const struct building_type *type; - struct building *building; // TODO: remove, use owner argument - int time; - } icastle_data; + void make_icastle(struct building *b, const struct building_type *btype, int timeout); + const struct building_type *icastle_type(const struct attrib *a); /* ------------------------------------------------------------- */ /* Kommentare: diff --git a/src/reports.c b/src/reports.c index 24ff6dcb2..99b9f755c 100644 --- a/src/reports.c +++ b/src/reports.c @@ -356,8 +356,7 @@ const char **illusion) if (bt_illusion && b->type == bt_illusion) { const attrib *a = a_findc(b->attribs, &at_icastle); if (a != NULL) { - icastle_data *icastle = (icastle_data *)a->data.v; - *illusion = buildingtype(icastle->type, b, b->size); + *illusion = buildingtype(icastle_type(a), b, b->size); } } } diff --git a/src/spells.c b/src/spells.c index 4a3b81d7a..1445598d9 100644 --- a/src/spells.c +++ b/src/spells.c @@ -4477,13 +4477,11 @@ int sp_icastle(castorder * co) { building *b; const building_type *type; - attrib *a; region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; double power = co->force; spellparameter *pa = co->par; - icastle_data *data; const char *bname; message *msg; const building_type *bt_illusion = bt_find("illusioncastle"); @@ -4519,12 +4517,7 @@ int sp_icastle(castorder * co) building_setname(b, bname); /* TODO: Auf timeout und action_destroy umstellen */ - a = a_add(&b->attribs, a_new(&at_icastle)); - data = (icastle_data *)a->data.v; - data->type = type; - data->building = b; - data->time = - 2 + (rng_int() % (int)(power)+1) * (rng_int() % (int)(power)+1); + make_icastle(b, type, 2 + (rng_int() % (int)(power)+1) * (rng_int() % (int)(power)+1)); if (mage->region == r) { if (leave(mage, false)) {