This commit is contained in:
Enno Rehling 2017-03-11 12:25:56 +01:00
commit de0a697ddb
4 changed files with 87 additions and 27 deletions

View File

@ -484,13 +484,13 @@
</string>
<string name="mallorntree">
<text locale="de">Mallornbaum</text>
<text locale="en">mallorn tree</text>
<text locale="de">Mallorn</text>
<text locale="en">mallorn</text>
</string>
<string name="mallorntree_p">
<text locale="de">Mallornbäume</text>
<text locale="en">mallorn trees</text>
<text locale="de">Mallorn</text>
<text locale="en">mallorn</text>
</string>
<!--Küsten -->

View File

@ -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);

View File

@ -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;
}

View File

@ -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) {