make report_resource return an rtype, not a name.

This commit is contained in:
Enno Rehling 2017-03-05 17:42:57 +01:00
parent d6ce1d9cfe
commit 0379a17350
6 changed files with 27 additions and 20 deletions

View File

@ -1094,12 +1094,12 @@ static void cr_reportspell(FILE * F, spell * sp, int level, const struct locale
}
}
static char *cr_output_resource(char *buf, const char *name,
static char *cr_output_resource(char *buf, const resource_type *rtype,
const struct locale *loc, int amount, int level)
{
assert(name);
buf += sprintf(buf, "RESOURCE %u\n", hashstring(name));
buf += sprintf(buf, "\"%s\";type\n", translate(name, LOC(loc, name)));
assert(rtype);
buf += sprintf(buf, "RESOURCE %u\n", hashstring(rtype->_name));
buf += sprintf(buf, "\"%s\";type\n", translate(rtype->_name, LOC(loc, rtype->_name)));
if (amount >= 0) {
if (level >= 0)
buf += sprintf(buf, "%d;skill\n", level);
@ -1180,7 +1180,7 @@ void cr_output_resources(stream *out, const faction * f, const region *r, bool s
}
for (n = 0; n < size; ++n) {
if (result[n].level >= 0 && result[n].number >= 0) {
stream_printf(out, "%d;%s\n", result[n].number, crtag(result[n].name));
/* stream_printf(out, "%d;%s\n", result[n].number, crtag(result[n].name)); */
}
}
#endif
@ -1188,7 +1188,7 @@ void cr_output_resources(stream *out, const faction * f, const region *r, bool s
for (n = 0; n < size; ++n) {
if (result[n].number >= 0) {
pos =
cr_output_resource(pos, result[n].name, f->locale, result[n].number,
cr_output_resource(pos, result[n].rtype, f->locale, result[n].number,
result[n].level);
}
}

View File

@ -58,6 +58,7 @@ static void test_cr_resources(CuTest *tc) {
struct locale *lang;
test_setup();
init_resources();
lang = get_or_create_locale("de"); /* CR tags are translated from this */
locale_setstring(lang, "money", "Silber");
locale_setstring(lang, "money_p", "Silber");

View File

@ -988,6 +988,11 @@ void init_resources(void)
rtype->itype = it_get_or_create(rtype);
rtype->itype->flags |= ITF_ANIMAL | ITF_BIG;
rtype = rt_get_or_create(resourcenames[R_SAPLING]);
rtype = rt_get_or_create(resourcenames[R_TREE]);
rtype = rt_get_or_create(resourcenames[R_MALLORN_SAPLING]);
rtype = rt_get_or_create(resourcenames[R_MALLORN_TREE]);
/* "special" spell components */
rtype = rt_get_or_create(resourcenames[R_AURA]);
rtype->uchange = res_changeaura;

View File

@ -1005,7 +1005,7 @@ void report_region(struct stream *out, const region * r, faction * f)
for (n = 0; n < numresults; ++n) {
if (result[n].number >= 0 && result[n].level >= 0) {
bytes = snprintf(bufp, size, ", %d %s/%d", result[n].number,
LOC(f->locale, result[n].name), result[n].level);
LOC(f->locale, result[n].rtype->_name), result[n].level);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}

View File

@ -346,11 +346,11 @@ report_items(const unit *u, item * result, int size, const unit * owner,
return n;
}
static void
report_resource(resource_report * result, const char *name, int number,
int level)
static void report_resource(resource_report * result, const resource_type *rtype,
int number, int level)
{
result->name = name;
assert(rtype);
result->rtype = rtype;
result->number = number;
result->level = level;
}
@ -408,37 +408,38 @@ const faction * viewer, bool see_unit)
int trees = rtrees(r, 2);
int saplings = rtrees(r, 1);
bool mallorn = fval(r, RF_MALLORN) != 0;
const resource_type *rtype;
if (money) {
if (n >= size)
return -1;
report_resource(result + n, "money", money, -1);
report_resource(result + n, get_resourcetype(R_SILVER), money, -1);
++n;
}
if (peasants) {
if (n >= size)
return -1;
report_resource(result + n, "peasant", peasants, -1);
report_resource(result + n, get_resourcetype(R_PEASANT), peasants, -1);
++n;
}
if (horses) {
if (n >= size)
return -1;
report_resource(result + n, "horse", horses, -1);
report_resource(result + n, get_resourcetype(R_HORSE), horses, -1);
++n;
}
if (saplings) {
if (n >= size)
return -1;
report_resource(result + n, mallorn ? "mallornsapling" : "sapling",
saplings, -1);
rtype = get_resourcetype(mallorn ? R_MALLORN_SAPLING : R_SAPLING);
report_resource(result + n, rtype, saplings, -1);
++n;
}
if (trees) {
if (n >= size)
return -1;
report_resource(result + n, mallorn ? "mallorn" : "tree", trees,
-1);
rtype = get_resourcetype(mallorn ? R_MALLORN_TREE : R_TREE);
report_resource(result + n, rtype, trees, -1);
++n;
}
}
@ -471,7 +472,7 @@ const faction * viewer, bool see_unit)
if (level >= 0 && visible >= 0) {
if (n >= size)
return -1;
report_resource(result + n, res->type->rtype->_name, visible, level);
report_resource(result + n, res->type->rtype, visible, level);
n++;
}
res = res->next;

View File

@ -107,7 +107,7 @@ extern "C" {
} arg_regions;
typedef struct resource_report {
const char *name;
const struct resource_type *rtype;
int number;
int level;
} resource_report;