refactor and kill dead code.

indentation normalization, copyright update.
This commit is contained in:
Enno Rehling 2014-10-18 18:37:44 +02:00
parent a58afb9d15
commit 5626abd8dc
3 changed files with 493 additions and 515 deletions

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
@ -115,7 +115,7 @@ void curse_init(attrib * a)
int curse_age(attrib * a) int curse_age(attrib * a)
{ {
curse *c = (curse *) a->data.v; curse *c = (curse *)a->data.v;
int result = 0; int result = 0;
if (c_flags(c) & CURSE_NOAGE) { if (c_flags(c) & CURSE_NOAGE) {
@ -126,7 +126,8 @@ int curse_age(attrib * a)
} }
if (result != 0) { if (result != 0) {
c->duration = 0; c->duration = 0;
} else if (c->duration != INT_MAX) { }
else if (c->duration != INT_MAX) {
c->duration = _max(0, c->duration - 1); c->duration = _max(0, c->duration - 1);
} }
return c->duration; return c->duration;
@ -140,7 +141,7 @@ void destroy_curse(curse * c)
void curse_done(attrib * a) void curse_done(attrib * a)
{ {
destroy_curse((curse *) a->data.v); destroy_curse((curse *)a->data.v);
} }
/** reads curses that have been removed from the code */ /** reads curses that have been removed from the code */
@ -150,9 +151,9 @@ static int read_ccompat(const char *cursename, struct storage *store)
const char *name; const char *name;
const char *tokens; const char *tokens;
} *seek, old_curses[] = { { } *seek, old_curses[] = { {
"disorientationzone", ""}, { "disorientationzone", "" }, {
"shipdisorientation", ""}, { "shipdisorientation", "" }, {
NULL, NULL}}; NULL, NULL } };
for (seek = old_curses; seek->name; ++seek) { for (seek = old_curses; seek->name; ++seek) {
if (strcmp(seek->tokens, cursename) == 0) { if (strcmp(seek->tokens, cursename) == 0) {
const char *p; const char *p;
@ -183,7 +184,7 @@ static int read_ccompat(const char *cursename, struct storage *store)
int curse_read(attrib * a, void *owner, struct storage *store) int curse_read(attrib * a, void *owner, struct storage *store)
{ {
curse *c = (curse *) a->data.v; curse *c = (curse *)a->data.v;
int ur; int ur;
char cursename[64]; char cursename[64];
int n; int n;
@ -198,19 +199,22 @@ int curse_read(attrib * a, void *owner, struct storage *store)
if (global.data_version >= CURSEVIGOURISFLOAT_VERSION) { if (global.data_version >= CURSEVIGOURISFLOAT_VERSION) {
READ_FLT(store, &flt); READ_FLT(store, &flt);
c->vigour = flt; c->vigour = flt;
} else { }
else {
READ_INT(store, &n); READ_INT(store, &n);
c->vigour = (float)n; c->vigour = (float)n;
} }
if (global.data_version < INTPAK_VERSION) { if (global.data_version < INTPAK_VERSION) {
ur = read_reference(&c->magician, store, read_int, resolve_unit); ur = read_reference(&c->magician, store, read_int, resolve_unit);
} else { }
else {
ur = read_reference(&c->magician, store, read_unit_reference, resolve_unit); ur = read_reference(&c->magician, store, read_unit_reference, resolve_unit);
} }
if (global.data_version < CURSEFLOAT_VERSION) { if (global.data_version < CURSEFLOAT_VERSION) {
READ_INT(store, &n); READ_INT(store, &n);
c->effect = (float)n; c->effect = (float)n;
} else { }
else {
READ_FLT(store, &flt); READ_FLT(store, &flt);
c->effect = flt; c->effect = flt;
} }
@ -225,7 +229,8 @@ int curse_read(attrib * a, void *owner, struct storage *store)
} }
if (global.data_version < CURSEFLAGS_VERSION) { if (global.data_version < CURSEFLAGS_VERSION) {
c_setflag(c, flags); c_setflag(c, flags);
} else { }
else {
c->flags = flags; c->flags = flags;
} }
c_clearflag(c, CURSE_ISNEW); c_clearflag(c, CURSE_ISNEW);
@ -250,7 +255,7 @@ int curse_read(attrib * a, void *owner, struct storage *store)
void curse_write(const attrib * a, const void *owner, struct storage *store) void curse_write(const attrib * a, const void *owner, struct storage *store)
{ {
unsigned int flags; unsigned int flags;
curse *c = (curse *) a->data.v; curse *c = (curse *)a->data.v;
const curse_type *ct = c->type; const curse_type *ct = c->type;
unit *mage = (c->magician && c->magician->number) ? c->magician : NULL; unit *mage = (c->magician && c->magician->number) ? c->magician : NULL;
@ -271,7 +276,7 @@ void curse_write(const attrib * a, const void *owner, struct storage *store)
WRITE_INT(store, c->data.i); WRITE_INT(store, c->data.i);
} }
if (c->type->typ == CURSETYP_REGION) { if (c->type->typ == CURSETYP_REGION) {
write_region_reference((region *) c->data.v, store); write_region_reference((region *)c->data.v, store);
} }
} }
@ -308,11 +313,12 @@ const curse_type *ct_find(const char *c)
int qi; int qi;
for (qi = 0; ctl; ql_advance(&ctl, &qi, 1)) { for (qi = 0; ctl; ql_advance(&ctl, &qi, 1)) {
curse_type *type = (curse_type *) ql_get(ctl, qi); curse_type *type = (curse_type *)ql_get(ctl, qi);
if (strcmp(c, type->cname) == 0) { if (strcmp(c, type->cname) == 0) {
return type; return type;
} else { }
else {
size_t k = _min(strlen(c), strlen(type->cname)); size_t k = _min(strlen(c), strlen(type->cname));
if (!_memicmp(c, type->cname, k)) { if (!_memicmp(c, type->cname, k)) {
return type; return type;
@ -327,39 +333,16 @@ const curse_type *ct_find(const char *c)
* einen pointer auf die struct zurück. * einen pointer auf die struct zurück.
*/ */
bool cmp_curse(const attrib * a, const void *data) static bool cmp_curse(const attrib * a, const void *data)
{ {
const curse *c = (const curse *)data; const curse *c = (const curse *)data;
if (a->type->flags & ATF_CURSE) { if (a->type->flags & ATF_CURSE) {
if (!data || c == (curse *) a->data.v) if (!data || c == (curse *)a->data.v)
return true; return true;
} }
return false; return false;
} }
bool cmp_cursetype(const attrib * a, const void *data)
{
const curse_type *ct = (const curse_type *)data;
if (a->type->flags & ATF_CURSE) {
if (!data || ct == ((curse *) a->data.v)->type)
return true;
}
return false;
}
curse *get_cursex(attrib * ap, const curse_type * ctype, variant data,
bool(*compare) (const curse *, variant))
{
attrib *a = a_select(ap, ctype, cmp_cursetype);
while (a) {
curse *c = (curse *) a->data.v;
if (compare(c, data))
return c;
a = a_select(a->next, ctype, cmp_cursetype);
}
return NULL;
}
curse *get_curse(attrib * ap, const curse_type * ctype) curse *get_curse(attrib * ap, const curse_type * ctype)
{ {
attrib *a = ap; attrib *a = ap;
@ -367,12 +350,13 @@ curse *get_curse(attrib * ap, const curse_type * ctype)
if (a->type->flags & ATF_CURSE) { if (a->type->flags & ATF_CURSE) {
const attrib_type *at = a->type; const attrib_type *at = a->type;
while (a && a->type == at) { while (a && a->type == at) {
curse *c = (curse *) a->data.v; curse *c = (curse *)a->data.v;
if (c->type == ctype) if (c->type == ctype)
return c; return c;
a = a->next; a = a->next;
} }
} else { }
else {
a = a->nexttype; a = a->nexttype;
} }
} }
@ -388,11 +372,10 @@ curse *findcurse(int cid)
} }
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
void remove_curse(attrib ** ap, const curse * c) bool remove_curse(attrib ** ap, const curse * c)
{ {
attrib *a = a_select(*ap, c, cmp_curse); attrib *a = a_select(*ap, c, cmp_curse);
if (a) return a && a_remove(ap, a) == 1;
a_remove(ap, a);
} }
/* gibt die allgemeine Stärke der Verzauberung zurück. id2 wird wie /* gibt die allgemeine Stärke der Verzauberung zurück. id2 wird wie
@ -423,7 +406,8 @@ float curse_changevigour(attrib ** ap, curse * c, float vigour)
if (vigour <= 0) { if (vigour <= 0) {
remove_curse(ap, c); remove_curse(ap, c);
vigour = 0; vigour = 0;
} else { }
else {
set_cursevigour(c, vigour); set_cursevigour(c, vigour);
} }
return vigour; return vigour;
@ -453,7 +437,7 @@ int curse_geteffect_int(const curse * c)
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
static void static void
set_curseingmagician(struct unit *magician, struct attrib *ap_target, set_curseingmagician(struct unit *magician, struct attrib *ap_target,
const curse_type * ct) const curse_type * ct)
{ {
curse *c = get_curse(ap_target, ct); curse *c = get_curse(ap_target, ct);
if (c) { if (c) {
@ -503,7 +487,7 @@ static curse *make_curse(unit * mage, attrib ** ap, const curse_type * ct,
a = a_new(&at_curse); a = a_new(&at_curse);
a_add(ap, a); a_add(ap, a);
c = (curse *) a->data.v; c = (curse *)a->data.v;
c->type = ct; c->type = ct;
c->flags = 0; c->flags = 0;
@ -576,7 +560,8 @@ curse *create_curse(unit * magician, attrib ** ap, const curse_type * ct,
} }
} }
set_curseingmagician(magician, *ap, ct); set_curseingmagician(magician, *ap, ct);
} else { }
else {
c = make_curse(magician, ap, ct, vigour, duration, effect, men); c = make_curse(magician, ap, ct, vigour, duration, effect, men);
} }
return c; return c;
@ -639,7 +624,7 @@ void transfer_curse(unit * u, unit * u2, int n)
a = a_find(u->attribs, &at_curse); a = a_find(u->attribs, &at_curse);
while (a && a->type == &at_curse) { while (a && a->type == &at_curse) {
curse *c = (curse *) a->data.v; curse *c = (curse *)a->data.v;
do_transfer_curse(c, u, u2, n); do_transfer_curse(c, u, u2, n);
a = a->next; a = a->next;
} }
@ -709,7 +694,7 @@ int resolve_curse(variant id, void *address)
result = -1; result = -1;
} }
} }
*(curse **) address = c; *(curse **)address = c;
return result; return result;
} }
@ -798,16 +783,19 @@ float destr_curse(curse * c, int cast_level, float force)
force -= c->vigour; force -= c->vigour;
if (c->type->change_vigour) { if (c->type->change_vigour) {
c->type->change_vigour(c, -((float)cast_level + 1) / 2); c->type->change_vigour(c, -((float)cast_level + 1) / 2);
} else { }
else {
c->vigour -= cast_level + 1 / 2; c->vigour -= cast_level + 1 / 2;
} }
} }
} else { /* Zauber ist stärker als curse */ }
else { /* Zauber ist stärker als curse */
if (force >= c->vigour) { /* reicht die Kraft noch aus? */ if (force >= c->vigour) { /* reicht die Kraft noch aus? */
force -= c->vigour; force -= c->vigour;
if (c->type->change_vigour) { if (c->type->change_vigour) {
c->type->change_vigour(c, -c->vigour); c->type->change_vigour(c, -c->vigour);
} else { }
else {
c->vigour = 0; c->vigour = 0;
} }

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

@ -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
@ -60,28 +60,26 @@ 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) {
a_remove(&td->target->attribs, a);
} else
log_error("could not perform removecurse::handle()\n"); log_error("could not perform removecurse::handle()\n");
} }
}
unused_arg(data); unused_arg(data);
return 0; 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);
@ -101,7 +99,7 @@ trigger_type tt_removecurse = {
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;