extract counting name particles.

This commit is contained in:
Enno Rehling 2016-08-28 19:00:04 +01:00
parent 0ac30c65a1
commit d1b6629281
1 changed files with 42 additions and 35 deletions

View File

@ -49,14 +49,10 @@ static const char *describe_braineater(unit * u, const struct locale *lang)
return LOC(lang, "describe_braineater"); return LOC(lang, "describe_braineater");
} }
static const char *make_names(const char *monster, int *num_postfix, static void count_particles(const char *monster, int *num_prefix, int *num_name, int *num_postfix)
int pprefix, int *num_name, int *num_prefix, int ppostfix)
{ {
int uv, uu, un;
static char name[NAMESIZE + 1]; // FIXME: static return value
char zText[32];
const char *str; const char *str;
char zText[32];
if (*num_prefix == 0) { if (*num_prefix == 0) {
for (*num_prefix = 0;; ++*num_prefix) { for (*num_prefix = 0;; ++*num_prefix) {
@ -80,48 +76,59 @@ static const char *make_names(const char *monster, int *num_postfix,
break; break;
} }
} }
}
static const char *make_names(const char *monster, int *num_postfix,
int pprefix, int *num_name, int *num_prefix, int ppostfix)
{
if (*num_name == 0) { if (*num_name == 0) {
return NULL; count_particles(monster, num_prefix, num_name, num_postfix);
} }
if (*num_name > 0) {
static char name[NAMESIZE + 1]; // FIXME: static return value
char zText[32];
int uv, uu, un;
const char *str;
/* nur 50% aller Namen haben "Vor-Teil" */ /* nur 50% aller Namen haben "Vor-Teil" */
uv = rng_int() % (*num_prefix * pprefix); uv = rng_int() % (*num_prefix * pprefix);
uu = rng_int() % *num_name; uu = rng_int() % *num_name;
/* nur 50% aller Namen haben "Nach-Teil", wenn kein Vor-Teil */ /* nur 50% aller Namen haben "Nach-Teil", wenn kein Vor-Teil */
if (*num_postfix > 0 && uv >= *num_prefix) { if (*num_postfix > 0 && uv >= *num_prefix) {
un = rng_int() % *num_postfix; un = rng_int() % *num_postfix;
} }
else { else {
un = rng_int() % (*num_postfix * ppostfix); un = rng_int() % (*num_postfix * ppostfix);
}
name[0] = 0;
if (uv < *num_prefix) {
sprintf(zText, "%s_prefix_%d", monster, uv);
str = locale_getstring(default_locale, zText);
if (str) {
size_t sz = strlcpy(name, (const char *)str, sizeof(name));
strlcpy(name + sz, " ", sizeof(name) - sz);
} }
}
sprintf(zText, "%s_name_%d", monster, uu); name[0] = 0;
str = locale_getstring(default_locale, zText); if (uv < *num_prefix) {
if (str) sprintf(zText, "%s_prefix_%d", monster, uv);
strlcat(name, (const char *)str, sizeof(name)); str = locale_getstring(default_locale, zText);
if (str) {
size_t sz = strlcpy(name, (const char *)str, sizeof(name));
strlcpy(name + sz, " ", sizeof(name) - sz);
}
}
if (un < *num_postfix) { sprintf(zText, "%s_name_%d", monster, uu);
sprintf(zText, "%s_postfix_%d", monster, un);
str = locale_getstring(default_locale, zText); str = locale_getstring(default_locale, zText);
if (str) { if (str)
strlcat(name, " ", sizeof(name));
strlcat(name, (const char *)str, sizeof(name)); strlcat(name, (const char *)str, sizeof(name));
if (un < *num_postfix) {
sprintf(zText, "%s_postfix_%d", monster, un);
str = locale_getstring(default_locale, zText);
if (str) {
strlcat(name, " ", sizeof(name));
strlcat(name, (const char *)str, sizeof(name));
}
} }
return name;
} }
return name; return NULL;
} }
static const char *undead_name(const unit * u) static const char *undead_name(const unit * u)