forked from github/server
units without a name will use their race as a default name.
This commit is contained in:
parent
3428f40f81
commit
9394c4324e
|
@ -1850,7 +1850,12 @@ static int nextbuf = 0;
|
||||||
|
|
||||||
char *write_unitname(const unit * u, char *buffer, size_t size)
|
char *write_unitname(const unit * u, char *buffer, size_t size)
|
||||||
{
|
{
|
||||||
slprintf(buffer, size, "%s (%s)", (const char *)u->name, itoa36(u->no));
|
if (u->name) {
|
||||||
|
slprintf(buffer, size, "%s (%s)", u->name, itoa36(u->no));
|
||||||
|
} else {
|
||||||
|
const char * name = rc_name(u->_race, u->number == 1 ? NAME_SINGULAR : NAME_PLURAL);
|
||||||
|
slprintf(buffer, size, "%s (%s)", locale_string(u->faction->locale, name), itoa36(u->no));
|
||||||
|
}
|
||||||
buffer[size - 1] = 0;
|
buffer[size - 1] = 0;
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
|
#include <util/base36.h>
|
||||||
|
#include <util/language.h>
|
||||||
#include "alchemy.h"
|
#include "alchemy.h"
|
||||||
#include "faction.h"
|
#include "faction.h"
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
|
@ -10,7 +12,9 @@
|
||||||
#include <CuTest.h>
|
#include <CuTest.h>
|
||||||
#include <tests.h>
|
#include <tests.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
static void test_remove_empty_units(CuTest *tc) {
|
static void test_remove_empty_units(CuTest *tc) {
|
||||||
|
@ -123,10 +127,48 @@ static void test_scale_number(CuTest *tc) {
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_unit_name(CuTest *tc) {
|
||||||
|
unit *u;
|
||||||
|
char name[32];
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
test_create_world();
|
||||||
|
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
|
||||||
|
unit_setname(u, "Hodor");
|
||||||
|
_snprintf(name, sizeof(name), "Hodor (%s)", itoa36(u->no));
|
||||||
|
CuAssertStrEquals(tc, name, unitname(u));
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_unit_name_from_race(CuTest *tc) {
|
||||||
|
unit *u;
|
||||||
|
char name[32];
|
||||||
|
struct locale *lang;
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
test_create_world();
|
||||||
|
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
|
||||||
|
unit_setname(u, NULL);
|
||||||
|
lang = get_or_create_locale("de");
|
||||||
|
locale_setstring(lang, rc_name(u->_race, NAME_SINGULAR), "Mensch");
|
||||||
|
locale_setstring(lang, rc_name(u->_race, NAME_PLURAL), "Menschen");
|
||||||
|
|
||||||
|
_snprintf(name, sizeof(name), "Mensch (%s)", itoa36(u->no));
|
||||||
|
CuAssertStrEquals(tc, name, unitname(u));
|
||||||
|
|
||||||
|
u->number = 2;
|
||||||
|
_snprintf(name, sizeof(name), "Menschen (%s)", itoa36(u->no));
|
||||||
|
CuAssertStrEquals(tc, name, unitname(u));
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
CuSuite *get_unit_suite(void)
|
CuSuite *get_unit_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
SUITE_ADD_TEST(suite, test_scale_number);
|
SUITE_ADD_TEST(suite, test_scale_number);
|
||||||
|
SUITE_ADD_TEST(suite, test_unit_name);
|
||||||
|
SUITE_ADD_TEST(suite, test_unit_name_from_race);
|
||||||
SUITE_ADD_TEST(suite, test_remove_empty_units);
|
SUITE_ADD_TEST(suite, test_remove_empty_units);
|
||||||
SUITE_ADD_TEST(suite, test_remove_units_ignores_spells);
|
SUITE_ADD_TEST(suite, test_remove_units_ignores_spells);
|
||||||
SUITE_ADD_TEST(suite, test_remove_units_without_faction);
|
SUITE_ADD_TEST(suite, test_remove_units_without_faction);
|
||||||
|
|
Loading…
Reference in New Issue