forked from github/server
pass the parent of an attribute into a_age and attrib_type::age
This commit is contained in:
parent
22367249db
commit
33d1521bfd
23 changed files with 70 additions and 43 deletions
|
@ -219,9 +219,10 @@ static void free_potiondelay(attrib * a)
|
||||||
free(a->data.v);
|
free(a->data.v);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int age_potiondelay(attrib * a)
|
static int age_potiondelay(attrib * a, void *owner)
|
||||||
{
|
{
|
||||||
potiondelay *pd = (potiondelay *)a->data.v;
|
potiondelay *pd = (potiondelay *)a->data.v;
|
||||||
|
unused_arg(owner);
|
||||||
pd->amount = do_potion(pd->u, pd->r, pd->ptype, pd->amount);
|
pd->amount = do_potion(pd->u, pd->r, pd->ptype, pd->amount);
|
||||||
return AT_AGE_REMOVE;
|
return AT_AGE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include <storage.h>
|
#include <storage.h>
|
||||||
|
|
||||||
static int verify_hate(attrib * a)
|
static int verify_hate(attrib * a, void *owner)
|
||||||
{
|
{
|
||||||
|
unused_arg(owner);
|
||||||
if (a->data.v == NULL) {
|
if (a->data.v == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include <storage.h>
|
#include <storage.h>
|
||||||
|
|
||||||
static int age_moved(attrib * a)
|
static int age_moved(attrib * a, void *owner)
|
||||||
{
|
{
|
||||||
|
unused_arg(owner);
|
||||||
--a->data.i;
|
--a->data.i;
|
||||||
return a->data.i > 0;
|
return a->data.i > 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,8 +65,9 @@ void set_movement(attrib ** alist, int type)
|
||||||
a->data.i |= type;
|
a->data.i |= type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int age_speedup(attrib * a)
|
static int age_speedup(attrib * a, void *owner)
|
||||||
{
|
{
|
||||||
|
unused_arg(owner);
|
||||||
if (a->data.sa[0] > 0) {
|
if (a->data.sa[0] > 0) {
|
||||||
assert(a->data.sa[0] - a->data.sa[1] >= SHRT_MIN);
|
assert(a->data.sa[0] - a->data.sa[1] >= SHRT_MIN);
|
||||||
assert(a->data.sa[0] - a->data.sa[1] <= SHRT_MAX);
|
assert(a->data.sa[0] - a->data.sa[1] <= SHRT_MAX);
|
||||||
|
|
|
@ -20,15 +20,26 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include "reduceproduction.h"
|
#include "reduceproduction.h"
|
||||||
#include <kernel/save.h>
|
#include <kernel/save.h>
|
||||||
|
#include <kernel/region.h>
|
||||||
|
#include <kernel/messages.h>
|
||||||
|
#include <util/message.h>
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
static int age_reduceproduction(attrib * a)
|
static int age_reduceproduction(attrib * a, void *owner)
|
||||||
{
|
{
|
||||||
|
region * r = (region *)owner;
|
||||||
int reduce = 100 - (5 * --a->data.sa[1]);
|
int reduce = 100 - (5 * --a->data.sa[1]);
|
||||||
if (reduce < 10)
|
assert(r);
|
||||||
|
if (reduce < 10) {
|
||||||
reduce = 10;
|
reduce = 10;
|
||||||
|
}
|
||||||
a->data.sa[0] = (short)reduce;
|
a->data.sa[0] = (short)reduce;
|
||||||
return (a->data.sa[1] > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
if (a->data.sa[1] > 0) {
|
||||||
|
ADDMSG(&r->msgs, msg_message("reduceproduction", ""));
|
||||||
|
return AT_AGE_KEEP;
|
||||||
|
}
|
||||||
|
return AT_AGE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
attrib_type at_reduceproduction = {
|
attrib_type at_reduceproduction = {
|
||||||
|
|
|
@ -28,12 +28,12 @@ without prior permission by the authors of Eressea.
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
typedef struct building_action {
|
typedef struct building_action {
|
||||||
struct building *b;
|
struct building *b; // TODO: remove, use attribute-owner?
|
||||||
char *fname;
|
char *fname;
|
||||||
char *param;
|
char *param;
|
||||||
} building_action;
|
} building_action;
|
||||||
|
|
||||||
static int lc_age(struct attrib *a)
|
static int lc_age(struct attrib *a, void *owner)
|
||||||
{
|
{
|
||||||
building_action *data = (building_action *)a->data.v;
|
building_action *data = (building_action *)a->data.v;
|
||||||
const char *fname = data->fname;
|
const char *fname = data->fname;
|
||||||
|
@ -42,6 +42,7 @@ static int lc_age(struct attrib *a)
|
||||||
int result = -1;
|
int result = -1;
|
||||||
|
|
||||||
assert(b != NULL);
|
assert(b != NULL);
|
||||||
|
assert(owner == b);
|
||||||
if (fname != NULL) {
|
if (fname != NULL) {
|
||||||
lua_State *L = (lua_State *)global.vm_state;
|
lua_State *L = (lua_State *)global.vm_state;
|
||||||
|
|
||||||
|
|
|
@ -45,8 +45,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#define HORNDURATION 3
|
#define HORNDURATION 3
|
||||||
#define HORNIMMUNITY 30
|
#define HORNIMMUNITY 30
|
||||||
|
|
||||||
static int age_peaceimmune(attrib * a)
|
static int age_peaceimmune(attrib * a, void *owner)
|
||||||
{
|
{
|
||||||
|
unused_arg(owner);
|
||||||
return (--a->data.i > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
return (--a->data.i > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,11 +112,12 @@ void curse_init(attrib * a)
|
||||||
a->data.v = calloc(1, sizeof(curse));
|
a->data.v = calloc(1, sizeof(curse));
|
||||||
}
|
}
|
||||||
|
|
||||||
int curse_age(attrib * a)
|
int curse_age(attrib * a, void *owner)
|
||||||
{
|
{
|
||||||
curse *c = (curse *)a->data.v;
|
curse *c = (curse *)a->data.v;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
|
unused_arg(owner);
|
||||||
c_clearflag(c, CURSE_ISNEW);
|
c_clearflag(c, CURSE_ISNEW);
|
||||||
|
|
||||||
if (c_flags(c) & CURSE_NOAGE) {
|
if (c_flags(c) & CURSE_NOAGE) {
|
||||||
|
|
|
@ -291,7 +291,7 @@ extern "C" {
|
||||||
|
|
||||||
void curse_init(struct attrib *a);
|
void curse_init(struct attrib *a);
|
||||||
void curse_done(struct attrib *a);
|
void curse_done(struct attrib *a);
|
||||||
int curse_age(struct attrib *a);
|
int curse_age(struct attrib *a, void *owner);
|
||||||
|
|
||||||
double destr_curse(struct curse *c, int cast_level, double force);
|
double destr_curse(struct curse *c, int cast_level, double force);
|
||||||
|
|
||||||
|
|
|
@ -771,10 +771,11 @@ void set_level(unit * u, skill_t sk, int value)
|
||||||
sk_set(add_skill(u, sk), value);
|
sk_set(add_skill(u, sk), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int leftship_age(struct attrib *a)
|
static int leftship_age(struct attrib *a, void *owner)
|
||||||
{
|
{
|
||||||
/* must be aged, so it doesn't affect report generation (cansee) */
|
/* must be aged, so it doesn't affect report generation (cansee) */
|
||||||
unused_arg(a);
|
unused_arg(a);
|
||||||
|
unused_arg(owner);
|
||||||
return AT_AGE_REMOVE; /* remove me */
|
return AT_AGE_REMOVE; /* remove me */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -341,12 +341,12 @@ static void test_age_familiar(CuTest *tc) {
|
||||||
CuAssertIntEquals(tc, true, create_newfamiliar(mag, fam));
|
CuAssertIntEquals(tc, true, create_newfamiliar(mag, fam));
|
||||||
CuAssertPtrEquals(tc, fam, get_familiar(mag));
|
CuAssertPtrEquals(tc, fam, get_familiar(mag));
|
||||||
CuAssertPtrEquals(tc, mag, get_familiar_mage(fam));
|
CuAssertPtrEquals(tc, mag, get_familiar_mage(fam));
|
||||||
a_age(&fam->attribs);
|
a_age(&fam->attribs, fam);
|
||||||
a_age(&mag->attribs);
|
a_age(&mag->attribs, mag);
|
||||||
CuAssertPtrEquals(tc, fam, get_familiar(mag));
|
CuAssertPtrEquals(tc, fam, get_familiar(mag));
|
||||||
CuAssertPtrEquals(tc, mag, get_familiar_mage(fam));
|
CuAssertPtrEquals(tc, mag, get_familiar_mage(fam));
|
||||||
set_number(fam, 0);
|
set_number(fam, 0);
|
||||||
a_age(&mag->attribs);
|
a_age(&mag->attribs, mag);
|
||||||
CuAssertPtrEquals(tc, 0, get_familiar(mag));
|
CuAssertPtrEquals(tc, 0, get_familiar(mag));
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
10
src/laws.c
10
src/laws.c
|
@ -3096,7 +3096,7 @@ static building *age_building(building * b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
a_age(&b->attribs);
|
a_age(&b->attribs, b);
|
||||||
handle_event(b->attribs, "timer", b);
|
handle_event(b->attribs, "timer", b);
|
||||||
|
|
||||||
if (b->type->age) {
|
if (b->type->age) {
|
||||||
|
@ -3108,7 +3108,7 @@ static building *age_building(building * b)
|
||||||
|
|
||||||
static void age_region(region * r)
|
static void age_region(region * r)
|
||||||
{
|
{
|
||||||
a_age(&r->attribs);
|
a_age(&r->attribs, r);
|
||||||
handle_event(r->attribs, "timer", r);
|
handle_event(r->attribs, "timer", r);
|
||||||
|
|
||||||
if (!r->land)
|
if (!r->land)
|
||||||
|
@ -3153,7 +3153,7 @@ static void ageing(void)
|
||||||
|
|
||||||
/* Factions */
|
/* Factions */
|
||||||
for (f = factions; f; f = f->next) {
|
for (f = factions; f; f = f->next) {
|
||||||
a_age(&f->attribs);
|
a_age(&f->attribs, f);
|
||||||
handle_event(f->attribs, "timer", f);
|
handle_event(f->attribs, "timer", f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3168,7 +3168,7 @@ static void ageing(void)
|
||||||
/* Einheiten */
|
/* Einheiten */
|
||||||
for (up = &r->units; *up;) {
|
for (up = &r->units; *up;) {
|
||||||
unit *u = *up;
|
unit *u = *up;
|
||||||
a_age(&u->attribs);
|
a_age(&u->attribs, u);
|
||||||
if (u == *up)
|
if (u == *up)
|
||||||
handle_event(u->attribs, "timer", u);
|
handle_event(u->attribs, "timer", u);
|
||||||
if (u == *up)
|
if (u == *up)
|
||||||
|
@ -3178,7 +3178,7 @@ static void ageing(void)
|
||||||
/* Schiffe */
|
/* Schiffe */
|
||||||
for (sp = &r->ships; *sp;) {
|
for (sp = &r->ships; *sp;) {
|
||||||
ship *s = *sp;
|
ship *s = *sp;
|
||||||
a_age(&s->attribs);
|
a_age(&s->attribs, s);
|
||||||
if (s == *sp)
|
if (s == *sp)
|
||||||
handle_event(s->attribs, "timer", s);
|
handle_event(s->attribs, "timer", s);
|
||||||
if (s == *sp)
|
if (s == *sp)
|
||||||
|
|
|
@ -149,17 +149,19 @@ 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);
|
||||||
WRITE_TOK(store, data->type->_name);
|
WRITE_TOK(store, data->type->_name);
|
||||||
WRITE_INT(store, data->building->no);
|
WRITE_INT(store, data->building->no);
|
||||||
WRITE_INT(store, data->time);
|
WRITE_INT(store, data->time);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int a_ageicastle(struct attrib *a)
|
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;
|
building *b = data->building; // TODO: use owner
|
||||||
region *r = b->region;
|
region *r = b->region;
|
||||||
|
assert(owner == b);
|
||||||
ADDMSG(&r->msgs, msg_message("icastle_dissolve", "building", b));
|
ADDMSG(&r->msgs, msg_message("icastle_dissolve", "building", b));
|
||||||
/* remove_building lets units leave the building */
|
/* remove_building lets units leave the building */
|
||||||
remove_building(&r->buildings, b);
|
remove_building(&r->buildings, b);
|
||||||
|
@ -2388,10 +2390,11 @@ static int read_magician(attrib * a, void *owner, struct storage *store)
|
||||||
return AT_READ_OK;
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int age_unit(attrib * a)
|
static int age_unit(attrib * a, void *owner)
|
||||||
/* if unit is gone or dead, remove the attribute */
|
/* if unit is gone or dead, remove the attribute */
|
||||||
{
|
{
|
||||||
unit *u = (unit *)a->data.v;
|
unit *u = (unit *)a->data.v;
|
||||||
|
unused_arg(owner);
|
||||||
return (u != NULL && u->number > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
return (u != NULL && u->number > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -208,7 +208,7 @@ extern "C" {
|
||||||
|
|
||||||
typedef struct icastle_data {
|
typedef struct icastle_data {
|
||||||
const struct building_type *type;
|
const struct building_type *type;
|
||||||
struct building *building; /* reverse pointer to dissolve the object */
|
struct building *building; // TODO: remove, use owner argument
|
||||||
int time;
|
int time;
|
||||||
} icastle_data;
|
} icastle_data;
|
||||||
|
|
||||||
|
|
|
@ -212,11 +212,12 @@ order * ord)
|
||||||
/**
|
/**
|
||||||
* Tempel der Schreie, Demo-Gebäude **/
|
* Tempel der Schreie, Demo-Gebäude **/
|
||||||
|
|
||||||
static int age_hurting(attrib * a)
|
static int age_hurting(attrib * a, void *owner)
|
||||||
{
|
{
|
||||||
building *b = (building *)a->data.v;
|
building *b = (building *)a->data.v;
|
||||||
unit *u;
|
unit *u;
|
||||||
int active = 0;
|
int active = 0;
|
||||||
|
assert(owner == b);
|
||||||
if (b == NULL)
|
if (b == NULL)
|
||||||
return AT_AGE_REMOVE;
|
return AT_AGE_REMOVE;
|
||||||
for (u = b->region->units; u; u = u->next) {
|
for (u = b->region->units; u; u = u->next) {
|
||||||
|
|
|
@ -135,9 +135,10 @@ static void shiptrail_finalize(attrib * a)
|
||||||
free(a->data.v);
|
free(a->data.v);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int shiptrail_age(attrib * a)
|
static int shiptrail_age(attrib * a, void *owner)
|
||||||
{
|
{
|
||||||
traveldir *t = (traveldir *)(a->data.v);
|
traveldir *t = (traveldir *)(a->data.v);
|
||||||
|
unused_arg(owner);
|
||||||
|
|
||||||
t->age--;
|
t->age--;
|
||||||
return (t->age > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
return (t->age > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
||||||
|
|
|
@ -287,9 +287,9 @@ static void test_age_trails(CuTest *tc) {
|
||||||
move_ship(sh, r1, r2, route);
|
move_ship(sh, r1, r2, route);
|
||||||
|
|
||||||
CuAssertPtrNotNull(tc, r1->attribs);
|
CuAssertPtrNotNull(tc, r1->attribs);
|
||||||
a_age(&r1->attribs);
|
a_age(&r1->attribs, r1);
|
||||||
CuAssertPtrNotNull(tc, r1->attribs);
|
CuAssertPtrNotNull(tc, r1->attribs);
|
||||||
a_age(&r1->attribs);
|
a_age(&r1->attribs, r1);
|
||||||
CuAssertPtrEquals(tc, 0, r1->attribs);
|
CuAssertPtrEquals(tc, 0, r1->attribs);
|
||||||
free_regionlist(route);
|
free_regionlist(route);
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
|
|
|
@ -42,7 +42,7 @@ static void test_good_dreams(CuTest *tc) {
|
||||||
CuAssertTrue(tc, curse && curse->duration > 1);
|
CuAssertTrue(tc, curse && curse->duration > 1);
|
||||||
CuAssertTrue(tc, curse->effect == 1);
|
CuAssertTrue(tc, curse->effect == 1);
|
||||||
|
|
||||||
a_age(&r->attribs);
|
a_age(&r->attribs, r);
|
||||||
CuAssertIntEquals_Msg(tc, "good dreams give +1 to allies", 1, get_modifier(u1, SK_MELEE, 11, r, false));
|
CuAssertIntEquals_Msg(tc, "good dreams give +1 to allies", 1, get_modifier(u1, SK_MELEE, 11, r, false));
|
||||||
CuAssertIntEquals_Msg(tc, "good dreams have no effect on non-allies", 0, get_modifier(u2, SK_MELEE, 11, r, false));
|
CuAssertIntEquals_Msg(tc, "good dreams have no effect on non-allies", 0, get_modifier(u2, SK_MELEE, 11, r, false));
|
||||||
free_castorder(&co);
|
free_castorder(&co);
|
||||||
|
@ -67,7 +67,7 @@ static void test_dreams(CuTest *tc) {
|
||||||
|
|
||||||
sp_gooddreams(&co);
|
sp_gooddreams(&co);
|
||||||
sp_baddreams(&co);
|
sp_baddreams(&co);
|
||||||
a_age(&r->attribs);
|
a_age(&r->attribs, r);
|
||||||
CuAssertIntEquals_Msg(tc, "good dreams in same region as bad dreams", 1, get_modifier(u1, SK_MELEE, 11, r, false));
|
CuAssertIntEquals_Msg(tc, "good dreams in same region as bad dreams", 1, get_modifier(u1, SK_MELEE, 11, r, false));
|
||||||
CuAssertIntEquals_Msg(tc, "bad dreams in same region as good dreams", -1, get_modifier(u2, SK_MELEE, 11, r, false));
|
CuAssertIntEquals_Msg(tc, "bad dreams in same region as good dreams", -1, get_modifier(u2, SK_MELEE, 11, r, false));
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ static void test_bad_dreams(CuTest *tc) {
|
||||||
CuAssertTrue(tc, curse && curse->duration > 1);
|
CuAssertTrue(tc, curse && curse->duration > 1);
|
||||||
CuAssertTrue(tc, curse->effect == -1);
|
CuAssertTrue(tc, curse->effect == -1);
|
||||||
|
|
||||||
a_age(&r->attribs);
|
a_age(&r->attribs, r);
|
||||||
CuAssertIntEquals_Msg(tc, "bad dreams have no effect on allies", 0, get_modifier(u1, SK_MELEE, 11, r, false));
|
CuAssertIntEquals_Msg(tc, "bad dreams have no effect on allies", 0, get_modifier(u1, SK_MELEE, 11, r, false));
|
||||||
CuAssertIntEquals_Msg(tc, "bad dreams give -1 to non-allies", -1, get_modifier(u2, SK_MELEE, 11, r, false));
|
CuAssertIntEquals_Msg(tc, "bad dreams give -1 to non-allies", -1, get_modifier(u2, SK_MELEE, 11, r, false));
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ extern const char *directions[];
|
||||||
|
|
||||||
typedef struct alp_data {
|
typedef struct alp_data {
|
||||||
unit *mage;
|
unit *mage;
|
||||||
unit *target;
|
unit *target; // TODO: remove, use attribute-owner?
|
||||||
} alp_data;
|
} alp_data;
|
||||||
|
|
||||||
static void alp_init(attrib * a)
|
static void alp_init(attrib * a)
|
||||||
|
@ -59,9 +59,10 @@ static void alp_done(attrib * a)
|
||||||
free(a->data.v);
|
free(a->data.v);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int alp_verify(attrib * a)
|
static int alp_verify(attrib * a, void *owner)
|
||||||
{
|
{
|
||||||
alp_data *ad = (alp_data *)a->data.v;
|
alp_data *ad = (alp_data *)a->data.v;
|
||||||
|
unused_arg(owner);
|
||||||
if (ad->mage && ad->target)
|
if (ad->mage && ad->target)
|
||||||
return 1;
|
return 1;
|
||||||
return 0; /* remove the attribute */
|
return 0; /* remove the attribute */
|
||||||
|
|
|
@ -252,7 +252,7 @@ attrib *a_new(const attrib_type * at)
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a_age(attrib ** p)
|
int a_age(attrib ** p, void *owner)
|
||||||
{
|
{
|
||||||
attrib **ap = p;
|
attrib **ap = p;
|
||||||
/* Attribute altern, und die Entfernung (age()==0) eines Attributs
|
/* Attribute altern, und die Entfernung (age()==0) eines Attributs
|
||||||
|
@ -260,7 +260,7 @@ int a_age(attrib ** p)
|
||||||
while (*ap) {
|
while (*ap) {
|
||||||
attrib *a = *ap;
|
attrib *a = *ap;
|
||||||
if (a->type->age) {
|
if (a->type->age) {
|
||||||
int result = a->type->age(a);
|
int result = a->type->age(a, owner);
|
||||||
assert(result >= 0 || !"age() returned a negative value");
|
assert(result >= 0 || !"age() returned a negative value");
|
||||||
if (result == AT_AGE_REMOVE) {
|
if (result == AT_AGE_REMOVE) {
|
||||||
a_remove(p, a);
|
a_remove(p, a);
|
||||||
|
|
|
@ -52,7 +52,7 @@ extern "C" {
|
||||||
const char *name;
|
const char *name;
|
||||||
void(*initialize) (struct attrib *);
|
void(*initialize) (struct attrib *);
|
||||||
void(*finalize) (struct attrib *);
|
void(*finalize) (struct attrib *);
|
||||||
int(*age) (struct attrib *);
|
int(*age) (struct attrib *, void *owner);
|
||||||
/* age returns 0 if the attribute needs to be removed, !=0 otherwise */
|
/* age returns 0 if the attribute needs to be removed, !=0 otherwise */
|
||||||
void(*write) (const struct attrib *, const void *owner, struct storage *);
|
void(*write) (const struct attrib *, const void *owner, struct storage *);
|
||||||
int(*read) (struct attrib *, void *owner, struct storage *); /* return AT_READ_OK on success, AT_READ_FAIL if attrib needs removal */
|
int(*read) (struct attrib *, void *owner, struct storage *); /* return AT_READ_OK on success, AT_READ_FAIL if attrib needs removal */
|
||||||
|
@ -74,7 +74,7 @@ extern "C" {
|
||||||
extern void a_removeall(attrib ** a, const attrib_type * at);
|
extern void a_removeall(attrib ** a, const attrib_type * at);
|
||||||
extern attrib *a_new(const attrib_type * at);
|
extern attrib *a_new(const attrib_type * at);
|
||||||
|
|
||||||
extern int a_age(attrib ** attribs);
|
extern int a_age(attrib ** attribs, void *owner);
|
||||||
extern int a_read(struct storage *store, attrib ** attribs, void *owner);
|
extern int a_read(struct storage *store, attrib ** attribs, void *owner);
|
||||||
extern void a_write(struct storage *store, const attrib * attribs,
|
extern void a_write(struct storage *store, const attrib * attribs,
|
||||||
const void *owner);
|
const void *owner);
|
||||||
|
|
|
@ -66,9 +66,10 @@ static void a_freedirection(attrib * a)
|
||||||
free(d);
|
free(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int a_agedirection(attrib * a)
|
static int a_agedirection(attrib * a, void *owner)
|
||||||
{
|
{
|
||||||
spec_direction *d = (spec_direction *)(a->data.v);
|
spec_direction *d = (spec_direction *)(a->data.v);
|
||||||
|
unused_arg(owner);
|
||||||
--d->duration;
|
--d->duration;
|
||||||
return (d->duration > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
return (d->duration > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
||||||
}
|
}
|
||||||
|
@ -78,7 +79,7 @@ static int a_readdirection(attrib * a, void *owner, struct storage *store)
|
||||||
spec_direction *d = (spec_direction *)(a->data.v);
|
spec_direction *d = (spec_direction *)(a->data.v);
|
||||||
char lbuf[32];
|
char lbuf[32];
|
||||||
|
|
||||||
(void)owner;
|
unused_arg(owner);
|
||||||
READ_INT(store, &d->x);
|
READ_INT(store, &d->x);
|
||||||
READ_INT(store, &d->y);
|
READ_INT(store, &d->y);
|
||||||
READ_INT(store, &d->duration);
|
READ_INT(store, &d->duration);
|
||||||
|
@ -95,7 +96,7 @@ a_writedirection(const attrib * a, const void *owner, struct storage *store)
|
||||||
{
|
{
|
||||||
spec_direction *d = (spec_direction *)(a->data.v);
|
spec_direction *d = (spec_direction *)(a->data.v);
|
||||||
|
|
||||||
(void)owner;
|
unused_arg(owner);
|
||||||
WRITE_INT(store, d->x);
|
WRITE_INT(store, d->x);
|
||||||
WRITE_INT(store, d->y);
|
WRITE_INT(store, d->y);
|
||||||
WRITE_INT(store, d->duration);
|
WRITE_INT(store, d->duration);
|
||||||
|
|
|
@ -56,7 +56,7 @@ static int cmp_age(const void *v1, const void *v2)
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct wormhole_data {
|
typedef struct wormhole_data {
|
||||||
building *entry;
|
building *entry; // TODO: remove, use attribute-owner
|
||||||
region *exit;
|
region *exit;
|
||||||
} wormhole_data;
|
} wormhole_data;
|
||||||
|
|
||||||
|
@ -70,13 +70,14 @@ static void wormhole_done(struct attrib *a)
|
||||||
free(a->data.v);
|
free(a->data.v);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int wormhole_age(struct attrib *a)
|
static int wormhole_age(struct attrib *a, void *owner)
|
||||||
{
|
{
|
||||||
wormhole_data *data = (wormhole_data *)a->data.v;
|
wormhole_data *data = (wormhole_data *)a->data.v;
|
||||||
int maxtransport = data->entry->size;
|
int maxtransport = data->entry->size;
|
||||||
region *r = data->entry->region;
|
region *r = data->entry->region;
|
||||||
unit *u = r->units;
|
unit *u = r->units;
|
||||||
|
|
||||||
|
unused_arg(owner);
|
||||||
for (; u != NULL && maxtransport != 0; u = u->next) {
|
for (; u != NULL && maxtransport != 0; u = u->next) {
|
||||||
if (u->building == data->entry) {
|
if (u->building == data->entry) {
|
||||||
message *m = NULL;
|
message *m = NULL;
|
||||||
|
|
Loading…
Reference in a new issue