diff --git a/src/creport.c b/src/creport.c index c766ae872..ee7abcc87 100644 --- a/src/creport.c +++ b/src/creport.c @@ -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); } } diff --git a/src/creport.test.c b/src/creport.test.c index b329e2d22..aff170b01 100644 --- a/src/creport.test.c +++ b/src/creport.test.c @@ -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"); diff --git a/src/kernel/item.c b/src/kernel/item.c index 1fb90d456..48ea7a690 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -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; diff --git a/src/report.c b/src/report.c index 6e8d811bc..43a7ab514 100644 --- a/src/report.c +++ b/src/report.c @@ -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(); } diff --git a/src/reports.c b/src/reports.c index 737e4fc48..63e274265 100644 --- a/src/reports.c +++ b/src/reports.c @@ -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; diff --git a/src/reports.h b/src/reports.h index 855234376..6ce14e775 100644 --- a/src/reports.h +++ b/src/reports.h @@ -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;