forked from github/server
Merge pull request #618 from ennorehling/2268-name_unit
BUG 2268: monster names
This commit is contained in:
commit
fa52e92f3e
|
@ -369,10 +369,3 @@ void register_race_description_function(race_desc_func func, const char *name) {
|
|||
void register_race_name_function(race_name_func func, const char *name) {
|
||||
register_function((pf_generic)func, name);
|
||||
}
|
||||
|
||||
char * race_namegen(const struct race *rc, struct unit *u) {
|
||||
if (rc->generate_name) {
|
||||
rc->generate_name(u);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -252,7 +252,6 @@ extern "C" {
|
|||
const char *raceprefix(const struct unit *u);
|
||||
void register_race_name_function(race_name_func, const char *);
|
||||
void register_race_description_function(race_desc_func, const char *);
|
||||
char * race_namegen(const struct race *rc, struct unit *u);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1480,15 +1480,9 @@ void default_name(const unit *u, char name[], int len) {
|
|||
|
||||
void name_unit(unit * u)
|
||||
{
|
||||
if (u_race(u)->generate_name) {
|
||||
char *gen_name = race_namegen(u_race(u), u);
|
||||
if (gen_name) {
|
||||
free(u->_name);
|
||||
u->_name = gen_name;
|
||||
}
|
||||
else {
|
||||
unit_setname(u, racename(u->faction->locale, u, u_race(u)));
|
||||
}
|
||||
const race *rc = u_race(u);
|
||||
if (rc->generate_name) {
|
||||
rc->generate_name(u);
|
||||
}
|
||||
else {
|
||||
char name[32];
|
||||
|
|
|
@ -468,6 +468,24 @@ static void test_renumber_unit(CuTest *tc) {
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
static void gen_name(unit *u)
|
||||
{
|
||||
unit_setname(u, "Hodor");
|
||||
}
|
||||
|
||||
static void test_name_unit(CuTest *tc) {
|
||||
race *rc;
|
||||
unit * u;
|
||||
|
||||
test_setup();
|
||||
rc = test_create_race("skeleton");
|
||||
u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0));
|
||||
rc->generate_name = gen_name;
|
||||
name_unit(u);
|
||||
CuAssertStrEquals(tc, "Hodor", unit_getname(u));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
CuSuite *get_unit_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
|
@ -491,5 +509,6 @@ CuSuite *get_unit_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_inside_building);
|
||||
SUITE_ADD_TEST(suite, test_limited_skills);
|
||||
SUITE_ADD_TEST(suite, test_renumber_unit);
|
||||
SUITE_ADD_TEST(suite, test_name_unit);
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -221,11 +221,7 @@ const char *silbe3[SIL3] = {
|
|||
|
||||
static void generic_name(unit * u)
|
||||
{
|
||||
const char * name = rc_name_s(u_race(u), (u->number == 1) ? NAME_SINGULAR : NAME_PLURAL);
|
||||
name = LOC(u->faction->locale, name);
|
||||
if (name) {
|
||||
unit_setname(u, name);
|
||||
}
|
||||
unit_setname(u, NULL);
|
||||
}
|
||||
|
||||
static void dragon_name(unit * u)
|
||||
|
|
|
@ -24,7 +24,7 @@ static void test_names(CuTest * tc)
|
|||
locale_setstring(default_locale, "undead_postfix_0", "Kobolde");
|
||||
CuAssertPtrNotNull(tc, foo = (race_name_func)get_function("nameundead"));
|
||||
rc->generate_name = foo;
|
||||
race_namegen(rc, u);
|
||||
rc->generate_name(u);
|
||||
CuAssertStrEquals(tc, "Graue Kobolde", u->_name);
|
||||
CuAssertPtrNotNull(tc, get_function("nameskeleton"));
|
||||
CuAssertPtrNotNull(tc, get_function("namezombie"));
|
||||
|
@ -36,9 +36,31 @@ static void test_names(CuTest * tc)
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_monster_names(CuTest *tc) {
|
||||
unit *u;
|
||||
race *rc;
|
||||
|
||||
test_setup();
|
||||
register_names();
|
||||
default_locale = test_create_locale();
|
||||
locale_setstring(default_locale, "race::irongolem", "Eisengolem");
|
||||
locale_setstring(default_locale, "race::irongolem_p", "Eisengolems");
|
||||
rc = test_create_race("irongolem");
|
||||
u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0));
|
||||
CuAssertPtrNotNull(tc, u->_name);
|
||||
rc->generate_name = (race_name_func)get_function("namegeneric");
|
||||
rc->generate_name(u);
|
||||
CuAssertPtrEquals(tc, 0, u->_name);
|
||||
CuAssertStrEquals(tc, "Eisengolem", unit_getname(u));
|
||||
u->number = 2;
|
||||
CuAssertStrEquals(tc, "Eisengolems", unit_getname(u));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
CuSuite *get_names_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_names);
|
||||
SUITE_ADD_TEST(suite, test_monster_names);
|
||||
return suite;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue