Cleanup in cinfo_ code, although I would prefer that it doesn't write into buf but returns a message *. sometime later.

This commit is contained in:
Enno Rehling 2007-03-07 22:38:04 +00:00
parent 041a258ab2
commit da224f6670
13 changed files with 58 additions and 45 deletions

View File

@ -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); self = c->type->cansee(viewer, obj, typ, c, self);
} }
dh = c->type->curseinfo(viewer->locale, 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 (dh==0) {
if (c->type->info_str!=NULL) { if (c->type->info_str!=NULL) {
sprintf(buf, "%s (%s)", c->type->info_str, itoa36(c->no)); sprintf(buf, "%s (%s)", c->type->info_str, itoa36(c->no));
} else { } else {
log_error(("no curseinfo for %s\n", c->type->cname));
sprintf(buf, "an unknown curse lies on the region. (%s)", itoa36(c->no)); sprintf(buf, "an unknown curse lies on the region. (%s)", itoa36(c->no));
} }
} else { } else {

View File

@ -467,7 +467,7 @@ print_curses(FILE *F, const faction *viewer, const void * obj, typ_t typ, int in
unit * owner; unit * owner;
a = b->attribs; a = b->attribs;
r = b->region; r = b->region;
if((owner = buildingowner(r,b)) != NULL){ if ((owner = buildingowner(r,b)) != NULL){
if (owner->faction == viewer){ if (owner->faction == viewer){
self = 2; self = 2;
} else { /* steht eine Person der Partei in der Burg? */ } 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) { for(;a;a=a->next) {
int dh = 0;
if (fval(a->type, ATF_CURSE)) { if (fval(a->type, ATF_CURSE)) {
curse *c = (curse *)a->data.v; curse *c = (curse *)a->data.v;
if (c->type->curseinfo) { if (print_curse(c, viewer, obj, typ, self)) {
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) {
rnl(F); rnl(F);
rparagraph(F, buf, indent, 2, 0); rparagraph(F, buf, indent, 2, 0);
} }

View File

@ -737,7 +737,7 @@ oldcursename(int id)
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
int 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; struct message * msg;

View File

@ -222,15 +222,14 @@ typedef struct curse_type {
unsigned int mergeflags; unsigned int mergeflags;
const char *info_str; /* Wirkung des curse, wird bei einer gelungenen const char *info_str; /* Wirkung des curse, wird bei einer gelungenen
Zauberanalyse angezeigt */ 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); void (*change_vigour)(curse*, double);
int (*read)(FILE * F, curse * c); int (*read)(FILE * F, curse * c);
int (*write)(FILE * F, const 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 *); int (*age)(curse *);
} curse_type; } curse_type;
extern attrib_type at_curse; extern attrib_type at_curse;
extern void curse_write(const attrib * a,FILE * f); extern void curse_write(const attrib * a,FILE * f);
extern int curse_read(struct 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: */ /*** COMPATIBILITY MACROS. DO NOT USE FOR NEW CODE, REPLACE IN OLD CODE: */
extern const char * oldcursename(int id); extern const char * oldcursename(int id);
extern void register_curses(void); 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) \ #define is_cursed(a, id, id2) \
curse_active(get_curse(a, ct_find(oldcursename(id)))) curse_active(get_curse(a, ct_find(oldcursename(id))))

View File

@ -68,6 +68,7 @@ struct plane;
struct order; struct order;
struct spell; struct spell;
struct region; struct region;
struct curse;
struct fighter; struct fighter;
struct region_list; struct region_list;
struct race; struct race;

View File

@ -22,6 +22,7 @@
#include "reports.h" #include "reports.h"
/* kernel includes */ /* kernel includes */
#include <kernel/curse.h>
#include <kernel/building.h> #include <kernel/building.h>
#include <kernel/border.h> #include <kernel/border.h>
#include <kernel/terrain.h> #include <kernel/terrain.h>
@ -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 ? '+' : '-'))); 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 * const struct unit *
ucansee(const struct faction *f, const struct unit *u, const struct unit *x) ucansee(const struct faction *f, const struct unit *u, const struct unit *x)
{ {

View File

@ -110,6 +110,8 @@ extern const char * report_kampfstatus(const struct unit * u, const struct local
extern int update_nmrs(void); extern int update_nmrs(void);
extern int * nmrs; 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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -34,7 +34,7 @@
static int 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; message * msg;
@ -59,7 +59,7 @@ cinfo_building(const struct locale * lang, const void * obj, typ_t typ, curse *c
/* C_MAGICWALLS*/ /* C_MAGICWALLS*/
static int 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; message * msg = NULL;
if (typ == TYP_BUILDING){ if (typ == TYP_BUILDING){

View File

@ -42,7 +42,7 @@
* godcursezone * godcursezone
*/ */
static int 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; region *r;
message * msg; message * msg;
@ -82,7 +82,7 @@ static struct curse_type ct_godcursezone = {
* C_GBDREAM * C_GBDREAM
*/ */
static int 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; message * msg;
@ -91,7 +91,7 @@ cinfo_dreamcurse(const struct locale * lang, const void * obj, typ_t typ, curse
unused(obj); unused(obj);
assert(typ == TYP_REGION); assert(typ == TYP_REGION);
if (curse_geteffect(c) > 0){ if (curse_geteffect(c) > 0) {
msg = msg_message("curseinfo::gooddream", "id", c->no); msg = msg_message("curseinfo::gooddream", "id", c->no);
} else { } else {
msg = msg_message("curseinfo::baddream", "id", c->no); msg = msg_message("curseinfo::baddream", "id", c->no);
@ -117,7 +117,7 @@ static struct curse_type ct_gbdream = {
* erzeugt Straßennetz * erzeugt Straßennetz
*/ */
static int 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; message * msg;
@ -128,7 +128,7 @@ cinfo_magicstreet(const struct locale * lang, const void * obj, typ_t typ, curse
assert(typ == TYP_REGION); assert(typ == TYP_REGION);
/* Warnung vor Auflösung */ /* Warnung vor Auflösung */
if (c->duration <= 2){ if (c->duration <= 2) {
msg = msg_message("curseinfo::magicstreet", "id", c->no); msg = msg_message("curseinfo::magicstreet", "id", c->no);
} else { } else {
msg = msg_message("curseinfo::magicstreetwarn", "id", c->no); msg = msg_message("curseinfo::magicstreetwarn", "id", c->no);
@ -153,7 +153,7 @@ static struct curse_type ct_magicstreet = {
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
static int 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; message * msg;
@ -164,13 +164,13 @@ cinfo_antimagiczone(const struct locale * lang, const void * obj, typ_t typ, cur
assert(typ == TYP_REGION); assert(typ == TYP_REGION);
/* Magier spüren eine Antimagiezone */ /* Magier spüren eine Antimagiezone */
if (self == 2 || self == 1){ if (self == 2 || self == 1) {
msg = msg_message("curseinfo::antimagiczone", "id", c->no); msg = msg_message("curseinfo::antimagiczone", "id", c->no);
if (msg) { if (msg) {
nr_render(msg, lang, buf, sizeof(buf), NULL); nr_render(msg, lang, buf, sizeof(buf), NULL);
msg_release(msg); msg_release(msg);
return 1;
} }
return 1;
} }
return 0; 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 */ /* alle Magier können eine Antimagiezone wahrnehmen */
static int 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; region *r;
unit *u = NULL; unit *u = NULL;
@ -189,8 +189,8 @@ cansee_antimagiczone(const struct faction *viewer, const void * obj, typ_t typ,
assert(typ == TYP_REGION); assert(typ == TYP_REGION);
r = (region *)obj; r = (region *)obj;
for (u = r->units; u; u = u->next) { for (u = r->units; u; u = u->next) {
if (u->faction==viewer){ if (u->faction==viewer) {
if (u==mage){ if (u==mage) {
self = 2; self = 2;
break; break;
} }
@ -212,7 +212,7 @@ static struct curse_type ct_antimagiczone = {
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
static int 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; message * msg;
@ -222,7 +222,7 @@ cinfo_farvision(const struct locale * lang, const void * obj, typ_t typ, curse *
assert(typ == TYP_REGION); assert(typ == TYP_REGION);
/* Magier spüren eine farvision */ /* Magier spüren eine farvision */
if (self != 0){ if (self != 0) {
msg = msg_message("curseinfo::farvision", "id", c->no); msg = msg_message("curseinfo::farvision", "id", c->no);
nr_render(msg, lang, buf, sizeof(buf), NULL); nr_render(msg, lang, buf, sizeof(buf), NULL);
msg_release(msg); msg_release(msg);

View File

@ -33,7 +33,7 @@
int 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; message * msg;
@ -41,7 +41,7 @@ cinfo_ship(const struct locale * lang, const void * obj, typ_t typ, curse *c, in
unused(obj); unused(obj);
assert(typ == TYP_SHIP); 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); msg = msg_message(mkname("curseinfo", c->type->cname), "id", c->no);
} else { } else {
msg = msg_message(mkname("curseinfo", "shipunknown"), "id", c->no); 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 */ /* C_SHIP_NODRIFT */
static int 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; ship * sh;
unused(typ); unused(typ);

View File

@ -19,7 +19,7 @@ extern "C" {
struct locale; struct locale;
struct curse; 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); extern void register_shipcurse(void);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -41,7 +41,7 @@
*/ */
/* erhöht/senkt regeneration und maxaura um effect% */ /* erhöht/senkt regeneration und maxaura um effect% */
static int 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; struct unit *u;
unused(typ); unused(typ);
@ -52,7 +52,7 @@ cinfo_auraboost(const struct locale * lang, const void * obj, typ_t typ, struct
if (curse_geteffect(c) > 100){ if (curse_geteffect(c) > 100){
sprintf(buf, "%s fühlt sich von starken magischen Energien " sprintf(buf, "%s fühlt sich von starken magischen Energien "
"durchströmt. (%s)", u->name, curseid(c)); "durchströmt. (%s)", u->name, curseid(c));
}else{ } else {
sprintf(buf, "%s hat Schwierigkeiten seine magischen Energien " sprintf(buf, "%s hat Schwierigkeiten seine magischen Energien "
"zu sammeln. (%s)", u->name, curseid(c)); "zu sammeln. (%s)", u->name, curseid(c));
} }
@ -82,7 +82,7 @@ static struct curse_type ct_magicboost = {
* C_SLAVE * C_SLAVE
*/ */
static int 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; unit *u;
unused(typ); unused(typ);
@ -110,7 +110,7 @@ static struct curse_type ct_slavery = { "slavery",
* C_CALM * C_CALM
*/ */
static int 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; unit *u;
const struct race * rc; const struct race * rc;
@ -147,7 +147,7 @@ static struct curse_type ct_calmmonster = { "calmmonster",
* C_SPEED * C_SPEED
*/ */
static int 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; unit *u;
curse_unit * cu; curse_unit * cu;
@ -179,7 +179,7 @@ static struct curse_type ct_speed = {
* C_ORC * C_ORC
*/ */
int 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; unit *u;
message * msg; message * msg;
@ -210,7 +210,7 @@ static struct curse_type ct_orcish = {
* C_KAELTESCHUTZ * C_KAELTESCHUTZ
*/ */
static int 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; unit *u;
curse_unit * cu; curse_unit * cu;
@ -241,7 +241,7 @@ static struct curse_type ct_insectfur = {
* C_SPARKLE * C_SPARKLE
*/ */
static int 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[] = { const char * effects[] = {
NULL, /* end grau*/ NULL, /* end grau*/
@ -383,7 +383,7 @@ write_skill(FILE * F, const curse * c)
} }
static int 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; unit *u = (unit *)obj;
int sk = c->data.i; int sk = c->data.i;

View File

@ -19,7 +19,7 @@ extern "C" {
struct curse; struct curse;
struct locale; 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); extern void register_unitcurse(void);