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);
}
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 {

View File

@ -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);
}

View File

@ -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;

View File

@ -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))))

View File

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

View File

@ -22,6 +22,7 @@
#include "reports.h"
/* kernel includes */
#include <kernel/curse.h>
#include <kernel/building.h>
#include <kernel/border.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 ? '+' : '-')));
}
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)
{

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 * nmrs;
extern int print_curse(const struct curse * c, const struct faction * viewer, const void * obj, typ_t typ, int self);
#ifdef __cplusplus
}
#endif

View File

@ -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){

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -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);