Merge branch 'master' of github.com:badgerman/eressea

This commit is contained in:
Enno Rehling 2014-10-18 19:57:50 +02:00
commit 78db167802
8 changed files with 549 additions and 556 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2014, Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
@ -251,7 +251,7 @@ extern "C" {
bool is_cursed_internal(struct attrib *ap, const curse_type * ctype); bool is_cursed_internal(struct attrib *ap, const curse_type * ctype);
/* ignoriert CURSE_ISNEW */ /* ignoriert CURSE_ISNEW */
extern void remove_curse(struct attrib **ap, const struct curse *c); bool remove_curse(struct attrib **ap, const struct curse *c);
/* löscht einen konkreten Spruch auf einem Objekt. /* löscht einen konkreten Spruch auf einem Objekt.
*/ */
@ -280,11 +280,6 @@ extern "C" {
* unterschiedlich gewünscht sein * unterschiedlich gewünscht sein
* */ * */
extern struct curse *get_cursex(struct attrib *ap, const curse_type * ctype,
variant data, bool(*compare) (const struct curse *, variant));
/* gibt pointer auf die erste curse-struct zurück, deren Typ ctype ist,
* und für die compare() true liefert, oder einen NULL-pointer.
* */
extern struct curse *get_curse(struct attrib *ap, const curse_type * ctype); extern struct curse *get_curse(struct attrib *ap, const curse_type * ctype);
/* gibt pointer auf die erste curse-struct zurück, deren Typ ctype ist, /* gibt pointer auf die erste curse-struct zurück, deren Typ ctype ist,
* oder einen NULL-pointer * oder einen NULL-pointer
@ -303,9 +298,6 @@ extern "C" {
extern void curse_done(struct attrib *a); extern void curse_done(struct attrib *a);
extern int curse_age(struct attrib *a); extern int curse_age(struct attrib *a);
extern bool cmp_curse(const struct attrib *a, const void *data);
extern bool cmp_cursetype(const struct attrib *a, const void *data);
extern float destr_curse(struct curse *c, int cast_level, float force); extern float destr_curse(struct curse *c, int cast_level, float force);
extern int resolve_curse(variant data, void *address); extern int resolve_curse(variant data, void *address);

View File

@ -1313,7 +1313,6 @@ faction *readfaction(struct gamedata * data)
f->flags = FFL_NPC | FFL_NOIDLEOUT; f->flags = FFL_NPC | FFL_NOIDLEOUT;
} }
} }
assert((f->flags&FFL_SAVEMASK) == f->flags);
a_read(data->store, &f->attribs, f); a_read(data->store, &f->attribs, f);
if (data->version >= CLAIM_VERSION) { if (data->version >= CLAIM_VERSION) {

View File

@ -35,16 +35,6 @@
/* util includes */ /* util includes */
#include <util/attrib.h> #include <util/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <util/goodies.h>
#include <util/language.h>
#include <util/lists.h>
#include <util/log.h>
#include <util/umlaut.h>
#include <util/parser.h>
#include <util/rng.h>
#include <storage.h> #include <storage.h>
/* libc includes */ /* libc includes */
@ -56,18 +46,11 @@
static int read_permissions(attrib * a, void *owner, struct storage *store) static int read_permissions(attrib * a, void *owner, struct storage *store)
{ {
attrib *attr = NULL; attrib *attr = NULL;
a_read(store, &attr, NULL); a_read(store, &attr, owner);
a_free(attr); a_remove(&attr, a);
return AT_READ_OK; return AT_READ_OK;
} }
struct attrib_type at_permissions = {
"GM:permissions",
NULL, NULL, NULL,
NULL, read_permissions,
ATF_UNIQUE
};
static int read_gmcreate(attrib * a, void *owner, struct storage *store) static int read_gmcreate(attrib * a, void *owner, struct storage *store)
{ {
char zText[32]; char zText[32];
@ -75,15 +58,8 @@ static int read_gmcreate(attrib * a, void *owner, struct storage *store)
return AT_READ_OK; return AT_READ_OK;
} }
/* at_gmcreate specifies that the owner can create items of a particular type */
attrib_type at_gmcreate = {
"GM:create",
NULL, NULL, NULL,
NULL, read_gmcreate
};
void register_gmcmd(void) void register_gmcmd(void)
{ {
at_register(&at_gmcreate); at_deprecate("GM:create", read_gmcreate);
at_register(&at_permissions); at_deprecate("GM:permissions", read_permissions);
} }

View File

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2014, Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -41,68 +41,66 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <stdio.h> #include <stdio.h>
typedef struct removecurse_data { typedef struct removecurse_data {
curse *curse; curse *curse;
unit *target; unit *target;
} removecurse_data; } removecurse_data;
static void removecurse_init(trigger * t) static void removecurse_init(trigger * t)
{ {
t->data.v = calloc(sizeof(removecurse_data), 1); t->data.v = calloc(sizeof(removecurse_data), 1);
} }
static void removecurse_free(trigger * t) static void removecurse_free(trigger * t)
{ {
free(t->data.v); free(t->data.v);
} }
static int removecurse_handle(trigger * t, void *data) static int removecurse_handle(trigger * t, void *data)
{ {
/* call an event handler on removecurse. /* call an event handler on removecurse.
* data.v -> ( variant event, int timer ) * data.v -> ( variant event, int timer )
*/ */
removecurse_data *td = (removecurse_data *) t->data.v; removecurse_data *td = (removecurse_data *)t->data.v;
if (td->curse && td->target) { if (td->curse && td->target) {
attrib *a = a_select(td->target->attribs, td->curse, cmp_curse); if (!remove_curse(&td->target->attribs, td->curse)) {
if (a) { log_error("could not perform removecurse::handle()\n");
a_remove(&td->target->attribs, a); }
} else }
log_error("could not perform removecurse::handle()\n"); unused_arg(data);
} return 0;
unused_arg(data);
return 0;
} }
static void removecurse_write(const trigger * t, struct storage *store) static void removecurse_write(const trigger * t, struct storage *store)
{ {
removecurse_data *td = (removecurse_data *) t->data.v; removecurse_data *td = (removecurse_data *)t->data.v;
WRITE_TOK(store, td->target ? itoa36(td->target->no) : 0); WRITE_TOK(store, td->target ? itoa36(td->target->no) : 0);
WRITE_INT(store, td->curse ? td->curse->no : 0); WRITE_INT(store, td->curse ? td->curse->no : 0);
} }
static int removecurse_read(trigger * t, struct storage *store) static int removecurse_read(trigger * t, struct storage *store)
{ {
removecurse_data *td = (removecurse_data *) t->data.v; removecurse_data *td = (removecurse_data *)t->data.v;
read_reference(&td->target, store, read_unit_reference, resolve_unit); read_reference(&td->target, store, read_unit_reference, resolve_unit);
read_reference(&td->curse, store, read_int, resolve_curse); read_reference(&td->curse, store, read_int, resolve_curse);
return AT_READ_OK; return AT_READ_OK;
} }
trigger_type tt_removecurse = { trigger_type tt_removecurse = {
"removecurse", "removecurse",
removecurse_init, removecurse_init,
removecurse_free, removecurse_free,
removecurse_handle, removecurse_handle,
removecurse_write, removecurse_write,
removecurse_read removecurse_read
}; };
trigger *trigger_removecurse(curse * c, unit * target) trigger *trigger_removecurse(curse * c, unit * target)
{ {
trigger *t = t_new(&tt_removecurse); trigger *t = t_new(&tt_removecurse);
removecurse_data *td = (removecurse_data *) t->data.v; removecurse_data *td = (removecurse_data *)t->data.v;
td->curse = c; td->curse = c;
td->target = target; td->target = target;
return t; return t;
} }

View File

@ -151,14 +151,6 @@ attrib *a_add(attrib ** pa, attrib * a)
return a; return a;
} }
void a_free(attrib * a)
{
const attrib_type *at = a->type;
if (at->finalize)
at->finalize(a);
free(a);
}
static int a_unlink(attrib ** pa, attrib * a) static int a_unlink(attrib ** pa, attrib * a)
{ {
attrib **pnexttype = pa; attrib **pnexttype = pa;
@ -197,6 +189,14 @@ static int a_unlink(attrib ** pa, attrib * a)
return 0; return 0;
} }
static void a_free(attrib * a)
{
const attrib_type *at = a->type;
if (at->finalize)
at->finalize(a);
free(a);
}
int a_remove(attrib ** pa, attrib * a) int a_remove(attrib ** pa, attrib * a)
{ {
int ok; int ok;

View File

@ -73,7 +73,6 @@ extern "C" {
extern int a_remove(attrib ** pa, attrib * at); extern int a_remove(attrib ** pa, attrib * at);
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 void a_free(attrib * a);
extern int a_age(attrib ** attribs); extern int a_age(attrib ** attribs);
extern int a_read(struct storage *store, attrib ** attribs, void *owner); extern int a_read(struct storage *store, attrib ** attribs, void *owner);

View File

@ -12,6 +12,8 @@ static void test_attrib_new(CuTest * tc)
CuAssertPtrEquals(tc, 0, a->next); CuAssertPtrEquals(tc, 0, a->next);
CuAssertPtrEquals(tc, 0, a->nexttype); CuAssertPtrEquals(tc, 0, a->nexttype);
CuAssertPtrEquals(tc, (void *)a->type, (void *)&at_test); CuAssertPtrEquals(tc, (void *)a->type, (void *)&at_test);
a_remove(&a, a);
CuAssertPtrEquals(tc, 0, a);
} }
@ -20,18 +22,55 @@ static void test_attrib_add(CuTest * tc)
attrib_type at_foo = { "foo" }; attrib_type at_foo = { "foo" };
attrib_type at_bar = { "bar" }; attrib_type at_bar = { "bar" };
attrib *a, *alist = 0; attrib *a, *alist = 0;
CuAssertPtrNotNull(tc, (a = a_new(&at_foo))); CuAssertPtrNotNull(tc, (a = a_new(&at_foo)));
CuAssertPtrEquals(tc, a, a_add(&alist, a)); CuAssertPtrEquals(tc, a, a_add(&alist, a));
CuAssertPtrEquals(tc, a, alist); CuAssertPtrEquals(tc, a, alist);
CuAssertPtrEquals(tc, 0, alist->nexttype);
CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_foo)))); CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_foo))));
CuAssertPtrEquals(tc, alist->next, a); CuAssertPtrEquals_Msg(tc, "new attribute not added after existing", alist->next, a);
CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_bar))));
CuAssertPtrEquals_Msg(tc, "new atribute not added at end of list", alist->next->next, a);
CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_foo))));
CuAssertPtrEquals_Msg(tc, "messages not sorted by type", alist->next->next, a);
a_removeall(&alist, &at_foo);
a_removeall(&alist, &at_bar);
}
static void test_attrib_remove(CuTest * tc)
{
attrib_type at_foo = { "foo" };
attrib *a, *alist = 0;
CuAssertPtrNotNull(tc, a_add(&alist, a_new(&at_foo)));
CuAssertPtrNotNull(tc, a = a_add(&alist, a_new(&at_foo)));
CuAssertIntEquals(tc, 1, a_remove(&alist, a));
CuAssertPtrNotNull(tc, alist);
CuAssertIntEquals(tc, 1, a_remove(&alist, alist));
CuAssertPtrEquals(tc, 0, alist);
}
static void test_attrib_nexttype(CuTest * tc)
{
attrib_type at_foo = { "foo" };
attrib_type at_bar = { "bar" };
attrib *a, *alist = 0;
CuAssertPtrNotNull(tc, (a = a_new(&at_foo)));
CuAssertPtrEquals(tc, 0, a->nexttype);
CuAssertPtrEquals(tc, a, a_add(&alist, a));
CuAssertPtrEquals(tc, 0, alist->nexttype);
CuAssertPtrNotNull(tc, a_add(&alist, a_new(&at_foo)));
CuAssertPtrEquals(tc, 0, alist->nexttype); CuAssertPtrEquals(tc, 0, alist->nexttype);
CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_bar)))); CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_bar))));
CuAssertPtrEquals(tc, alist->next->next, a);
CuAssertPtrEquals(tc, a, alist->nexttype); CuAssertPtrEquals(tc, a, alist->nexttype);
CuAssertPtrEquals(tc, 0, a->nexttype);
a_removeall(&alist, &at_foo);
a_removeall(&alist, &at_bar);
} }
CuSuite *get_attrib_suite(void) CuSuite *get_attrib_suite(void)
@ -39,5 +78,7 @@ CuSuite *get_attrib_suite(void)
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_attrib_new); SUITE_ADD_TEST(suite, test_attrib_new);
SUITE_ADD_TEST(suite, test_attrib_add); SUITE_ADD_TEST(suite, test_attrib_add);
SUITE_ADD_TEST(suite, test_attrib_remove);
SUITE_ADD_TEST(suite, test_attrib_nexttype);
return suite; return suite;
} }