2010-08-08 10:06:34 +02:00
|
|
|
|
/*
|
2015-01-30 22:10:29 +01:00
|
|
|
|
Copyright (c) 1998-2015, Enno Rehling <enno@eressea.de>
|
2014-08-24 21:49:55 +02:00
|
|
|
|
Katja Zedel <katze@felidae.kn-bremen.de
|
|
|
|
|
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
#include <platform.h>
|
|
|
|
|
#include <kernel/config.h>
|
|
|
|
|
#include "names.h"
|
|
|
|
|
|
|
|
|
|
/* kernel includes */
|
2014-08-27 06:40:18 +02:00
|
|
|
|
#include <kernel/unit.h>
|
2016-08-28 21:02:45 +02:00
|
|
|
|
#include <kernel/race.h>
|
2014-08-27 06:40:18 +02:00
|
|
|
|
#include <kernel/region.h>
|
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
|
#include <kernel/race.h>
|
|
|
|
|
#include <kernel/terrain.h>
|
|
|
|
|
#include <kernel/terrainid.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
/* util includes */
|
|
|
|
|
#include <util/base36.h>
|
|
|
|
|
#include <util/bsdstring.h>
|
|
|
|
|
#include <util/language.h>
|
2016-08-28 21:02:45 +02:00
|
|
|
|
#include <util/functions.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <util/rng.h>
|
|
|
|
|
#include <util/unicode.h>
|
|
|
|
|
|
|
|
|
|
/* libc includes */
|
2012-06-04 03:41:07 +02:00
|
|
|
|
#include <assert.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <ctype.h>
|
|
|
|
|
#include <wctype.h>
|
|
|
|
|
#include <stdlib.h>
|
2014-03-15 19:29:11 +01:00
|
|
|
|
#include <stdio.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2016-08-28 21:44:09 +02:00
|
|
|
|
static const char *describe_race(const race * rc, const struct locale *lang)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2016-08-28 21:44:09 +02:00
|
|
|
|
char zText[32];
|
|
|
|
|
sprintf(zText, "describe_%s", rc->_name);
|
|
|
|
|
return LOC(lang, zText);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-28 20:00:04 +02:00
|
|
|
|
static void count_particles(const char *monster, int *num_prefix, int *num_name, int *num_postfix)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2016-08-28 20:00:04 +02:00
|
|
|
|
char zText[32];
|
2016-08-28 20:06:14 +02:00
|
|
|
|
const char *str;
|
2014-08-24 21:49:55 +02:00
|
|
|
|
|
2016-08-28 20:06:14 +02:00
|
|
|
|
for (*num_prefix = 0;; ++*num_prefix) {
|
|
|
|
|
sprintf(zText, "%s_prefix_%d", monster, *num_prefix);
|
|
|
|
|
str = locale_getstring(default_locale, zText);
|
|
|
|
|
if (str == NULL)
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-08-24 21:49:55 +02:00
|
|
|
|
|
2016-08-28 20:06:14 +02:00
|
|
|
|
for (*num_name = 0;; ++*num_name) {
|
|
|
|
|
sprintf(zText, "%s_name_%d", monster, *num_name);
|
|
|
|
|
str = locale_getstring(default_locale, zText);
|
|
|
|
|
if (str == NULL)
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-08-24 21:49:55 +02:00
|
|
|
|
|
2016-08-28 20:06:14 +02:00
|
|
|
|
for (*num_postfix = 0;; ++*num_postfix) {
|
|
|
|
|
sprintf(zText, "%s_postfix_%d", monster, *num_postfix);
|
|
|
|
|
str = locale_getstring(default_locale, zText);
|
|
|
|
|
if (str == NULL)
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2016-08-28 20:00:04 +02:00
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2016-08-28 21:31:25 +02:00
|
|
|
|
static void make_name(unit *u, const char *monster, int *num_postfix,
|
2016-08-28 20:00:04 +02:00
|
|
|
|
int pprefix, int *num_name, int *num_prefix, int ppostfix)
|
|
|
|
|
{
|
2014-08-24 21:49:55 +02:00
|
|
|
|
if (*num_name == 0) {
|
2016-08-28 20:00:04 +02:00
|
|
|
|
count_particles(monster, num_prefix, num_name, num_postfix);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2016-08-28 20:00:04 +02:00
|
|
|
|
if (*num_name > 0) {
|
2016-08-30 08:56:40 +02:00
|
|
|
|
char name[NAMESIZE + 1];
|
2016-08-28 20:00:04 +02:00
|
|
|
|
char zText[32];
|
2016-08-28 21:27:40 +02:00
|
|
|
|
int uv = 0, uu = 0, un = 0;
|
2016-08-28 20:00:04 +02:00
|
|
|
|
const char *str;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2016-08-28 21:27:40 +02:00
|
|
|
|
if (*num_prefix > 0) {
|
|
|
|
|
uv = rng_int() % (*num_prefix * pprefix);
|
|
|
|
|
}
|
2016-08-28 20:00:04 +02:00
|
|
|
|
uu = rng_int() % *num_name;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2016-08-28 20:00:04 +02:00
|
|
|
|
if (*num_postfix > 0 && uv >= *num_prefix) {
|
|
|
|
|
un = rng_int() % *num_postfix;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
un = rng_int() % (*num_postfix * ppostfix);
|
2014-08-24 21:49:55 +02:00
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2016-08-28 20:00:04 +02:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-24 21:49:55 +02:00
|
|
|
|
|
2016-08-28 20:00:04 +02:00
|
|
|
|
sprintf(zText, "%s_name_%d", monster, uu);
|
2014-08-24 21:49:55 +02:00
|
|
|
|
str = locale_getstring(default_locale, zText);
|
2016-08-28 20:00:04 +02:00
|
|
|
|
if (str)
|
2015-10-30 11:02:51 +01:00
|
|
|
|
strlcat(name, (const char *)str, sizeof(name));
|
2016-08-28 20:00:04 +02:00
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
}
|
2014-08-24 21:49:55 +02:00
|
|
|
|
}
|
2016-08-28 21:31:25 +02:00
|
|
|
|
unit_setname(u, name);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-28 21:27:40 +02:00
|
|
|
|
static void undead_name(unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-08-24 21:49:55 +02:00
|
|
|
|
static int num_postfix, num_name, num_prefix;
|
2016-08-28 21:31:25 +02:00
|
|
|
|
make_name(u, "undead", &num_postfix, 2, &num_name, &num_prefix, 2);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-28 21:27:40 +02:00
|
|
|
|
static void skeleton_name(unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-08-24 21:49:55 +02:00
|
|
|
|
static int num_postfix, num_name, num_prefix;
|
2016-08-28 21:31:25 +02:00
|
|
|
|
make_name(u, "skeleton", &num_postfix, 5, &num_name, &num_prefix, 2);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-28 21:27:40 +02:00
|
|
|
|
static void zombie_name(unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-08-24 21:49:55 +02:00
|
|
|
|
static int num_postfix, num_name, num_prefix;
|
2016-08-28 21:31:25 +02:00
|
|
|
|
make_name(u, "zombie", &num_postfix, 5, &num_name, &num_prefix, 2);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-28 21:27:40 +02:00
|
|
|
|
static void ghoul_name(unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-08-24 21:49:55 +02:00
|
|
|
|
static int num_postfix, num_name, num_prefix;
|
2016-08-28 21:31:25 +02:00
|
|
|
|
make_name(u, "ghoul", &num_postfix, 5, &num_name, &num_prefix, 4);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Drachen */
|
|
|
|
|
|
|
|
|
|
#define SIL1 15
|
|
|
|
|
|
|
|
|
|
const char *silbe1[SIL1] = {
|
2014-08-24 21:49:55 +02:00
|
|
|
|
"Tar",
|
|
|
|
|
"Ter",
|
|
|
|
|
"Tor",
|
|
|
|
|
"Pan",
|
|
|
|
|
"Par",
|
|
|
|
|
"Per",
|
|
|
|
|
"Nim",
|
|
|
|
|
"Nan",
|
|
|
|
|
"Nun",
|
|
|
|
|
"Gor",
|
|
|
|
|
"For",
|
|
|
|
|
"Fer",
|
|
|
|
|
"Kar",
|
|
|
|
|
"Kur",
|
|
|
|
|
"Pen",
|
2010-08-08 10:06:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define SIL2 19
|
|
|
|
|
|
|
|
|
|
const char *silbe2[SIL2] = {
|
2014-08-24 21:49:55 +02:00
|
|
|
|
"da",
|
|
|
|
|
"do",
|
|
|
|
|
"dil",
|
|
|
|
|
"di",
|
|
|
|
|
"dor",
|
|
|
|
|
"dar",
|
|
|
|
|
"ra",
|
|
|
|
|
"ran",
|
|
|
|
|
"ras",
|
|
|
|
|
"ro",
|
|
|
|
|
"rum",
|
|
|
|
|
"rin",
|
|
|
|
|
"ten",
|
|
|
|
|
"tan",
|
|
|
|
|
"ta",
|
|
|
|
|
"tor",
|
|
|
|
|
"gur",
|
|
|
|
|
"ga",
|
|
|
|
|
"gas",
|
2010-08-08 10:06:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define SIL3 14
|
|
|
|
|
|
|
|
|
|
const char *silbe3[SIL3] = {
|
2014-08-24 21:49:55 +02:00
|
|
|
|
"gul",
|
|
|
|
|
"gol",
|
|
|
|
|
"dol",
|
|
|
|
|
"tan",
|
|
|
|
|
"tar",
|
|
|
|
|
"tur",
|
|
|
|
|
"sur",
|
|
|
|
|
"sin",
|
|
|
|
|
"kur",
|
|
|
|
|
"kor",
|
|
|
|
|
"kar",
|
|
|
|
|
"dul",
|
|
|
|
|
"dol",
|
|
|
|
|
"bus",
|
2010-08-08 10:06:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
2016-08-28 21:27:40 +02:00
|
|
|
|
static void generic_name(unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2015-02-11 22:41:10 +01:00
|
|
|
|
const char * name = rc_name_s(u_race(u), (u->number == 1) ? NAME_SINGULAR : NAME_PLURAL);
|
2016-08-28 21:27:40 +02:00
|
|
|
|
name = LOC(u->faction->locale, name);
|
|
|
|
|
if (name) {
|
|
|
|
|
unit_setname(u, name);
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-28 21:27:40 +02:00
|
|
|
|
static void dragon_name(unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2016-08-28 21:27:40 +02:00
|
|
|
|
char name[NAMESIZE + 1];
|
2014-08-24 21:49:55 +02:00
|
|
|
|
int rnd, ter = 0;
|
|
|
|
|
int anzahl = 1;
|
|
|
|
|
static int num_postfix;
|
|
|
|
|
char zText[32];
|
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
|
|
if (num_postfix == 0) {
|
|
|
|
|
for (num_postfix = 0;; ++num_postfix) {
|
|
|
|
|
sprintf(zText, "dragon_postfix_%d", num_postfix);
|
|
|
|
|
str = locale_getstring(default_locale, zText);
|
|
|
|
|
if (str == NULL)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (num_postfix == 0)
|
|
|
|
|
num_postfix = -1;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2014-08-24 21:49:55 +02:00
|
|
|
|
|
|
|
|
|
if (u) {
|
|
|
|
|
region *r = u->region;
|
|
|
|
|
anzahl = u->number;
|
|
|
|
|
switch (rterrain(r)) {
|
|
|
|
|
case T_PLAIN:
|
|
|
|
|
ter = 1;
|
|
|
|
|
break;
|
|
|
|
|
case T_MOUNTAIN:
|
|
|
|
|
ter = 2;
|
|
|
|
|
break;
|
|
|
|
|
case T_DESERT:
|
|
|
|
|
ter = 3;
|
|
|
|
|
break;
|
|
|
|
|
case T_SWAMP:
|
|
|
|
|
ter = 4;
|
|
|
|
|
break;
|
|
|
|
|
case T_GLACIER:
|
|
|
|
|
ter = 5;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2014-08-24 21:49:55 +02:00
|
|
|
|
|
2015-11-04 12:59:03 +01:00
|
|
|
|
if (num_postfix <=0) {
|
2016-08-28 21:27:40 +02:00
|
|
|
|
return;
|
2015-11-04 12:59:03 +01:00
|
|
|
|
}
|
|
|
|
|
else if (num_postfix < 6) {
|
|
|
|
|
rnd = rng_int() % num_postfix;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
rnd = num_postfix / 6;
|
|
|
|
|
rnd = (rng_int() % rnd) + ter * rnd;
|
|
|
|
|
}
|
2014-08-24 21:49:55 +02:00
|
|
|
|
sprintf(zText, "dragon_postfix_%d", rnd);
|
|
|
|
|
|
|
|
|
|
str = locale_getstring(default_locale, zText);
|
|
|
|
|
assert(str != NULL);
|
|
|
|
|
|
|
|
|
|
if (anzahl > 1) {
|
|
|
|
|
const char *no_article = strchr((const char *)str, ' ');
|
|
|
|
|
assert(no_article);
|
2015-01-10 17:05:10 +01:00
|
|
|
|
// TODO: localization
|
2014-08-24 21:49:55 +02:00
|
|
|
|
sprintf(name, "Die %sn von %s", no_article + 1, rname(u->region,
|
|
|
|
|
default_locale));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
char n[32];
|
2015-10-30 11:06:24 +01:00
|
|
|
|
size_t sz;
|
2014-08-24 21:49:55 +02:00
|
|
|
|
|
2015-10-30 11:06:24 +01:00
|
|
|
|
sz = strlcpy(n, silbe1[rng_int() % SIL1], sizeof(n));
|
|
|
|
|
sz += strlcat(n, silbe2[rng_int() % SIL2], sizeof(n));
|
|
|
|
|
sz += strlcat(n, silbe3[rng_int() % SIL3], sizeof(n));
|
2014-08-24 21:49:55 +02:00
|
|
|
|
if (rng_int() % 5 > 2) {
|
|
|
|
|
sprintf(name, "%s, %s", n, str); /* "Name, der Titel" */
|
|
|
|
|
}
|
|
|
|
|
else {
|
2015-10-30 11:06:24 +01:00
|
|
|
|
sz = strlcpy(name, (const char *)str, sizeof(name)); /* "Der Titel Name" */
|
2014-08-24 21:49:55 +02:00
|
|
|
|
name[0] = (char)toupper(name[0]); /* TODO: UNICODE - should use towupper() */
|
2015-10-30 11:06:24 +01:00
|
|
|
|
sz += strlcat(name, " ", sizeof(name));
|
|
|
|
|
sz += strlcat(name, n, sizeof(name));
|
2014-08-24 21:49:55 +02:00
|
|
|
|
}
|
|
|
|
|
if (u && (rng_int() % 3 == 0)) {
|
2015-10-30 11:06:24 +01:00
|
|
|
|
sz += strlcat(name, " von ", sizeof(name));
|
|
|
|
|
sz += strlcat(name, (const char *)rname(u->region, default_locale), sizeof(name));
|
2014-08-24 21:49:55 +02:00
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-28 21:27:40 +02:00
|
|
|
|
unit_setname(u, name);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Dracoide */
|
|
|
|
|
|
|
|
|
|
#define DRAC_PRE 13
|
|
|
|
|
static const char *drac_pre[DRAC_PRE] = {
|
2014-08-24 21:49:55 +02:00
|
|
|
|
"Siss",
|
|
|
|
|
"Xxaa",
|
|
|
|
|
"Shht",
|
|
|
|
|
"X'xixi",
|
|
|
|
|
"Xar",
|
|
|
|
|
"X'zish",
|
|
|
|
|
"X",
|
|
|
|
|
"Sh",
|
|
|
|
|
"R",
|
|
|
|
|
"Z",
|
|
|
|
|
"Y",
|
|
|
|
|
"L",
|
|
|
|
|
"Ck",
|
2010-08-08 10:06:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define DRAC_MID 12
|
|
|
|
|
static const char *drac_mid[DRAC_MID] = {
|
2014-08-24 21:49:55 +02:00
|
|
|
|
"siss",
|
|
|
|
|
"xxaa",
|
|
|
|
|
"shht",
|
|
|
|
|
"xxi",
|
|
|
|
|
"xar",
|
|
|
|
|
"x'zish",
|
|
|
|
|
"x",
|
|
|
|
|
"sh",
|
|
|
|
|
"r",
|
|
|
|
|
"z'ck",
|
|
|
|
|
"y",
|
|
|
|
|
"rl"
|
2010-08-08 10:06:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define DRAC_SUF 10
|
|
|
|
|
static const char *drac_suf[DRAC_SUF] = {
|
2014-08-24 21:49:55 +02:00
|
|
|
|
"xil",
|
|
|
|
|
"shh",
|
|
|
|
|
"s",
|
|
|
|
|
"x",
|
|
|
|
|
"arr",
|
|
|
|
|
"lll",
|
|
|
|
|
"lll",
|
|
|
|
|
"shack",
|
|
|
|
|
"ck",
|
|
|
|
|
"k"
|
2010-08-08 10:06:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
2016-08-28 21:27:40 +02:00
|
|
|
|
static void dracoid_name(unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2016-08-30 08:56:40 +02:00
|
|
|
|
static char name[NAMESIZE + 1];
|
2014-08-24 21:49:55 +02:00
|
|
|
|
int mid_syllabels;
|
2015-10-30 11:09:28 +01:00
|
|
|
|
size_t sz;
|
2014-08-24 21:49:55 +02:00
|
|
|
|
|
2015-05-12 18:07:47 +02:00
|
|
|
|
/* ignore u */
|
2015-10-30 15:21:06 +01:00
|
|
|
|
unused_arg(u);
|
2014-08-24 21:49:55 +02:00
|
|
|
|
/* Wieviele Mittelteile? */
|
|
|
|
|
|
|
|
|
|
mid_syllabels = rng_int() % 4;
|
|
|
|
|
|
2015-10-30 11:09:28 +01:00
|
|
|
|
sz = strlcpy(name, drac_pre[rng_int() % DRAC_PRE], sizeof(name));
|
2014-08-24 21:49:55 +02:00
|
|
|
|
while (mid_syllabels > 0) {
|
|
|
|
|
mid_syllabels--;
|
|
|
|
|
if (rng_int() % 10 < 4)
|
2015-10-30 11:09:28 +01:00
|
|
|
|
strlcat(name, "'", sizeof(name));
|
|
|
|
|
sz += strlcat(name, drac_mid[rng_int() % DRAC_MID], sizeof(name));
|
2014-08-24 21:49:55 +02:00
|
|
|
|
}
|
2015-10-30 11:09:28 +01:00
|
|
|
|
sz += strlcat(name, drac_suf[rng_int() % DRAC_SUF], sizeof(name));
|
2016-08-28 21:27:40 +02:00
|
|
|
|
unit_setname(u, name);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** returns an abbreviation of a string.
|
|
|
|
|
* TODO: buflen is being ignored */
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-08-24 21:49:55 +02:00
|
|
|
|
const char *p = s;
|
|
|
|
|
char *bufp;
|
|
|
|
|
unsigned int c = 0;
|
|
|
|
|
size_t bpt, i;
|
|
|
|
|
ucs4_t ucs;
|
|
|
|
|
size_t size;
|
|
|
|
|
int result;
|
|
|
|
|
|
|
|
|
|
/* Pr<50>fen, ob Kurz genug */
|
|
|
|
|
|
|
|
|
|
if (strlen(s) <= maxchars) {
|
|
|
|
|
return s;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2014-08-24 21:49:55 +02:00
|
|
|
|
/* Anzahl der W<>rter feststellen */
|
|
|
|
|
|
|
|
|
|
while (*p != 0) {
|
|
|
|
|
|
|
|
|
|
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
|
|
|
|
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
|
|
|
|
|
|
|
|
|
/* Leerzeichen <20>berspringen */
|
|
|
|
|
while (*p != 0 && !iswalnum((wint_t)ucs)) {
|
|
|
|
|
p += size;
|
|
|
|
|
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
|
|
|
|
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Counter erh<72>hen */
|
|
|
|
|
if (*p != 0)
|
|
|
|
|
++c;
|
|
|
|
|
|
|
|
|
|
/* alnums <20>berspringen */
|
|
|
|
|
while (*p != 0 && iswalnum((wint_t)ucs)) {
|
|
|
|
|
p += size;
|
|
|
|
|
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
|
|
|
|
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-24 21:49:55 +02:00
|
|
|
|
/* Buchstaben pro Teilk<6C>rzel = _max(1,max/AnzWort) */
|
2015-11-03 23:17:11 +01:00
|
|
|
|
bpt = (c > 0) ? _max(1, maxchars / c) : 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-24 21:49:55 +02:00
|
|
|
|
/* Einzelne W<>rter anspringen und jeweils die ersten BpT kopieren */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-24 21:49:55 +02:00
|
|
|
|
p = s;
|
|
|
|
|
c = 0;
|
|
|
|
|
bufp = buf;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-24 21:49:55 +02:00
|
|
|
|
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
|
|
|
|
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-24 21:49:55 +02:00
|
|
|
|
while (*p != 0 && c < maxchars) {
|
|
|
|
|
/* Leerzeichen <20>berspringen */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-24 21:49:55 +02:00
|
|
|
|
while (*p != 0 && !iswalnum((wint_t)ucs)) {
|
|
|
|
|
p += size;
|
|
|
|
|
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
|
|
|
|
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-24 21:49:55 +02:00
|
|
|
|
/* alnums <20>bertragen */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-24 21:49:55 +02:00
|
|
|
|
for (i = 0; i < bpt && *p != 0 && iswalnum((wint_t)ucs); ++i) {
|
|
|
|
|
memcpy(bufp, p, size);
|
|
|
|
|
p += size;
|
|
|
|
|
bufp += size;
|
|
|
|
|
++c;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-24 21:49:55 +02:00
|
|
|
|
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
|
|
|
|
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-24 21:49:55 +02:00
|
|
|
|
/* Bis zum n<>chsten Leerzeichen */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-24 21:49:55 +02:00
|
|
|
|
while (c < maxchars && *p != 0 && iswalnum((wint_t)ucs)) {
|
|
|
|
|
p += size;
|
|
|
|
|
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
|
|
|
|
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-24 21:49:55 +02:00
|
|
|
|
*bufp = 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-24 21:49:55 +02:00
|
|
|
|
return buf;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void register_names(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2016-08-28 21:44:09 +02:00
|
|
|
|
register_race_description_function(describe_race, "describe_race");
|
2014-08-24 21:49:55 +02:00
|
|
|
|
/* function name
|
|
|
|
|
* generate a name for a nonplayerunit
|
|
|
|
|
* race->generate_name() */
|
2016-08-28 21:02:45 +02:00
|
|
|
|
register_race_name_function(undead_name, "nameundead");
|
|
|
|
|
register_race_name_function(skeleton_name, "nameskeleton");
|
|
|
|
|
register_race_name_function(zombie_name, "namezombie");
|
|
|
|
|
register_race_name_function(ghoul_name, "nameghoul");
|
|
|
|
|
register_race_name_function(dracoid_name, "namedracoid");
|
2016-08-28 21:27:40 +02:00
|
|
|
|
register_race_name_function(dragon_name, "namedragon");
|
2016-08-28 21:02:45 +02:00
|
|
|
|
register_race_name_function(generic_name, "namegeneric");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|