From da224f6670a91f22c043f302fc8eeae73b45a88f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 7 Mar 2007 22:38:04 +0000 Subject: [PATCH] Cleanup in cinfo_ code, although I would prefer that it doesn't write into buf but returns a message *. sometime later. --- src/common/gamecode/creport.c | 3 +-- src/common/gamecode/report.c | 11 ++--------- src/common/kernel/curse.c | 2 +- src/common/kernel/curse.h | 7 +++---- src/common/kernel/eressea.h | 1 + src/common/kernel/reports.c | 19 +++++++++++++++++++ src/common/kernel/reports.h | 2 ++ src/common/spells/buildingcurse.c | 4 ++-- src/common/spells/regioncurse.c | 26 +++++++++++++------------- src/common/spells/shipcurse.c | 6 +++--- src/common/spells/shipcurse.h | 2 +- src/common/spells/unitcurse.c | 18 +++++++++--------- src/common/spells/unitcurse.h | 2 +- 13 files changed, 58 insertions(+), 45 deletions(-) diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index 9a56f7e53..740df25dd 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -250,13 +250,12 @@ print_curses(FILE * F, const faction * viewer, const void * obj, typ_t typ) self = c->type->cansee(viewer, obj, typ, c, self); } dh = c->type->curseinfo(viewer->locale, obj, typ, c, self); - } else { - log_error(("no curseinfo for %s\n", c->type->cname)); } if (dh==0) { if (c->type->info_str!=NULL) { sprintf(buf, "%s (%s)", c->type->info_str, itoa36(c->no)); } else { + log_error(("no curseinfo for %s\n", c->type->cname)); sprintf(buf, "an unknown curse lies on the region. (%s)", itoa36(c->no)); } } else { diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index 81fa2e87f..02951cbd7 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -467,7 +467,7 @@ print_curses(FILE *F, const faction *viewer, const void * obj, typ_t typ, int in unit * owner; a = b->attribs; r = b->region; - if((owner = buildingowner(r,b)) != NULL){ + if ((owner = buildingowner(r,b)) != NULL){ if (owner->faction == viewer){ self = 2; } else { /* steht eine Person der Partei in der Burg? */ @@ -495,17 +495,10 @@ print_curses(FILE *F, const faction *viewer, const void * obj, typ_t typ, int in } for(;a;a=a->next) { - int dh = 0; if (fval(a->type, ATF_CURSE)) { curse *c = (curse *)a->data.v; - if (c->type->curseinfo) { - if (c->type->cansee) { - self = c->type->cansee(viewer, obj, typ, c, self); - } - dh = c->type->curseinfo(viewer->locale, obj, typ, c, self); - } - if (dh == 1) { + if (print_curse(c, viewer, obj, typ, self)) { rnl(F); rparagraph(F, buf, indent, 2, 0); } diff --git a/src/common/kernel/curse.c b/src/common/kernel/curse.c index fec6ed917..3e12a2354 100644 --- a/src/common/kernel/curse.c +++ b/src/common/kernel/curse.c @@ -737,7 +737,7 @@ oldcursename(int id) /* ------------------------------------------------------------- */ int -cinfo_simple(const struct locale * lang, const void * obj, typ_t typ, struct curse *c, int self) +cinfo_simple(const struct locale * lang, const void * obj, typ_t typ, const struct curse *c, int self) { struct message * msg; diff --git a/src/common/kernel/curse.h b/src/common/kernel/curse.h index 79b86717e..b8058b693 100644 --- a/src/common/kernel/curse.h +++ b/src/common/kernel/curse.h @@ -222,15 +222,14 @@ typedef struct curse_type { unsigned int mergeflags; const char *info_str; /* Wirkung des curse, wird bei einer gelungenen Zauberanalyse angezeigt */ - int (*curseinfo)(const struct locale*, const void*, typ_t, curse*, int); + int (*curseinfo)(const struct locale*, const void*, typ_t, const curse*, int); void (*change_vigour)(curse*, double); int (*read)(FILE * F, curse * c); int (*write)(FILE * F, const curse * c); - int (*cansee)(const struct faction*, const void*, typ_t, curse *, int); + int (*cansee)(const struct faction*, const void*, typ_t, const curse *, int); int (*age)(curse *); } curse_type; - extern attrib_type at_curse; extern void curse_write(const attrib * a,FILE * f); extern int curse_read(struct attrib * a,FILE * f); @@ -326,7 +325,7 @@ extern boolean curse_active(const curse * c); /*** COMPATIBILITY MACROS. DO NOT USE FOR NEW CODE, REPLACE IN OLD CODE: */ extern const char * oldcursename(int id); extern void register_curses(void); -extern int cinfo_simple(const struct locale * lang, const void * obj, typ_t typ, struct curse *c, int self); +extern int cinfo_simple(const struct locale * lang, const void * obj, typ_t typ, const struct curse *c, int self); #define is_cursed(a, id, id2) \ curse_active(get_curse(a, ct_find(oldcursename(id)))) diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index ce8591867..318394cf2 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -68,6 +68,7 @@ struct plane; struct order; struct spell; struct region; +struct curse; struct fighter; struct region_list; struct race; diff --git a/src/common/kernel/reports.c b/src/common/kernel/reports.c index 269954f1f..fded06910 100644 --- a/src/common/kernel/reports.c +++ b/src/common/kernel/reports.c @@ -22,6 +22,7 @@ #include "reports.h" /* kernel includes */ +#include #include #include #include @@ -808,6 +809,24 @@ spunit(struct strlist ** SP, const struct faction * f, const unit * u, int inden lparagraph(SP, buf, indent, (char) ((u->faction == f) ? '*' : (dh ? '+' : '-'))); } +int +print_curse(const struct curse * c, const struct faction * viewer, const void * obj, typ_t typ, int self) +{ + if (c->type->curseinfo) { + if (c->type->cansee) { + self = c->type->cansee(viewer, obj, typ, c, self); + } + return c->type->curseinfo(viewer->locale, obj, typ, c, self); + } else { + if (c->type->info_str!=NULL) { + sprintf(buf, "%s (%s)", c->type->info_str, itoa36(c->no)); + return 1; + } + } + log_error(("no curseinfo for %s\n", c->type->cname)); + return 0; +} + const struct unit * ucansee(const struct faction *f, const struct unit *u, const struct unit *x) { diff --git a/src/common/kernel/reports.h b/src/common/kernel/reports.h index 2befafe71..073861e4e 100644 --- a/src/common/kernel/reports.h +++ b/src/common/kernel/reports.h @@ -110,6 +110,8 @@ extern const char * report_kampfstatus(const struct unit * u, const struct local extern int update_nmrs(void); extern int * nmrs; + extern int print_curse(const struct curse * c, const struct faction * viewer, const void * obj, typ_t typ, int self); + #ifdef __cplusplus } #endif diff --git a/src/common/spells/buildingcurse.c b/src/common/spells/buildingcurse.c index cf2e5b3a0..28d4aefcf 100644 --- a/src/common/spells/buildingcurse.c +++ b/src/common/spells/buildingcurse.c @@ -34,7 +34,7 @@ static int -cinfo_building(const struct locale * lang, const void * obj, typ_t typ, curse *c, int self) +cinfo_building(const struct locale * lang, const void * obj, typ_t typ, const curse *c, int self) { message * msg; @@ -59,7 +59,7 @@ cinfo_building(const struct locale * lang, const void * obj, typ_t typ, curse *c /* C_MAGICWALLS*/ static int -cinfo_magicrunes(const struct locale* lang, const void * obj, typ_t typ, curse *c, int self) +cinfo_magicrunes(const struct locale* lang, const void * obj, typ_t typ, const curse *c, int self) { message * msg = NULL; if (typ == TYP_BUILDING){ diff --git a/src/common/spells/regioncurse.c b/src/common/spells/regioncurse.c index 220caa12e..15fd94e63 100644 --- a/src/common/spells/regioncurse.c +++ b/src/common/spells/regioncurse.c @@ -42,7 +42,7 @@ * godcursezone */ static int -cinfo_cursed_by_the_gods(const struct locale * lang, const void * obj, typ_t typ, curse *c, int self) +cinfo_cursed_by_the_gods(const struct locale * lang, const void * obj, typ_t typ, const curse *c, int self) { region *r; message * msg; @@ -82,7 +82,7 @@ static struct curse_type ct_godcursezone = { * C_GBDREAM */ static int -cinfo_dreamcurse(const struct locale * lang, const void * obj, typ_t typ, curse *c, int self) +cinfo_dreamcurse(const struct locale * lang, const void * obj, typ_t typ, const curse *c, int self) { message * msg; @@ -91,7 +91,7 @@ cinfo_dreamcurse(const struct locale * lang, const void * obj, typ_t typ, curse unused(obj); assert(typ == TYP_REGION); - if (curse_geteffect(c) > 0){ + if (curse_geteffect(c) > 0) { msg = msg_message("curseinfo::gooddream", "id", c->no); } else { msg = msg_message("curseinfo::baddream", "id", c->no); @@ -117,7 +117,7 @@ static struct curse_type ct_gbdream = { * erzeugt Straßennetz */ static int -cinfo_magicstreet(const struct locale * lang, const void * obj, typ_t typ, curse *c, int self) +cinfo_magicstreet(const struct locale * lang, const void * obj, typ_t typ, const curse *c, int self) { message * msg; @@ -128,7 +128,7 @@ cinfo_magicstreet(const struct locale * lang, const void * obj, typ_t typ, curse assert(typ == TYP_REGION); /* Warnung vor Auflösung */ - if (c->duration <= 2){ + if (c->duration <= 2) { msg = msg_message("curseinfo::magicstreet", "id", c->no); } else { msg = msg_message("curseinfo::magicstreetwarn", "id", c->no); @@ -153,7 +153,7 @@ static struct curse_type ct_magicstreet = { /* --------------------------------------------------------------------- */ static int -cinfo_antimagiczone(const struct locale * lang, const void * obj, typ_t typ, curse *c, int self) +cinfo_antimagiczone(const struct locale * lang, const void * obj, typ_t typ, const curse *c, int self) { message * msg; @@ -164,13 +164,13 @@ cinfo_antimagiczone(const struct locale * lang, const void * obj, typ_t typ, cur assert(typ == TYP_REGION); /* Magier spüren eine Antimagiezone */ - if (self == 2 || self == 1){ + if (self == 2 || self == 1) { msg = msg_message("curseinfo::antimagiczone", "id", c->no); if (msg) { nr_render(msg, lang, buf, sizeof(buf), NULL); msg_release(msg); + return 1; } - return 1; } return 0; @@ -178,7 +178,7 @@ cinfo_antimagiczone(const struct locale * lang, const void * obj, typ_t typ, cur /* alle Magier können eine Antimagiezone wahrnehmen */ static int -cansee_antimagiczone(const struct faction *viewer, const void * obj, typ_t typ, curse *c, int self) +cansee_antimagiczone(const struct faction *viewer, const void * obj, typ_t typ, const curse *c, int self) { region *r; unit *u = NULL; @@ -189,8 +189,8 @@ cansee_antimagiczone(const struct faction *viewer, const void * obj, typ_t typ, assert(typ == TYP_REGION); r = (region *)obj; for (u = r->units; u; u = u->next) { - if (u->faction==viewer){ - if (u==mage){ + if (u->faction==viewer) { + if (u==mage) { self = 2; break; } @@ -212,7 +212,7 @@ static struct curse_type ct_antimagiczone = { /* --------------------------------------------------------------------- */ static int -cinfo_farvision(const struct locale * lang, const void * obj, typ_t typ, curse *c, int self) +cinfo_farvision(const struct locale * lang, const void * obj, typ_t typ, const curse *c, int self) { message * msg; @@ -222,7 +222,7 @@ cinfo_farvision(const struct locale * lang, const void * obj, typ_t typ, curse * assert(typ == TYP_REGION); /* Magier spüren eine farvision */ - if (self != 0){ + if (self != 0) { msg = msg_message("curseinfo::farvision", "id", c->no); nr_render(msg, lang, buf, sizeof(buf), NULL); msg_release(msg); diff --git a/src/common/spells/shipcurse.c b/src/common/spells/shipcurse.c index e79353cae..7144c53ca 100644 --- a/src/common/spells/shipcurse.c +++ b/src/common/spells/shipcurse.c @@ -33,7 +33,7 @@ int -cinfo_ship(const struct locale * lang, const void * obj, typ_t typ, curse *c, int self) +cinfo_ship(const struct locale * lang, const void * obj, typ_t typ, const curse *c, int self) { message * msg; @@ -41,7 +41,7 @@ cinfo_ship(const struct locale * lang, const void * obj, typ_t typ, curse *c, in unused(obj); assert(typ == TYP_SHIP); - if (self != 0){ /* owner or inside */ + if (self != 0) { /* owner or inside */ msg = msg_message(mkname("curseinfo", c->type->cname), "id", c->no); } else { msg = msg_message(mkname("curseinfo", "shipunknown"), "id", c->no); @@ -59,7 +59,7 @@ cinfo_ship(const struct locale * lang, const void * obj, typ_t typ, curse *c, in /* C_SHIP_NODRIFT */ static int -cinfo_shipnodrift(const struct locale * lang, const void * obj, typ_t typ, curse *c, int self) +cinfo_shipnodrift(const struct locale * lang, const void * obj, typ_t typ, const curse *c, int self) { ship * sh; unused(typ); diff --git a/src/common/spells/shipcurse.h b/src/common/spells/shipcurse.h index 371b2c254..4384f7f38 100644 --- a/src/common/spells/shipcurse.h +++ b/src/common/spells/shipcurse.h @@ -19,7 +19,7 @@ extern "C" { struct locale; struct curse; -extern int cinfo_ship(const struct locale * lang, const void * obj, typ_t typ, struct curse *c, int self); +extern int cinfo_ship(const struct locale * lang, const void * obj, typ_t typ, const struct curse *c, int self); extern void register_shipcurse(void); #ifdef __cplusplus diff --git a/src/common/spells/unitcurse.c b/src/common/spells/unitcurse.c index 40d37b20c..6b0b00916 100644 --- a/src/common/spells/unitcurse.c +++ b/src/common/spells/unitcurse.c @@ -41,7 +41,7 @@ */ /* erhöht/senkt regeneration und maxaura um effect% */ static int -cinfo_auraboost(const struct locale * lang, const void * obj, typ_t typ, struct curse *c, int self) +cinfo_auraboost(const struct locale * lang, const void * obj, typ_t typ, const curse *c, int self) { struct unit *u; unused(typ); @@ -52,7 +52,7 @@ cinfo_auraboost(const struct locale * lang, const void * obj, typ_t typ, struct if (curse_geteffect(c) > 100){ sprintf(buf, "%s fühlt sich von starken magischen Energien " "durchströmt. (%s)", u->name, curseid(c)); - }else{ + } else { sprintf(buf, "%s hat Schwierigkeiten seine magischen Energien " "zu sammeln. (%s)", u->name, curseid(c)); } @@ -82,7 +82,7 @@ static struct curse_type ct_magicboost = { * C_SLAVE */ static int -cinfo_slave(const struct locale * lang, const void * obj, typ_t typ, struct curse *c, int self) +cinfo_slave(const struct locale * lang, const void * obj, typ_t typ, const curse *c, int self) { unit *u; unused(typ); @@ -110,7 +110,7 @@ static struct curse_type ct_slavery = { "slavery", * C_CALM */ static int -cinfo_calm(const struct locale * lang, const void * obj, typ_t typ, struct curse *c, int self) +cinfo_calm(const struct locale * lang, const void * obj, typ_t typ, const curse *c, int self) { unit *u; const struct race * rc; @@ -147,7 +147,7 @@ static struct curse_type ct_calmmonster = { "calmmonster", * C_SPEED */ static int -cinfo_speed(const struct locale * lang, const void * obj, typ_t typ, struct curse *c, int self) +cinfo_speed(const struct locale * lang, const void * obj, typ_t typ, const curse *c, int self) { unit *u; curse_unit * cu; @@ -179,7 +179,7 @@ static struct curse_type ct_speed = { * C_ORC */ int -cinfo_unit(const struct locale * lang, const void * obj, typ_t typ, struct curse *c, int self) +cinfo_unit(const struct locale * lang, const void * obj, typ_t typ, const curse *c, int self) { unit *u; message * msg; @@ -210,7 +210,7 @@ static struct curse_type ct_orcish = { * C_KAELTESCHUTZ */ static int -cinfo_kaelteschutz(const struct locale * lang, const void * obj, typ_t typ, struct curse *c, int self) +cinfo_kaelteschutz(const struct locale * lang, const void * obj, typ_t typ, const curse *c, int self) { unit *u; curse_unit * cu; @@ -241,7 +241,7 @@ static struct curse_type ct_insectfur = { * C_SPARKLE */ static int -cinfo_sparkle(const struct locale * lang, const void * obj, typ_t typ, struct curse *c, int self) +cinfo_sparkle(const struct locale * lang, const void * obj, typ_t typ, const curse *c, int self) { const char * effects[] = { NULL, /* end grau*/ @@ -383,7 +383,7 @@ write_skill(FILE * F, const curse * c) } static int -cinfo_skill(const struct locale * lang, const void * obj, typ_t typ, struct curse *c, int self) +cinfo_skill(const struct locale * lang, const void * obj, typ_t typ, const curse *c, int self) { unit *u = (unit *)obj; int sk = c->data.i; diff --git a/src/common/spells/unitcurse.h b/src/common/spells/unitcurse.h index 2a48883d7..a5c9ec5fb 100644 --- a/src/common/spells/unitcurse.h +++ b/src/common/spells/unitcurse.h @@ -19,7 +19,7 @@ extern "C" { struct curse; struct locale; -extern int cinfo_unit(const struct locale * lang, const void * obj, typ_t typ, struct curse *c, int self); +extern int cinfo_unit(const struct locale * lang, const void * obj, typ_t typ, const struct curse *c, int self); extern void register_unitcurse(void);