From af59e2f09c675c71647bc3328b14d16be38de605 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 8 Jan 2006 12:25:00 +0000 Subject: [PATCH] new argument-type for messages: items. not the most efficient, since it takes a deep copy of the list. --- src/common/gamecode/report.c | 57 ++++++++++++++++++++++++------------ src/common/kernel/reports.c | 24 +++++++++++++++ src/res/messages.xml | 7 +++++ 3 files changed, 69 insertions(+), 19 deletions(-) diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index b0c0482fb..10caadfff 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -1989,28 +1989,18 @@ report_plaintext(const char * filename, report_context * ctx) { int maxh = maxheroes(f); if (maxh) { - m = msg_message("nr_heroes", "units maxunits", countheroes(f), maxh); - nr_render(m, f->locale, buf, sizeof(buf), f); - msg_release(m); + message * msg = msg_message("nr_heroes", "units maxunits", countheroes(f), maxh); + nr_render(msg, f->locale, buf, sizeof(buf), f); + msg_release(msg); centre(F, buf, true); } } #endif if (f->items!=NULL) { - item * iclaim = f->items; - char * edit = buf; - strcpy(edit, LOC(f->locale, "claimable")); - edit += strlen(edit); - while (iclaim!=NULL) { - sprintf(edit, "%d %s", iclaim->number, - LOC(f->locale, resourcename(iclaim->type->rtype, (iclaim->number!=1)?NMF_PLURAL:0))); - iclaim = iclaim->next; - if (iclaim!=NULL) { - strcat(edit, ", "); - } - edit += strlen(edit); - } + message * msg = msg_message("nr_claims", "items", f->items); + nr_render(msg, f->locale, buf, sizeof(buf), f); + msg_release(msg); rnl(F); centre(F, buf, true); } @@ -3169,9 +3159,9 @@ eval_race(struct opstack ** stack, const void * userdata) static void eval_order(struct opstack ** stack, const void * userdata) /* order -> string */ { - const faction * report = (const faction*)userdata; - const struct order * ord = (const struct order *)opop(stack).v; - static char buf[256]; + const faction * report = (const faction*)userdata; + const struct order * ord = (const struct order *)opop(stack).v; + static char buf[256]; size_t len; variant var; @@ -3181,6 +3171,34 @@ eval_order(struct opstack ** stack, const void * userdata) /* order -> string */ opush(stack, var); } +static void +eval_items(struct opstack ** stack, const void * userdata) /* order -> string */ +{ + const faction * report = (const faction*)userdata; + const struct item * itm = (const struct item *)opop(stack).v; + static char buf[256]; + size_t len = sizeof(buf); + variant var; + + char * edit = buf; + while (itm!=NULL && len > 4) { + const char * rname = resourcename(itm->type->rtype, (itm->number!=1)?NMF_PLURAL:0); + int written = snprintf(edit, len, "%d %s", itm->number, LOC(report->locale, rname)); + len -= written; + edit += written; + + itm = itm->next; + if (itm!=NULL && len>2) { + strcat(edit, ", "); + edit += 2; + len -= 2; + } + } + *edit = 0; + var.v = strcpy(balloc(edit-buf+1), buf); + opush(stack, var); +} + static void eval_direction(struct opstack ** stack, const void * userdata) { @@ -3241,6 +3259,7 @@ report_init(void) add_function("int36", &eval_int36); add_function("trail", &eval_trail); add_function("spell", &eval_spell); + add_function("items", &eval_items); register_reporttype("nr", &report_plaintext, 1<next) { + item * itm = malloc(sizeof(item)); + itm->number = isrc->number; + itm->type = isrc->type; + *iptr = itm; + iptr = &itm->next; + } + *iptr = NULL; + x.v = idst; + return x; +} + +static void +var_free_items(variant x) +{ + i_freeall((item**)&x.v); +} + void reports_init(void) { @@ -1712,6 +1735,7 @@ reports_init(void) register_argtype("int", NULL, NULL, VAR_INT); register_argtype("string", var_free_string, var_copy_string, VAR_VOIDPTR); register_argtype("order", var_free_order, var_copy_order, VAR_VOIDPTR); + register_argtype("items", var_free_items, var_copy_items, VAR_VOIDPTR); /* register alternative visibility functions */ register_function((pf_generic)view_neighbours, "view_neighbours"); diff --git a/src/res/messages.xml b/src/res/messages.xml index 0f50c6596..e49bf4b8f 100644 --- a/src/res/messages.xml +++ b/src/res/messages.xml @@ -1,5 +1,12 @@ + + + + + "Einheiten können die folgenden Gegenstände beanspruchen: $items($items)" + "Units can claim the following items: $items($items)" +