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;
|
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)
|
static int wormhole_age(struct attrib *a, void *owner)
|
||||||
{
|
{
|
||||||
wormhole_data *data = (wormhole_data *)a->data.v;
|
building *entry = (building *)owner;
|
||||||
building *b = (building *)owner;
|
region *exit = (region *)a->data.v;
|
||||||
int maxtransport = b->size;
|
int maxtransport = entry->size;
|
||||||
region *r = b->region;
|
region *r = entry->region;
|
||||||
unit *u = r->units;
|
unit *u = r->units;
|
||||||
|
|
||||||
unused_arg(owner);
|
unused_arg(owner);
|
||||||
for (; u != NULL && maxtransport != 0; u = u->next) {
|
for (; u != NULL && maxtransport != 0; u = u->next) {
|
||||||
if (u->building == b) {
|
if (u->building == entry) {
|
||||||
message *m = NULL;
|
message *m = NULL;
|
||||||
if (u->number > maxtransport || has_limited_skills(u)) {
|
if (u->number > maxtransport || has_limited_skills(u)) {
|
||||||
m = msg_message("wormhole_requirements", "unit region", u, u->region);
|
m = msg_message("wormhole_requirements", "unit region", u, u->region);
|
||||||
}
|
}
|
||||||
else if (data->exit != NULL) {
|
else if (exit != NULL) {
|
||||||
move_unit(u, data->exit, NULL);
|
move_unit(u, exit, NULL);
|
||||||
maxtransport -= u->number;
|
maxtransport -= u->number;
|
||||||
m = msg_message("wormhole_exit", "unit region", u, data->exit);
|
m = msg_message("wormhole_exit", "unit region", u, exit);
|
||||||
add_message(&data->exit->msgs, m);
|
add_message(&exit->msgs, m);
|
||||||
}
|
}
|
||||||
if (m != NULL) {
|
if (m != NULL) {
|
||||||
add_message(&u->faction->msgs, m);
|
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));
|
ADDMSG(&r->msgs, msg_message("wormhole_dissolve", "region", r));
|
||||||
|
|
||||||
/* age returns 0 if the attribute needs to be removed, !=0 otherwise */
|
/* 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)
|
static void wormhole_write(const struct attrib *a, const void *owner, struct storage *store)
|
||||||
{
|
{
|
||||||
wormhole_data *data = (wormhole_data *)a->data.v;
|
region *exit = (region *)a->data.v;
|
||||||
write_region_reference(data->exit, store);
|
write_region_reference(exit, store);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** conversion code, turn 573, 2008-05-23 */
|
/** 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)
|
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_fun resolver = (global.data_version < UIDHASH_VERSION)
|
||||||
? resolve_exit : resolve_region_id;
|
? resolve_exit : resolve_region_id;
|
||||||
read_fun reader = (global.data_version < UIDHASH_VERSION)
|
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) {
|
if (global.data_version < ATTRIBOWNER_VERSION) {
|
||||||
READ_INT(store, NULL);
|
READ_INT(store, NULL);
|
||||||
}
|
}
|
||||||
if (read_reference(&data->exit, store, reader, resolver) == 0) {
|
if (read_reference(&a->data.v, store, reader, resolver) == 0) {
|
||||||
if (!data->exit) {
|
if (!a->data.v) {
|
||||||
return AT_READ_FAIL;
|
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 = {
|
static attrib_type at_wormhole = {
|
||||||
"wormhole",
|
"wormhole",
|
||||||
wormhole_init,
|
NULL,
|
||||||
wormhole_done,
|
NULL,
|
||||||
wormhole_age,
|
wormhole_age,
|
||||||
wormhole_write,
|
wormhole_write,
|
||||||
wormhole_read,
|
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);
|
building *b2 = new_building(bt_wormhole, r2, default_locale);
|
||||||
attrib *a1 = a_add(&b1->attribs, a_new(&at_wormhole));
|
attrib *a1 = a_add(&b1->attribs, a_new(&at_wormhole));
|
||||||
attrib *a2 = a_add(&b2->attribs, a_new(&at_wormhole));
|
attrib *a2 = a_add(&b2->attribs, a_new(&at_wormhole));
|
||||||
wormhole_data *d1 = (wormhole_data *)a1->data.v;
|
a1->data.v = b2->region;
|
||||||
wormhole_data *d2 = (wormhole_data *)a2->data.v;
|
a2->data.v = b1->region;
|
||||||
d1->exit = b2->region;
|
|
||||||
d2->exit = b1->region;
|
|
||||||
b1->size = bt_wormhole->maxsize;
|
b1->size = bt_wormhole->maxsize;
|
||||||
b2->size = bt_wormhole->maxsize;
|
b2->size = bt_wormhole->maxsize;
|
||||||
ADDMSG(&r1->msgs, msg_message("wormhole_appear", "region", r1));
|
ADDMSG(&r1->msgs, msg_message("wormhole_appear", "region", r1));
|
||||||
|
|
Loading…
Reference in a new issue