forked from github/server
fix a TODO, reduce size of icastle_data
This commit is contained in:
parent
a02d71bfef
commit
74d8b53ba8
5 changed files with 26 additions and 28 deletions
|
@ -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);
|
||||
}
|
||||
|
|
31
src/magic.c
31
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);
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Loading…
Reference in a new issue