fix a TODO, reduce size of icastle_data

This commit is contained in:
Enno Rehling 2015-12-17 12:59:12 +01:00
parent a02d71bfef
commit 74d8b53ba8
5 changed files with 26 additions and 28 deletions

View file

@ -93,9 +93,7 @@ lc_write(const struct attrib *a, const void *owner, struct storage *store)
const char *fname = data->fname; const char *fname = data->fname;
const char *fparam = data->param; const char *fparam = data->param;
#if RELEASE_VERSION < ATTRIBOWNER_VERSION unused_arg(owner);
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);
} }

View file

@ -124,19 +124,20 @@ static double MagicPower(double force)
return 0; 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) static int a_readicastle(attrib * a, void *owner, struct storage *store)
{ {
icastle_data *data = (icastle_data *)a->data.v; icastle_data *data = (icastle_data *)a->data.v;
variant bno;
char token[32]; char token[32];
READ_TOK(store, token, sizeof(token)); READ_TOK(store, token, sizeof(token));
READ_INT(store, &bno.i); if (global.data_version < ATTRIBOWNER_VERSION) {
READ_INT(store, &data->time); READ_INT(store, NULL);
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);
} }
READ_INT(store, &data->time);
data->type = bt_find(token); data->type = bt_find(token);
return AT_READ_OK; return AT_READ_OK;
} }
@ -145,9 +146,8 @@ static void
a_writeicastle(const attrib * a, const void *owner, struct storage *store) a_writeicastle(const attrib * a, const void *owner, struct storage *store)
{ {
icastle_data *data = (icastle_data *)a->data.v; icastle_data *data = (icastle_data *)a->data.v;
assert(owner == data->building); unused_arg(owner);
WRITE_TOK(store, data->type->_name); WRITE_TOK(store, data->type->_name);
WRITE_INT(store, data->building->no);
WRITE_INT(store, data->time); 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; icastle_data *data = (icastle_data *)a->data.v;
if (data->time <= 0) { if (data->time <= 0) {
building *b = data->building; // TODO: use owner building *b = (building *)owner;
region *r = b->region; region *r = b->region;
assert(owner == b); assert(owner == b);
ADDMSG(&r->msgs, msg_message("icastle_dissolve", "building", b)); ADDMSG(&r->msgs, msg_message("icastle_dissolve", "building", b));
@ -187,6 +187,17 @@ attrib_type at_icastle = {
a_readicastle 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); extern int dice(int count, int value);

View file

@ -206,11 +206,8 @@ extern "C" {
extern struct attrib_type at_reportspell; extern struct attrib_type at_reportspell;
extern struct attrib_type at_icastle; extern struct attrib_type at_icastle;
typedef struct icastle_data { void make_icastle(struct building *b, const struct building_type *btype, int timeout);
const struct building_type *type; const struct building_type *icastle_type(const struct attrib *a);
struct building *building; // TODO: remove, use owner argument
int time;
} icastle_data;
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
/* Kommentare: /* Kommentare:

View file

@ -356,8 +356,7 @@ const char **illusion)
if (bt_illusion && b->type == bt_illusion) { if (bt_illusion && b->type == bt_illusion) {
const attrib *a = a_findc(b->attribs, &at_icastle); const attrib *a = a_findc(b->attribs, &at_icastle);
if (a != NULL) { if (a != NULL) {
icastle_data *icastle = (icastle_data *)a->data.v; *illusion = buildingtype(icastle_type(a), b, b->size);
*illusion = buildingtype(icastle->type, b, b->size);
} }
} }
} }

View file

@ -4477,13 +4477,11 @@ int sp_icastle(castorder * co)
{ {
building *b; building *b;
const building_type *type; const building_type *type;
attrib *a;
region *r = co_get_region(co); region *r = co_get_region(co);
unit *mage = co->magician.u; unit *mage = co->magician.u;
int cast_level = co->level; int cast_level = co->level;
double power = co->force; double power = co->force;
spellparameter *pa = co->par; spellparameter *pa = co->par;
icastle_data *data;
const char *bname; const char *bname;
message *msg; message *msg;
const building_type *bt_illusion = bt_find("illusioncastle"); const building_type *bt_illusion = bt_find("illusioncastle");
@ -4519,12 +4517,7 @@ int sp_icastle(castorder * co)
building_setname(b, bname); building_setname(b, bname);
/* TODO: Auf timeout und action_destroy umstellen */ /* TODO: Auf timeout und action_destroy umstellen */
a = a_add(&b->attribs, a_new(&at_icastle)); make_icastle(b, type, 2 + (rng_int() % (int)(power)+1) * (rng_int() % (int)(power)+1));
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);
if (mage->region == r) { if (mage->region == r) {
if (leave(mage, false)) { if (leave(mage, false)) {