From 8b9f0f08942ef60bed449123cdf5c8843945d434 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 10 Mar 2017 23:18:09 +0100 Subject: [PATCH] BUG 2307: report mallorn trees as Mallorn in the CR. for legacy compatibility, we cannot call them Mallornbaeume. --- res/core/de/strings.xml | 8 ++--- src/creport.c | 8 +++-- src/creport.test.c | 70 ++++++++++++++++++++++++++++++++++++----- src/reports.c | 28 ++++++++--------- 4 files changed, 87 insertions(+), 27 deletions(-) diff --git a/res/core/de/strings.xml b/res/core/de/strings.xml index d69c0919f..a39657580 100644 --- a/res/core/de/strings.xml +++ b/res/core/de/strings.xml @@ -484,13 +484,13 @@ - Mallornbaum - mallorn tree + Mallorn + mallorn - Mallornbäume - mallorn trees + Mallorn + mallorn diff --git a/src/creport.c b/src/creport.c index f22096f19..d16f87f22 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1094,12 +1094,16 @@ static void cr_reportspell(FILE * F, spell * sp, int level, const struct locale static char *cr_output_resource(char *buf, const resource_type *rtype, const struct locale *loc, int amount, int level) { - const char * name; + const char *name, *tname; assert(rtype); name = resourcename(rtype, 1); assert(name); buf += sprintf(buf, "RESOURCE %u\n", hashstring(rtype->_name)); - buf += sprintf(buf, "\"%s\";type\n", translate(name, LOC(loc, rtype->_name))); + tname = LOC(loc, rtype->_name); + assert(tname); + tname = translate(name, tname); + assert(tname); + buf += sprintf(buf, "\"%s\";type\n", tname); if (amount >= 0) { if (level >= 0) buf += sprintf(buf, "%d;skill\n", level); diff --git a/src/creport.test.c b/src/creport.test.c index acd6201f9..46e6e6967 100644 --- a/src/creport.test.c +++ b/src/creport.test.c @@ -50,11 +50,7 @@ static void test_cr_unit(CuTest *tc) { test_cleanup(); } -static void test_cr_resources(CuTest *tc) { - stream strm; - char line[1024]; - faction *f; - region *r; +static void setup_resources(void) { struct locale *lang; test_setup(); @@ -70,6 +66,19 @@ static void test_cr_resources(CuTest *tc) { locale_setstring(lang, "tree_p", "Blumen"); locale_setstring(lang, "sapling", "Schoessling"); locale_setstring(lang, "sapling_p", "Schoesslinge"); + locale_setstring(lang, "mallornsapling", "Mallornschoessling"); + locale_setstring(lang, "mallornsapling_p", "Mallornschoesslinge"); + locale_setstring(lang, "mallorntree", "Mallorn"); + locale_setstring(lang, "mallorntree_p", "Mallorn"); +} + +static void test_cr_resources(CuTest *tc) { + stream strm; + char line[1024]; + faction *f; + region *r; + + setup_resources(); f = test_create_faction(0); r = test_create_region(0, 0, 0); @@ -88,6 +97,20 @@ static void test_cr_resources(CuTest *tc) { CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); CuAssertStrEquals(tc, "2;Schoesslinge", line); + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); + CuAssertIntEquals(tc, 0, memcmp(line, "RESOURCE ", 9)); + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); + CuAssertStrEquals(tc, "\"Schoesslinge\";type", line); + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); + CuAssertStrEquals(tc, "2;number", line); + + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); + CuAssertIntEquals(tc, 0, memcmp(line, "RESOURCE ", 9)); + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); + CuAssertStrEquals(tc, "\"Blumen\";type", line); + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); + CuAssertStrEquals(tc, "3;number", line); + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); CuAssertIntEquals(tc, 0, memcmp(line, "RESOURCE ", 9)); CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); @@ -109,17 +132,49 @@ static void test_cr_resources(CuTest *tc) { CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); CuAssertStrEquals(tc, "1;number", line); + mstream_done(&strm); + test_cleanup(); +} + +static void test_cr_mallorn(CuTest *tc) { + stream strm; + char line[1024]; + faction *f; + region *r; + + setup_resources(); + + f = test_create_faction(0); + r = test_create_region(0, 0, 0); + r->land->horses = 1; + r->land->peasants = 200; + r->land->money = 300; + r->flags |= RF_MALLORN; + rsettrees(r, 0, 1); + rsettrees(r, 1, 2); + rsettrees(r, 2, 3); + + mstream_init(&strm); + cr_output_resources(&strm, f, r, false); + strm.api->rewind(strm.handle); + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); + CuAssertStrEquals(tc, "3;Baeume", line); + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); + CuAssertStrEquals(tc, "2;Schoesslinge", line); + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); + CuAssertStrEquals(tc, "1;Mallorn", line); + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); CuAssertIntEquals(tc, 0, memcmp(line, "RESOURCE ", 9)); CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); - CuAssertStrEquals(tc, "\"Schoesslinge\";type", line); + CuAssertStrEquals(tc, "\"Mallornschoesslinge\";type", line); CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); CuAssertStrEquals(tc, "2;number", line); CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); CuAssertIntEquals(tc, 0, memcmp(line, "RESOURCE ", 9)); CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); - CuAssertStrEquals(tc, "\"Blumen\";type", line); + CuAssertStrEquals(tc, "\"Mallorn\";type", line); CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); CuAssertStrEquals(tc, "3;number", line); @@ -247,6 +302,7 @@ CuSuite *get_creport_suite(void) CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_cr_unit); SUITE_ADD_TEST(suite, test_cr_resources); + SUITE_ADD_TEST(suite, test_cr_mallorn); SUITE_ADD_TEST(suite, test_cr_factionstealth); return suite; } diff --git a/src/reports.c b/src/reports.c index 85ab34209..c23809a32 100644 --- a/src/reports.c +++ b/src/reports.c @@ -410,6 +410,20 @@ const faction * viewer, bool see_unit) bool mallorn = fval(r, RF_MALLORN) != 0; const resource_type *rtype; + if (saplings) { + if (n >= size) + return -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; + rtype = get_resourcetype(mallorn ? R_MALLORN_TREE : R_TREE); + report_resource(result + n, rtype, trees, -1); + ++n; + } if (money) { if (n >= size) return -1; @@ -428,20 +442,6 @@ const faction * viewer, bool see_unit) report_resource(result + n, get_resourcetype(R_HORSE), horses, -1); ++n; } - if (saplings) { - if (n >= size) - return -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; - rtype = get_resourcetype(mallorn ? R_MALLORN_TREE : R_TREE); - report_resource(result + n, rtype, trees, -1); - ++n; - } } if (see_unit) {