forked from github/server
continued: new argument type "items" or "resources" (previous solution didn't allow lists of resources, which come in handy for build-error messages).
This commit is contained in:
parent
8ca86912cf
commit
7eee06c285
|
@ -3172,23 +3172,23 @@ eval_order(struct opstack ** stack, const void * userdata) /* order -> string */
|
|||
}
|
||||
|
||||
static void
|
||||
eval_items(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 struct item * itm = (const struct item *)opop(stack).v;
|
||||
const struct resource * res = (const struct resource *)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));
|
||||
while (res!=NULL && len > 4) {
|
||||
const char * rname = resourcename(res->type, (res->number!=1)?NMF_PLURAL:0);
|
||||
int written = snprintf(edit, len, "%d %s", res->number, LOC(report->locale, rname));
|
||||
len -= written;
|
||||
edit += written;
|
||||
|
||||
itm = itm->next;
|
||||
if (itm!=NULL && len>2) {
|
||||
res = res->next;
|
||||
if (res!=NULL && len>2) {
|
||||
strcat(edit, ", ");
|
||||
edit += 2;
|
||||
len -= 2;
|
||||
|
@ -3259,7 +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);
|
||||
add_function("resources", &eval_resources);
|
||||
|
||||
register_reporttype("nr", &report_plaintext, 1<<O_REPORT);
|
||||
register_reporttype("txt", &report_template, 1<<O_ZUGVORLAGE);
|
||||
|
|
|
@ -882,18 +882,17 @@ build_building(unit * u, const building_type * btype, int want, order * ord)
|
|||
case ENOMATERIALS: {
|
||||
/* something missing from the list of materials */
|
||||
const construction * cons = btype->construction;
|
||||
char * ch = buf;
|
||||
resource * reslist = NULL;
|
||||
assert(cons);
|
||||
for (c=0;cons->materials[c].number; c++) {
|
||||
int n;
|
||||
if (c!=0) strcat(ch++, ",");
|
||||
n = cons->materials[c].number / cons->reqsize;
|
||||
sprintf(ch, " %d %s", n?n:1,
|
||||
LOC(lang, resourcename(cons->materials[c].rtype, cons->materials[c].number!=1)));
|
||||
ch = ch+strlen(ch);
|
||||
for (c=0;cons->materials[c].number; ++c) {
|
||||
resource * res = malloc(sizeof(resource));
|
||||
res->number = cons->materials[c].number / cons->reqsize;
|
||||
res->type = cons->materials[c].rtype;
|
||||
res->next = reslist;
|
||||
reslist = res->next;
|
||||
}
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "build_required",
|
||||
"required", buf));
|
||||
"required", reslist));
|
||||
return;
|
||||
}
|
||||
case ELOWSKILL:
|
||||
|
|
|
@ -31,6 +31,12 @@ typedef struct item {
|
|||
struct item * next;
|
||||
} item;
|
||||
|
||||
typedef struct resource {
|
||||
const struct resource_type * type;
|
||||
int number;
|
||||
struct resource * next;
|
||||
} resource;
|
||||
|
||||
/* bitfield values for resource_type::flags */
|
||||
#define RTF_NONE 0
|
||||
#define RTF_ITEM (1<<0) /* this resource is an item */
|
||||
|
|
|
@ -1697,24 +1697,30 @@ var_free_order(variant x)
|
|||
static variant
|
||||
var_copy_items(variant x)
|
||||
{
|
||||
item * isrc, * idst = NULL, ** iptr = &idst;
|
||||
item * isrc;
|
||||
resource * rdst = NULL, ** rptr = &rdst;
|
||||
|
||||
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;
|
||||
resource * res = malloc(sizeof(resource));
|
||||
res->number = isrc->number;
|
||||
res->type = isrc->type->rtype;
|
||||
*rptr = res;
|
||||
rptr = &res->next;
|
||||
}
|
||||
*iptr = NULL;
|
||||
x.v = idst;
|
||||
*rptr = NULL;
|
||||
x.v = rdst;
|
||||
return x;
|
||||
}
|
||||
|
||||
static void
|
||||
var_free_items(variant x)
|
||||
var_free_resources(variant x)
|
||||
{
|
||||
i_freeall((item**)&x.v);
|
||||
resource ** rsrc = (resource**)&x.v;
|
||||
while (*rsrc) {
|
||||
resource * res = *rsrc;
|
||||
*rsrc = res->next;
|
||||
free(res);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1735,7 +1741,8 @@ 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_argtype("resources", var_free_resources, NULL, VAR_VOIDPTR);
|
||||
register_argtype("items", var_free_resources, var_copy_items, VAR_VOIDPTR);
|
||||
|
||||
/* register alternative visibility functions */
|
||||
register_function((pf_generic)view_neighbours, "view_neighbours");
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
<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>
|
||||
<text locale="de">"Einheiten können die folgenden Gegenstände beanspruchen: $resources($items)"</text>
|
||||
<text locale="en">"Units can claim the following items: $resources($items)"</text>
|
||||
</message>
|
||||
<message name="sighting" section="events">
|
||||
<type>
|
||||
|
|
Loading…
Reference in New Issue