- second try for LEARN Magic "Gwyrrd"

- message-logging
This commit is contained in:
Enno Rehling 2009-07-13 13:57:46 +00:00
parent b67220f91e
commit 75234b303b
9 changed files with 93 additions and 64 deletions

View file

@ -3169,15 +3169,13 @@ new_units (void)
order ** newordersp; order ** newordersp;
if (!checkunitnumber(u->faction, 1)) { if (!checkunitnumber(u->faction, 1)) {
if (global.unitsperalliance) { if (global.unitsperalliance) {
ADDMSG(&u->faction->msgs, msg_message("too_many_units_in_alliance", ADDMSG(&u->faction->msgs, msg_feedback(u, makeord,
"command unit region allowed", "too_many_units_in_alliance", "allowed", maxunits(u->faction)));
makeord, u, r, maxunits(u->faction))); } else {
} else { ADDMSG(&u->faction->msgs, msg_feedback(u, makeord,
ADDMSG(&u->faction->msgs, msg_message("too_many_units_in_faction", "too_many_units_in_faction", "allowed", maxunits(u->faction)));
"command unit region allowed", }
makeord, u, r, maxunits(u->faction)));
}
ordp = &makeord->next; ordp = &makeord->next;
while (*ordp) { while (*ordp) {

View file

@ -615,8 +615,11 @@ learn_cmd(unit * u, order * ord)
} else { } else {
/* Es wurde kein Magiegebiet angegeben und die Partei /* Es wurde kein Magiegebiet angegeben und die Partei
* hat noch keins gewählt. */ * hat noch keins gewählt. */
cmistake(u, ord, 178, MSG_MAGIC); mtyp = getmagicskill(u->faction->locale);
return 0; if (mtyp==M_NONE) {
cmistake(u, ord, 178, MSG_MAGIC);
return 0;
}
} }
} }
if (mtyp != u->faction->magiegebiet){ if (mtyp != u->faction->magiegebiet){
@ -638,12 +641,14 @@ learn_cmd(unit * u, order * ord)
/* die Partei hat noch kein Magiegebiet gewählt. */ /* die Partei hat noch kein Magiegebiet gewählt. */
mtyp = getmagicskill(u->faction->locale); mtyp = getmagicskill(u->faction->locale);
if (mtyp == M_NONE){ if (mtyp == M_NONE){
cmistake(u, ord, 178, MSG_MAGIC); mtyp = getmagicskill(u->faction->locale);
return 0; if (mtyp==M_NONE) {
} else { cmistake(u, ord, 178, MSG_MAGIC);
/* Legt damit das Magiegebiet der Partei fest */ return 0;
u->faction->magiegebiet = mtyp; }
} }
/* Legt damit das Magiegebiet der Partei fest */
u->faction->magiegebiet = mtyp;
} }
} }
} }

View file

@ -88,11 +88,10 @@ use_hornofdancing(struct unit * u, const struct item_type * itype,
} }
if(regionsPacified > 0) { if(regionsPacified > 0) {
ADDMSG(&u->faction->msgs, msg_message("hornofpeace_u_success", ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "hornofpeace_u_success",
"unit region command pacified", u, u->region, ord, regionsPacified)); "pacified", regionsPacified));
} else { } else {
ADDMSG(&u->faction->msgs, msg_message("hornofpeace_u_nosuccess", ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "hornofpeace_u_nosuccess", ""));
"unit region command", u, u->region, ord));
} }
return 0; return 0;

View file

@ -77,36 +77,36 @@ arg_set(variant args[], const message_type * mtype, const char * buffer, variant
struct message * struct message *
msg_feedback(const struct unit * u, struct order * ord, const char * name, const char* sig, ...) msg_feedback(const struct unit * u, struct order * ord, const char * name, const char* sig, ...)
{ {
va_list marker; va_list marker;
const message_type * mtype = mt_find(name); const message_type * mtype = mt_find(name);
char paramname[64]; char paramname[64];
const char *ic = sig; const char *ic = sig;
variant args[16]; variant args[16];
variant var; variant var;
memset(args, 0, sizeof(args)); memset(args, 0, sizeof(args));
if (ord==NULL) ord = u->thisorder; if (ord==NULL) ord = u->thisorder;
if (!mtype) { if (!mtype) {
log_error(("trying to create message of unknown type \"%s\"\n", name)); log_error(("trying to create message of unknown type \"%s\"\n", name));
return msg_message("missing_feedback", "unit region command name", u, u->region, ord, name); return msg_message("missing_feedback", "unit region command name", u, u->region, ord, name);
} }
var.v = (void*)u; var.v = (void*)u;
arg_set(args, mtype, "unit", var); arg_set(args, mtype, "unit", var);
var.v = (void*)u->region; var.v = (void*)u->region;
arg_set(args, mtype, "region", var); arg_set(args, mtype, "region", var);
var.v = (void*)ord; var.v = (void*)ord;
arg_set(args, mtype, "command", var); arg_set(args, mtype, "command", var);
va_start(marker, sig); va_start(marker, sig);
while (*ic && !isalnum(*ic)) ic++; while (*ic && !isalnum(*ic)) ic++;
while (*ic) { while (*ic) {
char * oc = paramname; char * oc = paramname;
int i; int i;
while (isalnum(*ic)) *oc++ = *ic++; while (isalnum(*ic)) *oc++ = *ic++;
*oc = '\0'; *oc = '\0';
for (i=0;i!=mtype->nparameters;++i) { for (i=0;i!=mtype->nparameters;++i) {
if (!strcmp(paramname, mtype->pnames[i])) break; if (!strcmp(paramname, mtype->pnames[i])) break;
@ -124,10 +124,10 @@ msg_feedback(const struct unit * u, struct order * ord, const char * name, const
assert(!"program aborted."); assert(!"program aborted.");
} }
while (*ic && !isalnum(*ic)) ic++; while (*ic && !isalnum(*ic)) ic++;
} }
va_end(marker); va_end(marker);
return msg_create(mtype, args); return msg_create(mtype, args);
} }
message * message *
@ -239,13 +239,12 @@ addmessage(region * r, faction * f, const char *s, msg_t mtype, int level)
void void
cmistake(const unit * u, struct order *ord, int mno, int mtype) cmistake(const unit * u, struct order *ord, int mno, int mtype)
{ {
static char ebuf[20]; static char msgname[20];
unused(mtype); unused(mtype);
if (is_monsters(u->faction)) return; if (is_monsters(u->faction)) return;
sprintf(ebuf, "error%d", mno); sprintf(msgname, "error%d", mno);
ADDMSG(&u->faction->msgs, msg_message(ebuf, ADDMSG(&u->faction->msgs, msg_feedback(u, ord, msgname, ""));
"command unit region", ord, u, u->region));
} }
extern unsigned int new_hashstring(const char* s); extern unsigned int new_hashstring(const char* s);

View file

@ -1882,9 +1882,10 @@ static void
eval_resource(struct opstack ** stack, const void * userdata) eval_resource(struct opstack ** stack, const void * userdata)
{ {
const faction * report = (const faction*)userdata; const faction * report = (const faction*)userdata;
const struct locale * lang = report?report->locale:default_locale;
int j = opop(stack).i; int j = opop(stack).i;
const struct resource_type * res = (const struct resource_type *)opop(stack).v; const struct resource_type * res = (const struct resource_type *)opop(stack).v;
const char * c = LOC(report->locale, resourcename(res, j!=1)); const char * c = LOC(lang, resourcename(res, j!=1));
size_t len = strlen(c); size_t len = strlen(c);
variant var; variant var;
@ -1896,9 +1897,10 @@ static void
eval_race(struct opstack ** stack, const void * userdata) eval_race(struct opstack ** stack, const void * userdata)
{ {
const faction * report = (const faction*)userdata; const faction * report = (const faction*)userdata;
const struct locale * lang = report?report->locale:default_locale;
int j = opop(stack).i; int j = opop(stack).i;
const race * r = (const race *)opop(stack).v; const race * r = (const race *)opop(stack).v;
const char * c = LOC(report->locale, rc_name(r, j!=1)); const char * c = LOC(lang, rc_name(r, j!=1));
size_t len = strlen(c); size_t len = strlen(c);
variant var; variant var;
@ -1925,6 +1927,7 @@ static void
eval_resources(struct opstack ** stack, const void * userdata) /* order -> string */ eval_resources(struct opstack ** stack, const void * userdata) /* order -> string */
{ {
const faction * report = (const faction*)userdata; const faction * report = (const faction*)userdata;
const struct locale * lang = report?report->locale:default_locale;
const struct resource * res = (const struct resource *)opop(stack).v; const struct resource * res = (const struct resource *)opop(stack).v;
static char buf[1024]; /* but we only use about half of this */ static char buf[1024]; /* but we only use about half of this */
size_t size = sizeof(buf) - 1; size_t size = sizeof(buf) - 1;
@ -1933,7 +1936,7 @@ eval_resources(struct opstack ** stack, const void * userdata) /* order -> strin
char * bufp = buf; char * bufp = buf;
while (res!=NULL && size > 4) { while (res!=NULL && size > 4) {
const char * rname = resourcename(res->type, (res->number!=1)?NMF_PLURAL:0); const char * rname = resourcename(res->type, (res->number!=1)?NMF_PLURAL:0);
int bytes = snprintf(bufp, size, "%d %s", res->number, LOC(report->locale, rname)); int bytes = snprintf(bufp, size, "%d %s", res->number, LOC(lang, rname));
if (bytes<0 || wrptr(&bufp, &size, bytes)!=0 || size<sizeof(buf)/2) { if (bytes<0 || wrptr(&bufp, &size, bytes)!=0 || size<sizeof(buf)/2) {
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
break; break;
@ -1989,6 +1992,7 @@ static void
eval_trail(struct opstack ** stack, const void * userdata) /* order -> string */ eval_trail(struct opstack ** stack, const void * userdata) /* order -> string */
{ {
const faction * report = (const faction*)userdata; const faction * report = (const faction*)userdata;
const struct locale * lang = report?report->locale:default_locale;
int i, end = 0, begin = 0; int i, end = 0, begin = 0;
const arg_regions * regions = (const arg_regions *)opop(stack).v; const arg_regions * regions = (const arg_regions *)opop(stack).v;
static char buf[512]; static char buf[512];
@ -2004,7 +2008,7 @@ eval_trail(struct opstack ** stack, const void * userdata) /* order -> string */
end = regions->nregions; end = regions->nregions;
for (i=begin;i<end;++i) { for (i=begin;i<end;++i) {
region * r = regions->regions[i]; region * r = regions->regions[i];
const char * trail = trailinto(r, report->locale); const char * trail = trailinto(r, lang);
const char * rn = f_regionid_s(r, report); const char * rn = f_regionid_s(r, report);
int bytes = snprintf(bufp, size, trail, rn); int bytes = snprintf(bufp, size, trail, rn);
if (bytes<0 || wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER(); if (bytes<0 || wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
@ -2012,7 +2016,7 @@ eval_trail(struct opstack ** stack, const void * userdata) /* order -> string */
if (i+2<end) { if (i+2<end) {
bytes = (int)strlcpy(bufp, ", ", size); bytes = (int)strlcpy(bufp, ", ", size);
} else if (i+1<end) { } else if (i+1<end) {
bytes = (int)strlcpy(bufp, LOC(report->locale, "list_and"), size); bytes = (int)strlcpy(bufp, LOC(lang, "list_and"), size);
} else bytes = 0; } else bytes = 0;
if (bytes && wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER(); if (bytes && wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
@ -2032,8 +2036,9 @@ static void
eval_direction(struct opstack ** stack, const void * userdata) eval_direction(struct opstack ** stack, const void * userdata)
{ {
const faction * report = (const faction*)userdata; const faction * report = (const faction*)userdata;
const struct locale * lang = report?report->locale:default_locale;
int i = opop(stack).i; int i = opop(stack).i;
const char * c = LOC(report->locale, (i>=0)?directions[i]:"unknown_direction"); const char * c = LOC(lang, (i>=0)?directions[i]:"unknown_direction");
size_t len = strlen(c); size_t len = strlen(c);
variant var; variant var;
@ -2045,8 +2050,9 @@ static void
eval_skill(struct opstack ** stack, const void * userdata) eval_skill(struct opstack ** stack, const void * userdata)
{ {
const faction * report = (const faction*)userdata; const faction * report = (const faction*)userdata;
const struct locale * lang = report?report->locale:default_locale;
skill_t sk = (skill_t)opop(stack).i; skill_t sk = (skill_t)opop(stack).i;
const char * c = skillname(sk, report->locale); const char * c = skillname(sk, lang);
size_t len = strlen(c); size_t len = strlen(c);
variant var; variant var;
@ -2068,6 +2074,20 @@ eval_int36(struct opstack ** stack, const void * userdata)
} }
/*** END MESSAGE RENDERING ***/ /*** END MESSAGE RENDERING ***/
#include <util/nrmessage.h>
static void log_orders(const struct message * msg)
{
char buffer[4096];
int i;
for (i=0;i!=msg->type->nparameters;++i) {
if (msg->type->types[i]->copy==&var_copy_order) {
nr_render(msg, default_locale, buffer, sizeof(buffer), NULL);
log_warning(("meep - %s\n", buffer));
}
}
}
void void
reports_init(void) reports_init(void)
{ {
@ -2091,6 +2111,9 @@ reports_init(void)
register_argtype("items", var_free_resources, var_copy_items, VAR_VOIDPTR); register_argtype("items", var_free_resources, var_copy_items, VAR_VOIDPTR);
register_argtype("regions", var_free_regions, NULL, VAR_VOIDPTR); register_argtype("regions", var_free_regions, NULL, VAR_VOIDPTR);
msg_log_create = &log_orders;
/* register functions that turn message contents to readable strings */ /* register functions that turn message contents to readable strings */
add_function("alliance", &eval_alliance); add_function("alliance", &eval_alliance);
add_function("region", &eval_region); add_function("region", &eval_region);

View file

@ -61,8 +61,8 @@ static void
mistake(const unit * u, struct order * ord, const char *comment) mistake(const unit * u, struct order * ord, const char *comment)
{ {
if (!is_monsters(u->faction)) { if (!is_monsters(u->faction)) {
ADDMSG(&u->faction->msgs, msg_message("mistake", ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "mistake",
"command error unit region", ord, comment, u, u->region)); "error", comment));
} }
} }

View file

@ -1780,8 +1780,8 @@ sp_treewalkenter(castorder *co)
w = weight(u); w = weight(u);
if (remaining_cap - w < 0) { if (remaining_cap - w < 0) {
ADDMSG(&mage->faction->msgs, msg_message("fail_tooheavy", ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, "fail_tooheavy",
"command region unit target", co->order, r, mage, u)); "target", u));
continue; continue;
} }
remaining_cap = remaining_cap - w; remaining_cap = remaining_cap - w;
@ -5698,8 +5698,7 @@ sp_fetchastral(castorder *co)
region * ro = NULL; /* region in which the target is */ region * ro = NULL; /* region in which the target is */
if (rplane(rt)!=get_normalplane()) { if (rplane(rt)!=get_normalplane()) {
ADDMSG(&mage->faction->msgs, msg_message("error190", ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, "error190", ""));
"command region unit", co->order, rt, mage));
return 0; return 0;
} }
@ -5726,15 +5725,16 @@ sp_fetchastral(castorder *co)
} }
if (rfind==NULL) { if (rfind==NULL) {
/* the region r is not in the schemes of rt */ /* the region r is not in the schemes of rt */
ADDMSG(&mage->faction->msgs, msg_message("spellfail_distance", ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
"command region unit target", co->order, mage->region, mage, u)); "spellfail_distance", "target", u));
continue; continue;
} }
ro = u->region; ro = u->region;
} }
if (is_cursed(ro->attribs, C_ASTRALBLOCK, 0)) { if (is_cursed(ro->attribs, C_ASTRALBLOCK, 0)) {
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, "spellfail_astralblock", "")); ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
"spellfail_astralblock", ""));
continue; continue;
} }
@ -5745,8 +5745,8 @@ sp_fetchastral(castorder *co)
w = weight(u); w = weight(u);
if (remaining_cap - w < 0) { if (remaining_cap - w < 0) {
ADDMSG(&mage->faction->msgs, msg_message("fail_tooheavy", ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
"command region unit target", co->order, mage->region, mage, u)); "fail_tooheavy", "target", u));
continue; continue;
} }

View file

@ -24,6 +24,8 @@
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
void (*msg_log_create)(const struct message * msg) = 0;
const char * const char *
mt_name(const message_type* mtype) mt_name(const message_type* mtype)
{ {
@ -147,6 +149,7 @@ msg_create(const struct message_type * mtype, variant args[])
for (i=0;i!=mtype->nparameters;++i) { for (i=0;i!=mtype->nparameters;++i) {
msg->parameters[i] = copy_arg(mtype->types[i], args[i]); msg->parameters[i] = copy_arg(mtype->types[i], args[i]);
} }
if (msg_log_create) msg_log_create(msg);
return msg; return msg;
} }

View file

@ -63,6 +63,8 @@ extern const struct message_type * mt_find(const char *);
extern void register_argtype(const char * name, void(*free_arg)(variant), variant (*copy_arg)(variant), variant_type); extern void register_argtype(const char * name, void(*free_arg)(variant), variant (*copy_arg)(variant), variant_type);
extern const struct arg_type * find_argtype(const char * name); extern const struct arg_type * find_argtype(const char * name);
extern void (*msg_log_create)(const struct message * msg);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif