forked from github/server
remove wormhole_data struct now that it's nearly empty
This commit is contained in:
parent
9d1b5dccb8
commit
beb12372e0
1 changed files with 18 additions and 35 deletions
|
@ -55,40 +55,26 @@ static int cmp_age(const void *v1, const void *v2)
|
|||
return 0;
|
||||
}
|
||||
|
||||
typedef struct wormhole_data {
|
||||
region *exit;
|
||||
} wormhole_data;
|
||||
|
||||
static void wormhole_init(struct attrib *a)
|
||||
{
|
||||
a->data.v = calloc(1, sizeof(wormhole_data));
|
||||
}
|
||||
|
||||
static void wormhole_done(struct attrib *a)
|
||||
{
|
||||
free(a->data.v);
|
||||
}
|
||||
|
||||
static int wormhole_age(struct attrib *a, void *owner)
|
||||
{
|
||||
wormhole_data *data = (wormhole_data *)a->data.v;
|
||||
building *b = (building *)owner;
|
||||
int maxtransport = b->size;
|
||||
region *r = b->region;
|
||||
building *entry = (building *)owner;
|
||||
region *exit = (region *)a->data.v;
|
||||
int maxtransport = entry->size;
|
||||
region *r = entry->region;
|
||||
unit *u = r->units;
|
||||
|
||||
unused_arg(owner);
|
||||
for (; u != NULL && maxtransport != 0; u = u->next) {
|
||||
if (u->building == b) {
|
||||
if (u->building == entry) {
|
||||
message *m = NULL;
|
||||
if (u->number > maxtransport || has_limited_skills(u)) {
|
||||
m = msg_message("wormhole_requirements", "unit region", u, u->region);
|
||||
}
|
||||
else if (data->exit != NULL) {
|
||||
move_unit(u, data->exit, NULL);
|
||||
else if (exit != NULL) {
|
||||
move_unit(u, exit, NULL);
|
||||
maxtransport -= u->number;
|
||||
m = msg_message("wormhole_exit", "unit region", u, data->exit);
|
||||
add_message(&data->exit->msgs, m);
|
||||
m = msg_message("wormhole_exit", "unit region", u, exit);
|
||||
add_message(&exit->msgs, m);
|
||||
}
|
||||
if (m != NULL) {
|
||||
add_message(&u->faction->msgs, m);
|
||||
|
@ -97,7 +83,7 @@ static int wormhole_age(struct attrib *a, void *owner)
|
|||
}
|
||||
}
|
||||
|
||||
remove_building(&r->buildings, b);
|
||||
remove_building(&r->buildings, entry);
|
||||
ADDMSG(&r->msgs, msg_message("wormhole_dissolve", "region", r));
|
||||
|
||||
/* age returns 0 if the attribute needs to be removed, !=0 otherwise */
|
||||
|
@ -106,8 +92,8 @@ static int wormhole_age(struct attrib *a, void *owner)
|
|||
|
||||
static void wormhole_write(const struct attrib *a, const void *owner, struct storage *store)
|
||||
{
|
||||
wormhole_data *data = (wormhole_data *)a->data.v;
|
||||
write_region_reference(data->exit, store);
|
||||
region *exit = (region *)a->data.v;
|
||||
write_region_reference(exit, store);
|
||||
}
|
||||
|
||||
/** conversion code, turn 573, 2008-05-23 */
|
||||
|
@ -125,7 +111,6 @@ static int resolve_exit(variant id, void *address)
|
|||
|
||||
static int wormhole_read(struct attrib *a, void *owner, struct storage *store)
|
||||
{
|
||||
wormhole_data *data = (wormhole_data *)a->data.v;
|
||||
resolve_fun resolver = (global.data_version < UIDHASH_VERSION)
|
||||
? resolve_exit : resolve_region_id;
|
||||
read_fun reader = (global.data_version < UIDHASH_VERSION)
|
||||
|
@ -134,8 +119,8 @@ static int wormhole_read(struct attrib *a, void *owner, struct storage *store)
|
|||
if (global.data_version < ATTRIBOWNER_VERSION) {
|
||||
READ_INT(store, NULL);
|
||||
}
|
||||
if (read_reference(&data->exit, store, reader, resolver) == 0) {
|
||||
if (!data->exit) {
|
||||
if (read_reference(&a->data.v, store, reader, resolver) == 0) {
|
||||
if (!a->data.v) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
}
|
||||
|
@ -144,8 +129,8 @@ static int wormhole_read(struct attrib *a, void *owner, struct storage *store)
|
|||
|
||||
static attrib_type at_wormhole = {
|
||||
"wormhole",
|
||||
wormhole_init,
|
||||
wormhole_done,
|
||||
NULL,
|
||||
NULL,
|
||||
wormhole_age,
|
||||
wormhole_write,
|
||||
wormhole_read,
|
||||
|
@ -159,10 +144,8 @@ make_wormhole(const building_type * bt_wormhole, region * r1, region * r2)
|
|||
building *b2 = new_building(bt_wormhole, r2, default_locale);
|
||||
attrib *a1 = a_add(&b1->attribs, a_new(&at_wormhole));
|
||||
attrib *a2 = a_add(&b2->attribs, a_new(&at_wormhole));
|
||||
wormhole_data *d1 = (wormhole_data *)a1->data.v;
|
||||
wormhole_data *d2 = (wormhole_data *)a2->data.v;
|
||||
d1->exit = b2->region;
|
||||
d2->exit = b1->region;
|
||||
a1->data.v = b2->region;
|
||||
a2->data.v = b1->region;
|
||||
b1->size = bt_wormhole->maxsize;
|
||||
b2->size = bt_wormhole->maxsize;
|
||||
ADDMSG(&r1->msgs, msg_message("wormhole_appear", "region", r1));
|
||||
|
|
Loading…
Reference in a new issue