diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index e690c3dad..1c058f023 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -3169,15 +3169,13 @@ new_units (void) order ** newordersp; if (!checkunitnumber(u->faction, 1)) { - if (global.unitsperalliance) { - ADDMSG(&u->faction->msgs, msg_message("too_many_units_in_alliance", - "command unit region allowed", - makeord, u, r, maxunits(u->faction))); - } else { - ADDMSG(&u->faction->msgs, msg_message("too_many_units_in_faction", - "command unit region allowed", - makeord, u, r, maxunits(u->faction))); - } + if (global.unitsperalliance) { + ADDMSG(&u->faction->msgs, msg_feedback(u, makeord, + "too_many_units_in_alliance", "allowed", maxunits(u->faction))); + } else { + ADDMSG(&u->faction->msgs, msg_feedback(u, makeord, + "too_many_units_in_faction", "allowed", maxunits(u->faction))); + } ordp = &makeord->next; while (*ordp) { diff --git a/src/common/gamecode/study.c b/src/common/gamecode/study.c index 16b9f989b..45359ed4d 100644 --- a/src/common/gamecode/study.c +++ b/src/common/gamecode/study.c @@ -615,8 +615,11 @@ learn_cmd(unit * u, order * ord) } else { /* Es wurde kein Magiegebiet angegeben und die Partei * hat noch keins gewählt. */ - cmistake(u, ord, 178, MSG_MAGIC); - return 0; + mtyp = getmagicskill(u->faction->locale); + if (mtyp==M_NONE) { + cmistake(u, ord, 178, MSG_MAGIC); + return 0; + } } } if (mtyp != u->faction->magiegebiet){ @@ -638,12 +641,14 @@ learn_cmd(unit * u, order * ord) /* die Partei hat noch kein Magiegebiet gewählt. */ mtyp = getmagicskill(u->faction->locale); if (mtyp == M_NONE){ - cmistake(u, ord, 178, MSG_MAGIC); - return 0; - } else { - /* Legt damit das Magiegebiet der Partei fest */ - u->faction->magiegebiet = mtyp; + mtyp = getmagicskill(u->faction->locale); + if (mtyp==M_NONE) { + cmistake(u, ord, 178, MSG_MAGIC); + return 0; + } } + /* Legt damit das Magiegebiet der Partei fest */ + u->faction->magiegebiet = mtyp; } } } diff --git a/src/common/items/artrewards.c b/src/common/items/artrewards.c index 069a04e2c..276e942ac 100644 --- a/src/common/items/artrewards.c +++ b/src/common/items/artrewards.c @@ -88,11 +88,10 @@ use_hornofdancing(struct unit * u, const struct item_type * itype, } if(regionsPacified > 0) { - ADDMSG(&u->faction->msgs, msg_message("hornofpeace_u_success", - "unit region command pacified", u, u->region, ord, regionsPacified)); + ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "hornofpeace_u_success", + "pacified", regionsPacified)); } else { - ADDMSG(&u->faction->msgs, msg_message("hornofpeace_u_nosuccess", - "unit region command", u, u->region, ord)); + ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "hornofpeace_u_nosuccess", "")); } return 0; diff --git a/src/common/kernel/message.c b/src/common/kernel/message.c index 77bb3cb75..4296581ab 100644 --- a/src/common/kernel/message.c +++ b/src/common/kernel/message.c @@ -77,36 +77,36 @@ arg_set(variant args[], const message_type * mtype, const char * buffer, variant struct message * msg_feedback(const struct unit * u, struct order * ord, const char * name, const char* sig, ...) { - va_list marker; - const message_type * mtype = mt_find(name); - char paramname[64]; - const char *ic = sig; - variant args[16]; + va_list marker; + const message_type * mtype = mt_find(name); + char paramname[64]; + const char *ic = sig; + variant args[16]; 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) { - log_error(("trying to create message of unknown type \"%s\"\n", name)); + if (!mtype) { + 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); - } + } var.v = (void*)u; - arg_set(args, mtype, "unit", var); + arg_set(args, mtype, "unit", var); var.v = (void*)u->region; - arg_set(args, mtype, "region", var); + arg_set(args, mtype, "region", var); var.v = (void*)ord; - arg_set(args, mtype, "command", var); + arg_set(args, mtype, "command", var); - va_start(marker, sig); - while (*ic && !isalnum(*ic)) ic++; - while (*ic) { - char * oc = paramname; + va_start(marker, sig); + while (*ic && !isalnum(*ic)) ic++; + while (*ic) { + char * oc = paramname; int i; while (isalnum(*ic)) *oc++ = *ic++; - *oc = '\0'; + *oc = '\0'; for (i=0;i!=mtype->nparameters;++i) { 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."); } while (*ic && !isalnum(*ic)) ic++; - } - va_end(marker); + } + va_end(marker); - return msg_create(mtype, args); + return msg_create(mtype, args); } message * @@ -239,13 +239,12 @@ addmessage(region * r, faction * f, const char *s, msg_t mtype, int level) void cmistake(const unit * u, struct order *ord, int mno, int mtype) { - static char ebuf[20]; + static char msgname[20]; unused(mtype); - if (is_monsters(u->faction)) return; - sprintf(ebuf, "error%d", mno); - ADDMSG(&u->faction->msgs, msg_message(ebuf, - "command unit region", ord, u, u->region)); + if (is_monsters(u->faction)) return; + sprintf(msgname, "error%d", mno); + ADDMSG(&u->faction->msgs, msg_feedback(u, ord, msgname, "")); } extern unsigned int new_hashstring(const char* s); diff --git a/src/common/kernel/reports.c b/src/common/kernel/reports.c index a9660dea4..0c78d9737 100644 --- a/src/common/kernel/reports.c +++ b/src/common/kernel/reports.c @@ -1882,9 +1882,10 @@ static void eval_resource(struct opstack ** stack, const void * userdata) { const faction * report = (const faction*)userdata; + const struct locale * lang = report?report->locale:default_locale; int j = opop(stack).i; 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); variant var; @@ -1896,9 +1897,10 @@ static void eval_race(struct opstack ** stack, const void * userdata) { const faction * report = (const faction*)userdata; + const struct locale * lang = report?report->locale:default_locale; int j = opop(stack).i; 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); variant var; @@ -1925,6 +1927,7 @@ static void eval_resources(struct opstack ** stack, const void * userdata) /* order -> string */ { 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; static char buf[1024]; /* but we only use about half of this */ size_t size = sizeof(buf) - 1; @@ -1933,7 +1936,7 @@ eval_resources(struct opstack ** stack, const void * userdata) /* order -> strin char * bufp = buf; while (res!=NULL && size > 4) { 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 string */ { const faction * report = (const faction*)userdata; + const struct locale * lang = report?report->locale:default_locale; int i, end = 0, begin = 0; const arg_regions * regions = (const arg_regions *)opop(stack).v; static char buf[512]; @@ -2004,7 +2008,7 @@ eval_trail(struct opstack ** stack, const void * userdata) /* order -> string */ end = regions->nregions; for (i=begin;iregions[i]; - const char * trail = trailinto(r, report->locale); + const char * trail = trailinto(r, lang); const char * rn = f_regionid_s(r, report); int bytes = snprintf(bufp, size, trail, rn); 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+2locale, "list_and"), size); + bytes = (int)strlcpy(bufp, LOC(lang, "list_and"), size); } else bytes = 0; if (bytes && wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER(); @@ -2032,8 +2036,9 @@ static void eval_direction(struct opstack ** stack, const void * userdata) { const faction * report = (const faction*)userdata; + const struct locale * lang = report?report->locale:default_locale; 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); variant var; @@ -2045,8 +2050,9 @@ static void eval_skill(struct opstack ** stack, const void * userdata) { const faction * report = (const faction*)userdata; + const struct locale * lang = report?report->locale:default_locale; 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); variant var; @@ -2068,6 +2074,20 @@ eval_int36(struct opstack ** stack, const void * userdata) } /*** END MESSAGE RENDERING ***/ +#include + +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 reports_init(void) { @@ -2091,6 +2111,9 @@ reports_init(void) register_argtype("items", var_free_resources, var_copy_items, 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 */ add_function("alliance", &eval_alliance); add_function("region", &eval_region); diff --git a/src/common/modules/gmcmd.c b/src/common/modules/gmcmd.c index 41007e244..be0854d99 100644 --- a/src/common/modules/gmcmd.c +++ b/src/common/modules/gmcmd.c @@ -61,8 +61,8 @@ static void mistake(const unit * u, struct order * ord, const char *comment) { if (!is_monsters(u->faction)) { - ADDMSG(&u->faction->msgs, msg_message("mistake", - "command error unit region", ord, comment, u, u->region)); + ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "mistake", + "error", comment)); } } diff --git a/src/common/spells/spells.c b/src/common/spells/spells.c index 66cfdc88c..0016c3bcc 100644 --- a/src/common/spells/spells.c +++ b/src/common/spells/spells.c @@ -1780,8 +1780,8 @@ sp_treewalkenter(castorder *co) w = weight(u); if (remaining_cap - w < 0) { - ADDMSG(&mage->faction->msgs, msg_message("fail_tooheavy", - "command region unit target", co->order, r, mage, u)); + ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, "fail_tooheavy", + "target", u)); continue; } remaining_cap = remaining_cap - w; @@ -5698,8 +5698,7 @@ sp_fetchastral(castorder *co) region * ro = NULL; /* region in which the target is */ if (rplane(rt)!=get_normalplane()) { - ADDMSG(&mage->faction->msgs, msg_message("error190", - "command region unit", co->order, rt, mage)); + ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, "error190", "")); return 0; } @@ -5726,15 +5725,16 @@ sp_fetchastral(castorder *co) } if (rfind==NULL) { /* the region r is not in the schemes of rt */ - ADDMSG(&mage->faction->msgs, msg_message("spellfail_distance", - "command region unit target", co->order, mage->region, mage, u)); + ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, + "spellfail_distance", "target", u)); continue; } ro = u->region; } 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; } @@ -5745,8 +5745,8 @@ sp_fetchastral(castorder *co) w = weight(u); if (remaining_cap - w < 0) { - ADDMSG(&mage->faction->msgs, msg_message("fail_tooheavy", - "command region unit target", co->order, mage->region, mage, u)); + ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, + "fail_tooheavy", "target", u)); continue; } diff --git a/src/common/util/message.c b/src/common/util/message.c index 9659d5966..ae8346465 100644 --- a/src/common/util/message.c +++ b/src/common/util/message.c @@ -24,6 +24,8 @@ #include #include +void (*msg_log_create)(const struct message * msg) = 0; + const char * 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) { msg->parameters[i] = copy_arg(mtype->types[i], args[i]); } + if (msg_log_create) msg_log_create(msg); return msg; } diff --git a/src/common/util/message.h b/src/common/util/message.h index 242ed062f..021283903 100644 --- a/src/common/util/message.h +++ b/src/common/util/message.h @@ -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 const struct arg_type * find_argtype(const char * name); +extern void (*msg_log_create)(const struct message * msg); + #ifdef __cplusplus } #endif