BUG 2315: always use plural for resources

This commit is contained in:
Enno Rehling 2017-03-26 20:25:01 +02:00
parent 8b87eb608f
commit 406f8ca3e6
2 changed files with 28 additions and 3 deletions

View File

@ -1184,7 +1184,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) {
const char * name = resourcename(result[n].rtype, result[n].number != 1);
const char * name = resourcename(result[n].rtype, 1);
assert(name);
stream_printf(out, "%d;%s\n", result[n].number, crtag(name));
}

View File

@ -11,6 +11,7 @@
#include <kernel/item.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/resources.h>
#include <kernel/ship.h>
#include <kernel/unit.h>
#include <kernel/spell.h>
@ -52,8 +53,15 @@ static void test_cr_unit(CuTest *tc) {
static void setup_resources(void) {
struct locale *lang;
item_type *itype;
test_setup();
itype = it_get_or_create(rt_get_or_create("stone"));
itype->rtype->flags = RTF_LIMITED | RTF_POOLED;
itype->construction = calloc(1, sizeof(construction));
itype->construction->skill = SK_QUARRYING;
itype->construction->minskill = 1;
rmt_create(itype->rtype);
init_resources();
lang = get_or_create_locale("de"); /* CR tags are translated from this */
locale_setstring(lang, "money", "Silber");
@ -62,6 +70,8 @@ static void setup_resources(void) {
locale_setstring(lang, "horse_p", "Pferde");
locale_setstring(lang, "peasant", "Bauer");
locale_setstring(lang, "peasant_p", "Bauern");
locale_setstring(lang, "stone", "Stein");
locale_setstring(lang, "stone_p", "Steine");
locale_setstring(lang, "tree", "Blume");
locale_setstring(lang, "tree_p", "Blumen");
locale_setstring(lang, "sapling", "Schoessling");
@ -77,25 +87,31 @@ static void test_cr_resources(CuTest *tc) {
char line[1024];
faction *f;
region *r;
unit *u;
setup_resources();
f = test_create_faction(0);
r = test_create_region(0, 0, 0);
u = test_create_unit(f, r);
set_level(u, SK_QUARRYING, 1);
r->land->horses = 1;
r->land->peasants = 200;
r->land->money = 300;
rsettrees(r, 0, 1);
rsettrees(r, 1, 2);
rsettrees(r, 2, 3);
region_setresource(r, get_resourcetype(R_STONE), 1);
mstream_init(&strm);
cr_output_resources(&strm, f, r, false);
cr_output_resources(&strm, f, r, true);
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;Steine", line);
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
CuAssertIntEquals(tc, 0, memcmp(line, "RESOURCE ", 9));
@ -132,6 +148,15 @@ static void test_cr_resources(CuTest *tc) {
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
CuAssertStrEquals(tc, "1;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, "\"Steine\";type", line);
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
CuAssertStrEquals(tc, "1;skill", line);
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
CuAssertStrEquals(tc, "1;number", line);
mstream_done(&strm);
test_cleanup();
}