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)));
|
||||
|
|
|
@ -51,9 +51,8 @@ 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);
|
||||
|
@ -76,7 +75,6 @@ static void count_particles(const char *monster, int *num_prefix, int *num_name,
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const char *make_names(const char *monster, int *num_postfix,
|
||||
int pprefix, int *num_name, int *num_prefix, int ppostfix)
|
||||
|
|
Loading…
Reference in New Issue