diff --git a/src/kernel/race.c b/src/kernel/race.c index f28c5ed2f..decc3b7bb 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -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; -} diff --git a/src/kernel/race.h b/src/kernel/race.h index 022d09c86..6673676bd 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -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 } diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 4aff7d118..f06c4c252 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -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]; diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index c4b1f46ed..752627144 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -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; } diff --git a/src/names.c b/src/names.c index 99c21a05e..cf1cdb910 100644 --- a/src/names.c +++ b/src/names.c @@ -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) diff --git a/src/names.test.c b/src/names.test.c index f50937f17..8109fc2d4 100644 --- a/src/names.test.c +++ b/src/names.test.c @@ -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; }