forked from github/server
refactor to push back the const-ness of generated names.
This commit is contained in:
parent
d1b6629281
commit
0f3de70ced
|
@ -319,3 +319,12 @@ const char *dbrace(const struct race *rc)
|
|||
return zText;
|
||||
}
|
||||
|
||||
char * race_namegen(const struct race *rc, const struct unit *u) {
|
||||
if (rc->generate_name) {
|
||||
const char * str = rc->generate_name(u);
|
||||
if (str) {
|
||||
return _strdup(str);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -261,6 +261,7 @@ extern "C" {
|
|||
void give_starting_equipment(const struct equipment *eq,
|
||||
struct unit *u);
|
||||
const char *dbrace(const struct race *rc);
|
||||
char * race_namegen(const struct race *rc, const struct unit *u);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1414,10 +1414,10 @@ void default_name(const unit *u, char name[], int len) {
|
|||
void name_unit(unit * u)
|
||||
{
|
||||
if (u_race(u)->generate_name) {
|
||||
const char *gen_name = u_race(u)->generate_name(u);
|
||||
char *gen_name = race_namegen(u_race(u), u);
|
||||
if (gen_name) {
|
||||
free(u->_name);
|
||||
u->_name = _strdup(gen_name);
|
||||
u->_name = gen_name;
|
||||
}
|
||||
else {
|
||||
unit_setname(u, racename(u->faction->locale, u, u_race(u)));
|
||||
|
|
38
src/names.c
38
src/names.c
|
@ -51,30 +51,28 @@ static const char *describe_braineater(unit * u, const struct locale *lang)
|
|||
|
||||
static void count_particles(const char *monster, int *num_prefix, int *num_name, int *num_postfix)
|
||||
{
|
||||
const char *str;
|
||||
char zText[32];
|
||||
if (*num_prefix == 0) {
|
||||
const char *str;
|
||||
|
||||
for (*num_prefix = 0;; ++*num_prefix) {
|
||||
sprintf(zText, "%s_prefix_%d", monster, *num_prefix);
|
||||
str = locale_getstring(default_locale, zText);
|
||||
if (str == NULL)
|
||||
break;
|
||||
}
|
||||
for (*num_prefix = 0;; ++*num_prefix) {
|
||||
sprintf(zText, "%s_prefix_%d", monster, *num_prefix);
|
||||
str = locale_getstring(default_locale, zText);
|
||||
if (str == NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
for (*num_name = 0;; ++*num_name) {
|
||||
sprintf(zText, "%s_name_%d", monster, *num_name);
|
||||
str = locale_getstring(default_locale, zText);
|
||||
if (str == NULL)
|
||||
break;
|
||||
}
|
||||
for (*num_name = 0;; ++*num_name) {
|
||||
sprintf(zText, "%s_name_%d", monster, *num_name);
|
||||
str = locale_getstring(default_locale, zText);
|
||||
if (str == NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
for (*num_postfix = 0;; ++*num_postfix) {
|
||||
sprintf(zText, "%s_postfix_%d", monster, *num_postfix);
|
||||
str = locale_getstring(default_locale, zText);
|
||||
if (str == NULL)
|
||||
break;
|
||||
}
|
||||
for (*num_postfix = 0;; ++*num_postfix) {
|
||||
sprintf(zText, "%s_postfix_%d", monster, *num_postfix);
|
||||
str = locale_getstring(default_locale, zText);
|
||||
if (str == NULL)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue