(svn r1977) Typedef some enums and struct plus some minor style changes

This commit is contained in:
tron 2005-03-09 19:42:37 +00:00
parent e6e3e69da4
commit 9bc68d209f
2 changed files with 50 additions and 47 deletions

View File

@ -337,11 +337,13 @@ static byte MakeCzechTownName(char *buf, uint32 seed)
int prob_tails;
bool do_prefix, do_suffix, dynamic_subst;
/* IDs of the respective parts */
int prefix = 0, stem = 0, postfix = 0, ending = 0, suffix = 0;
int prefix = 0, ending = 0, suffix = 0;
uint postfix = 0;
uint stem;
/* The select criteria. */
enum CzechGender gender;
enum CzechChoose choose;
enum CzechAllow allow;
CzechGender gender;
CzechChoose choose;
CzechAllow allow;
// 1:3 chance to use a real name.
if (SeedModChance(0, 4, seed) == 0) {
@ -359,16 +361,15 @@ static byte MakeCzechTownName(char *buf, uint32 seed)
if (do_prefix) prefix = SeedModChance(5, lengthof(name_czech_adj) * 12, seed) / 12;
if (do_suffix) suffix = SeedModChance(7, lengthof(name_czech_suffix), seed);
// 3:1 chance 3:1 to use dynamic substantive
stem = SeedModChance(9, lengthof(name_czech_subst_full)
+ 3 * lengthof(name_czech_subst_stem),
seed);
if (stem < (int) lengthof(name_czech_subst_full)) {
stem = SeedModChance(9,
lengthof(name_czech_subst_full) + 3 * lengthof(name_czech_subst_stem),
seed);
if (stem < lengthof(name_czech_subst_full)) {
// That was easy!
dynamic_subst = false;
gender = name_czech_subst_full[stem].gender;
choose = name_czech_subst_full[stem].choose;
allow = name_czech_subst_full[stem].allow;
} else {
unsigned int map[lengthof(name_czech_subst_ending)];
int ending_start = -1, ending_stop = -1;
@ -393,18 +394,18 @@ static byte MakeCzechTownName(char *buf, uint32 seed)
// Always drop a postfix.
postfix += lengthof(name_czech_subst_postfix);
}
if (postfix < (int) lengthof(name_czech_subst_postfix))
if (postfix < lengthof(name_czech_subst_postfix))
choose |= CZC_POSTFIX;
else
choose |= CZC_NOPOSTFIX;
// Localize the array segment containing a good gender
for (ending = 0; ending < (int) lengthof(name_czech_subst_ending); ending++) {
const struct CzechNameSubst *e = &name_czech_subst_ending[ending];
const CzechNameSubst *e = &name_czech_subst_ending[ending];
if (gender == CZG_FREE
|| (gender == CZG_NFREE && e->gender != CZG_SNEUT && e->gender != CZG_PNEUT)
|| (gender == e->gender)) {
if (gender == CZG_FREE ||
(gender == CZG_NFREE && e->gender != CZG_SNEUT && e->gender != CZG_PNEUT) ||
gender == e->gender) {
if (ending_start < 0)
ending_start = ending;
@ -421,7 +422,7 @@ static byte MakeCzechTownName(char *buf, uint32 seed)
// Make a sequential map of the items with good mask
i = 0;
for (ending = ending_start; ending <= ending_stop; ending++) {
const struct CzechNameSubst *e = &name_czech_subst_ending[ending];
const CzechNameSubst *e = &name_czech_subst_ending[ending];
if ((e->choose & choose) == choose && (e->allow & allow) != 0)
map[i++] = ending;
@ -444,7 +445,7 @@ static byte MakeCzechTownName(char *buf, uint32 seed)
// Now finally construct the name
if (do_prefix) {
enum CzechPattern pattern = name_czech_adj[prefix].pattern;
CzechPattern pattern = name_czech_adj[prefix].pattern;
int endpos;
strcat(buf, name_czech_adj[prefix].name);
@ -463,7 +464,7 @@ static byte MakeCzechTownName(char *buf, uint32 seed)
if (dynamic_subst) {
strcat(buf, name_czech_subst_stem[stem].name);
if (postfix < (int) lengthof(name_czech_subst_postfix)) {
if (postfix < lengthof(name_czech_subst_postfix)) {
const char *poststr = name_czech_subst_postfix[postfix];
const char *endstr = name_czech_subst_ending[ending].name;
int postlen, endlen;
@ -473,19 +474,21 @@ static byte MakeCzechTownName(char *buf, uint32 seed)
assert(postlen > 0 && endlen > 0);
// Kill the "avava" and "Jananna"-like cases
if (postlen < 2 || postlen > endlen
|| ((poststr[1] != 'v' || poststr[1] != endstr[1])
&& poststr[2] != endstr[1])) {
int buflen;
if (postlen < 2 || postlen > endlen || (
(poststr[1] != 'v' || poststr[1] != endstr[1]) &&
poststr[2] != endstr[1])
) {
uint buflen;
strcat(buf, poststr);
buflen = strlen(buf);
// k-i -> c-i, h-i -> z-i
if (endstr[0] == 'i') {
if (buf[buflen - 1] == 'k')
buf[buflen - 1] = 'c';
else if (buf[buflen - 1] == 'h')
buf[buflen - 1] = 'z';
switch (buf[buflen - 1]) {
case 'k': buf[buflen - 1] = 'c'; break;
case 'h': buf[buflen - 1] = 'z'; break;
default: break;
}
}
}
}

View File

@ -1666,7 +1666,7 @@ static const char *name_czech_real[] = {
* with cloning this for your own language. */
// Sing., pl.
enum CzechGender {
typedef enum CzechGender {
CZG_SMASC,
CZG_SFEM,
CZG_SNEUT,
@ -1677,16 +1677,16 @@ enum CzechGender {
CZG_FREE,
// Like CZG_FREE, but disallow CZG_SNEUT.
CZG_NFREE
};
enum CzechPattern {
} CzechGender;
typedef enum CzechPattern {
CZP_JARNI,
CZP_MLADY,
CZP_PRIVL
};
} CzechPattern;
/* [CzechGender][CzechPattern] - replaces the last character of the adjective
* by this. */
// XXX: [CZG_SMASC][CZP_PRIVL] needs special handling: -ovX -> -uv.
static const char name_czech_patmod[6][3] = {
static const char name_czech_patmod[][3] = {
/* CZG_SMASC */ { 'í', 'ý', 'X' },
/* CZG_SFEM */ { 'í', 'á', 'a' },
/* CZG_SNEUT */ { 'í', 'é', 'o' },
@ -1697,36 +1697,36 @@ static const char name_czech_patmod[6][3] = {
// This way the substantives can choose only some adjectives/endings:
// At least one of these flags must be satisfied:
enum CzechAllow {
typedef enum CzechAllow {
CZA_SHORT = 1,
CZA_MIDDLE = 2,
CZA_LONG = 4,
CZA_ALL = ~0
};
} CzechAllow;
// All these flags must be satisfied (in the stem->others direction):
enum CzechChoose {
typedef enum CzechChoose {
CZC_NONE = 0, // No requirements.
CZC_COLOR = 1,
CZC_POSTFIX = 2, // Matched if postfix was inserted.
CZC_NOPOSTFIX = 4, // Matched if no postfix was inserted.
CZC_ANY = ~0
};
} CzechChoose;
struct CzechNameSubst {
enum CzechGender gender;
enum CzechAllow allow;
enum CzechChoose choose;
typedef struct CzechNameSubst {
CzechGender gender;
CzechAllow allow;
CzechChoose choose;
const char *name;
};
} CzechNameSubst;
struct CzechNameAdj {
enum CzechPattern pattern;
enum CzechChoose choose;
typedef struct CzechNameAdj {
CzechPattern pattern;
CzechChoose choose;
const char *name;
};
} CzechNameAdj;
// Some of items which should be common are doubled.
static const struct CzechNameAdj name_czech_adj[] = {
static const CzechNameAdj name_czech_adj[] = {
{ CZP_JARNI, CZC_ANY, "Horní" },
{ CZP_JARNI, CZC_ANY, "Horní" },
{ CZP_JARNI, CZC_ANY, "Dolní" },
@ -1778,7 +1778,7 @@ static const struct CzechNameAdj name_czech_adj[] = {
};
// Considered a stem for choose/allow matching purposes.
static const struct CzechNameSubst name_czech_subst_full[] = {
static const CzechNameSubst name_czech_subst_full[] = {
{ CZG_SMASC, CZA_ALL, CZC_COLOR, "Sedlec" },
{ CZG_SMASC, CZA_ALL, CZC_COLOR, "Brod" },
{ CZG_SMASC, CZA_ALL, CZC_COLOR, "Brod" },
@ -1798,7 +1798,7 @@ static const struct CzechNameSubst name_czech_subst_full[] = {
};
// TODO: More stems needed. --pasky
static const struct CzechNameSubst name_czech_subst_stem[] = {
static const CzechNameSubst name_czech_subst_stem[] = {
{ CZG_SMASC, CZA_MIDDLE, CZC_COLOR, "Kostel" },
{ CZG_SMASC, CZA_MIDDLE, CZC_COLOR, "Kláster" },
{ CZG_SMASC, CZA_SHORT, CZC_COLOR, "Lhot" },
@ -1851,7 +1851,7 @@ static const char *name_czech_subst_postfix[] = {
};
// This array must have the both neutral genders at the end!
static const struct CzechNameSubst name_czech_subst_ending[] = {
static const CzechNameSubst name_czech_subst_ending[] = {
{ CZG_SMASC, CZA_SHORT | CZA_MIDDLE, CZC_ANY, "ec" },
{ CZG_SMASC, CZA_SHORT | CZA_MIDDLE, CZC_ANY, "ín" },
{ CZG_SMASC, CZA_SHORT | CZA_MIDDLE | CZA_LONG, CZC_ANY, "ov" },