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;
|
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,
|
void give_starting_equipment(const struct equipment *eq,
|
||||||
struct unit *u);
|
struct unit *u);
|
||||||
const char *dbrace(const struct race *rc);
|
const char *dbrace(const struct race *rc);
|
||||||
|
char * race_namegen(const struct race *rc, const struct unit *u);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -1414,10 +1414,10 @@ void default_name(const unit *u, char name[], int len) {
|
||||||
void name_unit(unit * u)
|
void name_unit(unit * u)
|
||||||
{
|
{
|
||||||
if (u_race(u)->generate_name) {
|
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) {
|
if (gen_name) {
|
||||||
free(u->_name);
|
free(u->_name);
|
||||||
u->_name = _strdup(gen_name);
|
u->_name = gen_name;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
unit_setname(u, racename(u->faction->locale, u, u_race(u)));
|
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)
|
static void count_particles(const char *monster, int *num_prefix, int *num_name, int *num_postfix)
|
||||||
{
|
{
|
||||||
const char *str;
|
|
||||||
char zText[32];
|
char zText[32];
|
||||||
if (*num_prefix == 0) {
|
const char *str;
|
||||||
|
|
||||||
for (*num_prefix = 0;; ++*num_prefix) {
|
for (*num_prefix = 0;; ++*num_prefix) {
|
||||||
sprintf(zText, "%s_prefix_%d", monster, *num_prefix);
|
sprintf(zText, "%s_prefix_%d", monster, *num_prefix);
|
||||||
|
@ -75,7 +74,6 @@ static void count_particles(const char *monster, int *num_prefix, int *num_name,
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *make_names(const char *monster, int *num_postfix,
|
static const char *make_names(const char *monster, int *num_postfix,
|
||||||
|
|
Loading…
Reference in New Issue