forked from github/server
new argument-type for messages: items.
not the most efficient, since it takes a deep copy of the list.
This commit is contained in:
parent
6ad7a5562e
commit
af59e2f09c
3 changed files with 69 additions and 19 deletions
|
@ -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<<O_REPORT);
|
||||
register_reporttype("txt", &report_template, 1<<O_ZUGVORLAGE);
|
||||
|
|
|
@ -1694,6 +1694,29 @@ var_free_order(variant x)
|
|||
free_order(x.v);
|
||||
}
|
||||
|
||||
static variant
|
||||
var_copy_items(variant x)
|
||||
{
|
||||
item * isrc, * idst = NULL, ** iptr = &idst;
|
||||
|
||||
for (isrc = (item*)x.v; isrc!=NULL; isrc=isrc->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");
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<messages>
|
||||
<message name="nr_claims" section="nr">
|
||||
<type>
|
||||
<arg name="items" type="items"/>
|
||||
</type>
|
||||
<text locale="de">"Einheiten können die folgenden Gegenstände beanspruchen: $items($items)"</text>
|
||||
<text locale="en">"Units can claim the following items: $items($items)"</text>
|
||||
</message>
|
||||
<message name="sighting" section="events">
|
||||
<type>
|
||||
<arg name="region" type="region"/>
|
||||
|
|
Loading…
Reference in a new issue