From 4c00777553d6daf41de9a63cb23d45542fd9b791 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 24 Aug 2014 21:49:55 +0200 Subject: [PATCH] make race::_name a string, not an array of strings. add a test for rc_name. --- src/bind_faction.c | 2 +- src/bind_monsters.c | 2 +- src/bind_unit.c | 2 +- src/bindings.c | 2 +- src/creport.c | 10 +- src/economy.c | 2 +- src/give.c | 2 +- src/helpers.c | 6 +- src/kernel/CMakeLists.txt | 1 + src/kernel/battle.c | 4 +- src/kernel/config.c | 6 +- src/kernel/faction.c | 2 +- src/kernel/item.c | 2 +- src/kernel/jsonconf.test.c | 2 +- src/kernel/names.c | 675 +++++++++++++++++++------------------ src/kernel/names.h | 7 - src/kernel/race.c | 49 +-- src/kernel/race.h | 8 +- src/kernel/race.test.c | 24 ++ src/kernel/region.c | 10 +- src/kernel/region.h | 6 +- src/kernel/reports.c | 6 +- src/kernel/save.c | 6 +- src/kernel/skills.c | 2 +- src/kernel/xmlreader.c | 8 +- src/laws.c | 11 +- src/modules/score.c | 2 +- src/monsters.c | 4 +- src/races/races.c | 2 +- src/report.c | 2 +- src/spells/spells.c | 12 +- src/sqlite.c | 2 +- src/summary.c | 10 +- src/test_eressea.c | 1 + 34 files changed, 459 insertions(+), 433 deletions(-) create mode 100644 src/kernel/race.test.c diff --git a/src/bind_faction.c b/src/bind_faction.c index 166a70acd..d99d5c85f 100644 --- a/src/bind_faction.c +++ b/src/bind_faction.c @@ -385,7 +385,7 @@ static int tolua_faction_set_locale(lua_State * L) static int tolua_faction_get_race(lua_State * L) { faction *self = (faction *) tolua_tousertype(L, 1, 0); - tolua_pushstring(L, self->race->_name[0]); + tolua_pushstring(L, self->race->_name); return 1; } diff --git a/src/bind_monsters.c b/src/bind_monsters.c index 8d2b42700..22ae645c0 100644 --- a/src/bind_monsters.c +++ b/src/bind_monsters.c @@ -68,7 +68,7 @@ static int fix_familiars(struct lua_State *L) free(mage->spellbook); mage->spellbook = 0; - _snprintf(buffer, sizeof(buffer), "%s_familiar", u_race(u)->_name[0]); + _snprintf(buffer, sizeof(buffer), "%s_familiar", u_race(u)->_name); eq = get_equipment(buffer); if (eq) { equip_unit_mask(u, eq, EQUIP_SPELLS); diff --git a/src/bind_unit.c b/src/bind_unit.c index 4886408da..66be03a0c 100755 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -840,7 +840,7 @@ static int tolua_unit_set_faction(lua_State * L) static int tolua_unit_get_race(lua_State * L) { unit *self = (unit *) tolua_tousertype(L, 1, 0); - tolua_pushstring(L, u_race(self)->_name[0]); + tolua_pushstring(L, u_race(self)->_name); return 1; } diff --git a/src/bindings.c b/src/bindings.c index 791c1e26a..b5cfef0b5 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -711,7 +711,7 @@ static int tolua_write_spells(lua_State * L) for (; comp->type != 0; ++comp) { static const char *costs[] = { "fixed", "level", "linear" }; xmlNodePtr cnode = xmlNewNode(NULL, BAD_CAST "resource"); - xmlNewProp(cnode, BAD_CAST "name", BAD_CAST comp->type->_name[0]); + xmlNewProp(cnode, BAD_CAST "name", BAD_CAST comp->type->_name); xmlNewProp(cnode, BAD_CAST "amount", xml_i(comp->amount)); xmlNewProp(cnode, BAD_CAST "cost", BAD_CAST costs[comp->cost]); xmlAddChild(node, cnode); diff --git a/src/creport.c b/src/creport.c index c7beebc80..dfcc94f63 100644 --- a/src/creport.c +++ b/src/creport.c @@ -340,7 +340,7 @@ static int cr_race(variant var, char *buffer, const void *userdata) { const faction *report = (const faction *)userdata; const struct race *rc = (const race *)var.v; - const char *key = rc_name(rc, 0); + const char *key = rc_name(rc, NAME_SINGULAR); sprintf(buffer, "\"%s\"", translate(key, locale_string(report->locale, key))); return 0; @@ -832,20 +832,20 @@ static void cr_output_unit(FILE * F, const region * r, const faction * f, if (pzTmp) { fprintf(F, "\"%s\";Typ\n", pzTmp); if (u->faction == f && fval(u_race(u), RCF_SHAPESHIFTANY)) { - const char *zRace = rc_name(u_race(u), 1); + const char *zRace = rc_name(u_race(u), NAME_PLURAL); fprintf(F, "\"%s\";wahrerTyp\n", translate(zRace, locale_string(f->locale, zRace))); } } else { const race *irace = u_irace(u); - const char *zRace = rc_name(irace, 1); + const char *zRace = rc_name(irace, NAME_PLURAL); fprintf(F, "\"%s\";Typ\n", translate(zRace, locale_string(f->locale, zRace))); if (u->faction == f && irace != u_race(u)) { assert(skill_enabled(SK_STEALTH) || !"we're resetting this on load, so.. ircase should never be used"); - zRace = rc_name(u_race(u), 1); + zRace = rc_name(u_race(u), NAME_PLURAL); fprintf(F, "\"%s\";wahrerTyp\n", translate(zRace, locale_string(f->locale, zRace))); } @@ -1546,7 +1546,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset) fprintf(F, "%d;Punktedurchschnitt\n", avgscore); #endif { - const char *zRace = rc_name(f->race, 1); + const char *zRace = rc_name(f->race, NAME_PLURAL); fprintf(F, "\"%s\";Typ\n", translate(zRace, LOC(f->locale, zRace))); } prefix = get_prefix(f->attribs); diff --git a/src/economy.c b/src/economy.c index 940fec4f8..271482f89 100644 --- a/src/economy.c +++ b/src/economy.c @@ -259,7 +259,7 @@ static void add_recruits(unit * u, int number, int wanted) } strlcpy(equipment, "new_", sizeof(equipment)); - strlcat(equipment, u_race(u)->_name[0], sizeof(equipment)); + strlcat(equipment, u_race(u)->_name, sizeof(equipment)); strlcat(equipment, "_unit", sizeof(equipment)); equip_unit(unew, get_equipment(equipment)); diff --git a/src/give.c b/src/give.c index 35a2f47f4..feb28a877 100644 --- a/src/give.c +++ b/src/give.c @@ -228,7 +228,7 @@ void give_men(int n, unit * u, unit * u2, struct order *ord) error = 312; } else if (u2 && u2->number != 0 && u_race(u2) != u_race(u)) { - log_debug("faction %s attempts to give %s to %s.\n", itoa36(u->faction->no), u_race(u)->_name[0], u_race(u2)->_name[0]); + log_debug("faction %s attempts to give %s to %s.\n", itoa36(u->faction->no), u_race(u)->_name, u_race(u2)->_name); error = 139; } else if (u2 != NULL && (get_racename(u2->attribs) diff --git a/src/helpers.c b/src/helpers.c index d2b2c78a2..ffe1af9e2 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -216,7 +216,7 @@ static int lua_initfamiliar(unit * u) int result = -1; strlcpy(fname, "initfamiliar_", sizeof(fname)); - strlcat(fname, u_race(u)->_name[0], sizeof(fname)); + strlcat(fname, u_race(u)->_name, sizeof(fname)); lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { @@ -237,7 +237,7 @@ static int lua_initfamiliar(unit * u) create_mage(u, M_GRAY); - strlcpy(fname, u_race(u)->_name[0], sizeof(fname)); + strlcpy(fname, u_race(u)->_name, sizeof(fname)); strlcat(fname, "_familiar", sizeof(fname)); equip_unit(u, get_equipment(fname)); return result; @@ -345,7 +345,7 @@ lua_wage(const region * r, const faction * f, const race * rc, int in_turn) if (lua_isfunction(L, -1)) { tolua_pushusertype(L, (void *)r, TOLUA_CAST "region"); tolua_pushusertype(L, (void *)f, TOLUA_CAST "faction"); - tolua_pushstring(L, rc ? rc->_name[0] : 0); + tolua_pushstring(L, rc ? rc->_name : 0); tolua_pushnumber(L, (lua_Number) in_turn); if (lua_pcall(L, 3, 1, 0) != 0) { diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 918abbb80..b2bdece72 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -17,6 +17,7 @@ item.test.c move.test.c order.test.c pool.test.c +race.test.c reports.test.c spellbook.test.c curse.test.c diff --git a/src/kernel/battle.c b/src/kernel/battle.c index f4af20503..11d4aeb02 100644 --- a/src/kernel/battle.c +++ b/src/kernel/battle.c @@ -954,7 +954,7 @@ void kill_troop(troop dt) i_merge(&du->items, &drops); } } - sprintf(eqname, "%s_spoils", u_race(du)->_name[0]); + sprintf(eqname, "%s_spoils", u_race(du)->_name); eq = get_equipment(eqname); if (eq != NULL) { equip_items(&du->items, eq); @@ -2066,7 +2066,7 @@ static void make_heroes(battle * b) if (fval(u, UFL_HERO)) { int i; if (!playerrace(u_race(u))) { - log_error("Hero %s is a %s.\n", unitname(u), u_race(u)->_name[0]); + log_error("Hero %s is a %s.\n", unitname(u), u_race(u)->_name); } for (i = 0; i != u->number; ++i) { fig->person[i].speed += (hero_speed - 1); diff --git a/src/kernel/config.c b/src/kernel/config.c index 628ca6087..b6fab5f59 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -318,7 +318,7 @@ const char *dbrace(const struct race *rc) char *zPtr = zText; /* the english names are all in ASCII, so we don't need to worry about UTF8 */ - strcpy(zText, (const char *)LOC(get_locale("en"), rc_name(rc, 0))); + strcpy(zText, (const char *)LOC(get_locale("en"), rc_name(rc, NAME_SINGULAR))); while (*zPtr) { *zPtr = (char)(toupper(*zPtr)); ++zPtr; @@ -1838,9 +1838,9 @@ void init_locale(const struct locale *lang) for (rc = races; rc; rc = rc->next) { const char *name; var.v = (void *)rc; - name = LOC(lang, rc_name(rc, 1)); + name = LOC(lang, rc_name(rc, NAME_PLURAL)); if (name) addtoken(tokens, name, var); - name = LOC(lang, rc_name(rc, 0)); + name = LOC(lang, rc_name(rc, NAME_SINGULAR)); if (name) addtoken(tokens, name, var); } diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 14a04e152..b46848e3c 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -255,7 +255,7 @@ unit *addplayer(region * r, faction * f) u = createunit(r, f, 1, f->race); equip_items(&u->faction->items, get_equipment("new_faction")); equip_unit(u, get_equipment("first_unit")); - sprintf(buffer, "first_%s", u_race(u)->_name[0]); + sprintf(buffer, "first_%s", u_race(u)->_name); equip_unit(u, get_equipment(buffer)); u->hp = unit_max_hp(u) * u->number; fset(u, UFL_ISNEW); diff --git a/src/kernel/item.c b/src/kernel/item.c index 0079b576c..faa6f1611 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -1157,7 +1157,7 @@ static item *default_spoil(const struct race *rc, int size) char spoilname[32]; const item_type *itype; - sprintf(spoilname, "%sspoil", rc->_name[0]); + sprintf(spoilname, "%sspoil", rc->_name); itype = it_find(spoilname); if (itype != NULL) { i_add(&itm, i_new(itype, size)); diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index a9283ecc3..42505f0bb 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -112,7 +112,7 @@ static void test_findrace(CuTest *tc) { json_config(json); rc = findrace("Zwerg", lang); CuAssertPtrNotNull(tc, rc); - CuAssertStrEquals(tc, "dwarf", rc->_name[0]); + CuAssertStrEquals(tc, "dwarf", rc->_name); } static void test_items(CuTest * tc) diff --git a/src/kernel/names.c b/src/kernel/names.c index 706d53c33..02a2216a5 100644 --- a/src/kernel/names.c +++ b/src/kernel/names.c @@ -1,7 +1,7 @@ /* Copyright (c) 1998-2010, Enno Rehling - Katja Zedel +Katja Zedel Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -45,107 +45,108 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -const char *describe_braineater(unit * u, const struct locale *lang) +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, - int pprefix, int *num_name, int *num_prefix, int ppostfix) + int pprefix, int *num_name, int *num_prefix, int ppostfix) { - int uv, uu, un; - static char name[NAMESIZE + 1]; - char zText[32]; - const char *str; + int uv, uu, un; + static char name[NAMESIZE + 1]; + char zText[32]; + const char *str; - if (*num_prefix == 0) { + if (*num_prefix == 0) { - for (*num_prefix = 0;; ++*num_prefix) { - sprintf(zText, "%s_prefix_%d", monster, *num_prefix); - str = locale_getstring(default_locale, zText); - if (str == NULL) - break; + for (*num_prefix = 0;; ++*num_prefix) { + sprintf(zText, "%s_prefix_%d", monster, *num_prefix); + str = locale_getstring(default_locale, zText); + if (str == NULL) + break; + } + + for (*num_name = 0;; ++*num_name) { + sprintf(zText, "%s_name_%d", monster, *num_name); + str = locale_getstring(default_locale, zText); + if (str == NULL) + break; + } + + for (*num_postfix = 0;; ++*num_postfix) { + sprintf(zText, "%s_postfix_%d", monster, *num_postfix); + str = locale_getstring(default_locale, zText); + if (str == NULL) + break; + } } - for (*num_name = 0;; ++*num_name) { - sprintf(zText, "%s_name_%d", monster, *num_name); - str = locale_getstring(default_locale, zText); - if (str == NULL) - break; + if (*num_name == 0) { + return NULL; } - for (*num_postfix = 0;; ++*num_postfix) { - sprintf(zText, "%s_postfix_%d", monster, *num_postfix); - str = locale_getstring(default_locale, zText); - if (str == NULL) - break; + /* nur 50% aller Namen haben "Vor-Teil" */ + uv = rng_int() % (*num_prefix * pprefix); + + uu = rng_int() % *num_name; + + /* nur 50% aller Namen haben "Nach-Teil", wenn kein Vor-Teil */ + if (uv >= *num_prefix) { + un = rng_int() % *num_postfix; + } + else { + un = rng_int() % (*num_postfix * ppostfix); } - } - if (*num_name == 0) { - return NULL; - } + name[0] = 0; + if (uv < *num_prefix) { + sprintf(zText, "%s_prefix_%d", monster, uv); + str = locale_getstring(default_locale, zText); + if (str) { + strcat(name, (const char *)str); + strcat(name, " "); + } + } - /* nur 50% aller Namen haben "Vor-Teil" */ - uv = rng_int() % (*num_prefix * pprefix); - - uu = rng_int() % *num_name; - - /* nur 50% aller Namen haben "Nach-Teil", wenn kein Vor-Teil */ - if (uv >= *num_prefix) { - un = rng_int() % *num_postfix; - } else { - un = rng_int() % (*num_postfix * ppostfix); - } - - name[0] = 0; - if (uv < *num_prefix) { - sprintf(zText, "%s_prefix_%d", monster, uv); + sprintf(zText, "%s_name_%d", monster, uu); str = locale_getstring(default_locale, zText); - if (str) { - strcat(name, (const char *)str); - strcat(name, " "); + if (str) + strcat(name, (const char *)str); + + if (un < *num_postfix) { + sprintf(zText, "%s_postfix_%d", monster, un); + str = locale_getstring(default_locale, zText); + if (str) { + strcat(name, " "); + strcat(name, (const char *)str); + } } - } - - sprintf(zText, "%s_name_%d", monster, uu); - str = locale_getstring(default_locale, zText); - if (str) - strcat(name, (const char *)str); - - if (un < *num_postfix) { - sprintf(zText, "%s_postfix_%d", monster, un); - str = locale_getstring(default_locale, zText); - if (str) { - strcat(name, " "); - strcat(name, (const char *)str); - } - } - return name; + return name; } -const char *undead_name(const unit * u) +static const char *undead_name(const unit * u) { - static int num_postfix, num_name, num_prefix; - return make_names("undead", &num_postfix, 2, &num_name, &num_prefix, 2); + static int num_postfix, num_name, num_prefix; + return make_names("undead", &num_postfix, 2, &num_name, &num_prefix, 2); } -const char *skeleton_name(const unit * u) +static const char *skeleton_name(const unit * u) { - static int num_postfix, num_name, num_prefix; - return make_names("skeleton", &num_postfix, 5, &num_name, &num_prefix, 2); + static int num_postfix, num_name, num_prefix; + return make_names("skeleton", &num_postfix, 5, &num_name, &num_prefix, 2); } -const char *zombie_name(const unit * u) +static const char *zombie_name(const unit * u) { - static int num_postfix, num_name, num_prefix; - return make_names("zombie", &num_postfix, 5, &num_name, &num_prefix, 2); + static int num_postfix, num_name, num_prefix; + return make_names("zombie", &num_postfix, 5, &num_name, &num_prefix, 2); } -const char *ghoul_name(const unit * u) +static const char *ghoul_name(const unit * u) { - static int num_postfix, num_name, num_prefix; - return make_names("ghoul", &num_postfix, 5, &num_name, &num_prefix, 4); + static int num_postfix, num_name, num_prefix; + return make_names("ghoul", &num_postfix, 5, &num_name, &num_prefix, 4); } /* Drachen */ @@ -153,224 +154,224 @@ const char *ghoul_name(const unit * u) #define SIL1 15 const char *silbe1[SIL1] = { - "Tar", - "Ter", - "Tor", - "Pan", - "Par", - "Per", - "Nim", - "Nan", - "Nun", - "Gor", - "For", - "Fer", - "Kar", - "Kur", - "Pen", + "Tar", + "Ter", + "Tor", + "Pan", + "Par", + "Per", + "Nim", + "Nan", + "Nun", + "Gor", + "For", + "Fer", + "Kar", + "Kur", + "Pen", }; #define SIL2 19 const char *silbe2[SIL2] = { - "da", - "do", - "dil", - "di", - "dor", - "dar", - "ra", - "ran", - "ras", - "ro", - "rum", - "rin", - "ten", - "tan", - "ta", - "tor", - "gur", - "ga", - "gas", + "da", + "do", + "dil", + "di", + "dor", + "dar", + "ra", + "ran", + "ras", + "ro", + "rum", + "rin", + "ten", + "tan", + "ta", + "tor", + "gur", + "ga", + "gas", }; #define SIL3 14 const char *silbe3[SIL3] = { - "gul", - "gol", - "dol", - "tan", - "tar", - "tur", - "sur", - "sin", - "kur", - "kor", - "kar", - "dul", - "dol", - "bus", + "gul", + "gol", + "dol", + "tan", + "tar", + "tur", + "sur", + "sin", + "kur", + "kor", + "kar", + "dul", + "dol", + "bus", }; -const char *generic_name(const unit * u) +static const char *generic_name(const unit * u) { - if (u->no == 1) { - return LOC(u->faction->locale, mkname("race", u_race(u)->_name[0])); - } - return LOC(u->faction->locale, mkname("race", u_race(u)->_name[1])); + const char * name = rc_name(u_race(u), (u->no == 1) ? NAME_SINGULAR : NAME_PLURAL); + return LOC(u->faction->locale, name); } -const char *dragon_name(const unit * u) +static const char *dragon_name(const unit * u) { - static char name[NAMESIZE + 1]; - int rnd, ter = 0; - int anzahl = 1; - static int num_postfix; - char zText[32]; - const char *str; + static char name[NAMESIZE + 1]; + 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) { + 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; } - if (num_postfix == 0) - num_postfix = -1; - } - if (num_postfix <= 0) { - return NULL; - } - - 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; + if (num_postfix <= 0) { + return NULL; } - } - rnd = num_postfix / 6; - rnd = (rng_int() % rnd) + ter * rnd; - - 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); - /* TODO: GERMAN */ - sprintf(name, "Die %sn von %s", no_article+1, rname(u->region, - default_locale)); - } else { - char n[32]; - - strcpy(n, silbe1[rng_int() % SIL1]); - strcat(n, silbe2[rng_int() % SIL2]); - strcat(n, silbe3[rng_int() % SIL3]); - if (rng_int() % 5 > 2) { - sprintf(name, "%s, %s", n, str); /* "Name, der Titel" */ - } else { - strcpy(name, (const char *)str); /* "Der Titel Name" */ - name[0] = (char)toupper(name[0]); /* TODO: UNICODE - should use towupper() */ - strcat(name, " "); - strcat(name, n); + 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; + } } - if (u && (rng_int() % 3 == 0)) { - strcat(name, " von "); - strcat(name, (const char *)rname(u->region, default_locale)); - } - } - return name; + rnd = num_postfix / 6; + rnd = (rng_int() % rnd) + ter * rnd; + + 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); + /* TODO: GERMAN */ + sprintf(name, "Die %sn von %s", no_article + 1, rname(u->region, + default_locale)); + } + else { + char n[32]; + + strcpy(n, silbe1[rng_int() % SIL1]); + strcat(n, silbe2[rng_int() % SIL2]); + strcat(n, silbe3[rng_int() % SIL3]); + if (rng_int() % 5 > 2) { + sprintf(name, "%s, %s", n, str); /* "Name, der Titel" */ + } + else { + strcpy(name, (const char *)str); /* "Der Titel Name" */ + name[0] = (char)toupper(name[0]); /* TODO: UNICODE - should use towupper() */ + strcat(name, " "); + strcat(name, n); + } + if (u && (rng_int() % 3 == 0)) { + strcat(name, " von "); + strcat(name, (const char *)rname(u->region, default_locale)); + } + } + + return name; } /* Dracoide */ #define DRAC_PRE 13 static const char *drac_pre[DRAC_PRE] = { - "Siss", - "Xxaa", - "Shht", - "X'xixi", - "Xar", - "X'zish", - "X", - "Sh", - "R", - "Z", - "Y", - "L", - "Ck", + "Siss", + "Xxaa", + "Shht", + "X'xixi", + "Xar", + "X'zish", + "X", + "Sh", + "R", + "Z", + "Y", + "L", + "Ck", }; #define DRAC_MID 12 static const char *drac_mid[DRAC_MID] = { - "siss", - "xxaa", - "shht", - "xxi", - "xar", - "x'zish", - "x", - "sh", - "r", - "z'ck", - "y", - "rl" + "siss", + "xxaa", + "shht", + "xxi", + "xar", + "x'zish", + "x", + "sh", + "r", + "z'ck", + "y", + "rl" }; #define DRAC_SUF 10 static const char *drac_suf[DRAC_SUF] = { - "xil", - "shh", - "s", - "x", - "arr", - "lll", - "lll", - "shack", - "ck", - "k" + "xil", + "shh", + "s", + "x", + "arr", + "lll", + "lll", + "shack", + "ck", + "k" }; -const char *dracoid_name(const unit * u) +static const char *dracoid_name(const unit * u) { - static char name[NAMESIZE + 1]; - int mid_syllabels; + static char name[NAMESIZE + 1]; + int mid_syllabels; - u = u; - /* Wieviele Mittelteile? */ + u = u; + /* Wieviele Mittelteile? */ - mid_syllabels = rng_int() % 4; + mid_syllabels = rng_int() % 4; - strcpy(name, drac_pre[rng_int() % DRAC_PRE]); - while (mid_syllabels > 0) { - mid_syllabels--; - if (rng_int() % 10 < 4) - strcat(name, "'"); - strcat(name, drac_mid[rng_int() % DRAC_MID]); - } - strcat(name, drac_suf[rng_int() % DRAC_SUF]); - return name; + strcpy(name, drac_pre[rng_int() % DRAC_PRE]); + while (mid_syllabels > 0) { + mid_syllabels--; + if (rng_int() % 10 < 4) + strcat(name, "'"); + strcat(name, drac_mid[rng_int() % DRAC_MID]); + } + strcat(name, drac_suf[rng_int() % DRAC_SUF]); + return name; } /** returns an abbreviation of a string. @@ -378,104 +379,104 @@ const char *dracoid_name(const unit * u) const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars) { - const char *p = s; - char *bufp; - unsigned int c = 0; - size_t bpt, i; - ucs4_t ucs; - size_t size; - int result; + const char *p = s; + char *bufp; + unsigned int c = 0; + size_t bpt, i; + ucs4_t ucs; + size_t size; + int result; - /* Prüfen, ob Kurz genug */ + /* Prüfen, ob Kurz genug */ - if (strlen(s) <= maxchars) { - return s; - } - /* Anzahl der Wörter feststellen */ + if (strlen(s) <= maxchars) { + return s; + } + /* Anzahl der Wörter feststellen */ - while (*p != 0) { + while (*p != 0) { + + result = unicode_utf8_to_ucs4(&ucs, p, &size); + assert(result == 0 || "damnit, we're not handling invalid input here!"); + + /* Leerzeichen ü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öhen */ + if (*p != 0) + ++c; + + /* alnums ü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!"); + } + } + + /* Buchstaben pro Teilkürzel = _max(1,max/AnzWort) */ + + bpt = _max(1, maxchars / c); + + /* Einzelne Wörter anspringen und jeweils die ersten BpT kopieren */ + + p = s; + c = 0; + bufp = buf; result = unicode_utf8_to_ucs4(&ucs, p, &size); assert(result == 0 || "damnit, we're not handling invalid input here!"); - /* Leerzeichen ü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!"); + while (*p != 0 && c < maxchars) { + /* Leerzeichen ü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!"); + } + + /* alnums übertragen */ + + for (i = 0; i < bpt && *p != 0 && iswalnum((wint_t)ucs); ++i) { + memcpy(bufp, p, size); + p += size; + bufp += size; + ++c; + + result = unicode_utf8_to_ucs4(&ucs, p, &size); + assert(result == 0 || "damnit, we're not handling invalid input here!"); + } + + /* Bis zum nächsten Leerzeichen */ + + 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!"); + } } - /* Counter erhöhen */ - if (*p != 0) - ++c; + *bufp = 0; - /* alnums ü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!"); - } - } - - /* Buchstaben pro Teilkürzel = _max(1,max/AnzWort) */ - - bpt = _max(1, maxchars / c); - - /* Einzelne Wörter anspringen und jeweils die ersten BpT kopieren */ - - p = s; - c = 0; - bufp = buf; - - result = unicode_utf8_to_ucs4(&ucs, p, &size); - assert(result == 0 || "damnit, we're not handling invalid input here!"); - - while (*p != 0 && c < maxchars) { - /* Leerzeichen ü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!"); - } - - /* alnums übertragen */ - - for (i = 0; i < bpt && *p != 0 && iswalnum((wint_t) ucs); ++i) { - memcpy(bufp, p, size); - p += size; - bufp += size; - ++c; - - result = unicode_utf8_to_ucs4(&ucs, p, &size); - assert(result == 0 || "damnit, we're not handling invalid input here!"); - } - - /* Bis zum nächsten Leerzeichen */ - - 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!"); - } - } - - *bufp = 0; - - return buf; + return buf; } void register_names(void) { - register_function((pf_generic) describe_braineater, "describe_braineater"); - /* function name - * generate a name for a nonplayerunit - * race->generate_name() */ - register_function((pf_generic) undead_name, "nameundead"); - register_function((pf_generic) skeleton_name, "nameskeleton"); - register_function((pf_generic) zombie_name, "namezombie"); - register_function((pf_generic) ghoul_name, "nameghoul"); - register_function((pf_generic) dragon_name, "namedragon"); - register_function((pf_generic) dracoid_name, "namedracoid"); - register_function((pf_generic) generic_name, "namegeneric"); + register_function((pf_generic)describe_braineater, "describe_braineater"); + /* function name + * generate a name for a nonplayerunit + * race->generate_name() */ + register_function((pf_generic)undead_name, "nameundead"); + register_function((pf_generic)skeleton_name, "nameskeleton"); + register_function((pf_generic)zombie_name, "namezombie"); + register_function((pf_generic)ghoul_name, "nameghoul"); + register_function((pf_generic)dragon_name, "namedragon"); + register_function((pf_generic)dracoid_name, "namedracoid"); + register_function((pf_generic)generic_name, "namegeneric"); } diff --git a/src/kernel/names.h b/src/kernel/names.h index 03637d097..1bd1691d6 100644 --- a/src/kernel/names.h +++ b/src/kernel/names.h @@ -22,13 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif extern void register_names(void); - const char *undead_name(const struct unit *u); - const char *skeleton_name(const struct unit *u); - const char *zombie_name(const struct unit *u); - const char *ghoul_name(const struct unit *u); - const char *dragon_name(const struct unit *u); - const char *dracoid_name(const struct unit *u); - const char *generic_name(const struct unit *u); const char *abkz(const char *s, char *buf, size_t size, size_t maxchars); #ifdef __cplusplus diff --git a/src/kernel/race.c b/src/kernel/race.c index 508b2d00b..c6325a9bc 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -82,7 +82,8 @@ static race * race_cache[MAXRACES]; struct race *get_race(race_t rt) { static int cache = -1; const char * name; - + race * result = 0; + assert(rt < MAXRACES); name = racenames[rt]; if (!name) { @@ -93,13 +94,12 @@ struct race *get_race(race_t rt) { memset(race_cache, 0, sizeof(race_cache)); return race_cache[rt] = rc_get_or_create(name); } else { - race * result = race_cache[rt]; + result = race_cache[rt]; if (!result) { result = race_cache[rt] = rc_get_or_create(name); } - return result; } - return 0; + return result; } race_list *get_familiarraces(void) @@ -151,7 +151,7 @@ static race *rc_find_i(const char *name) const char *rname = name; race *rc = races; - while (rc && !strcmp(rname, rc->_name[0]) == 0) { + while (rc && !strcmp(rname, rc->_name) == 0) { rc = rc->next; } return rc; @@ -177,13 +177,7 @@ race *rc_get_or_create(const char *zName) assert(strchr(zName, ' ') == NULL); } strcpy(zBuffer, zName); - rc->_name[0] = _strdup(zBuffer); - sprintf(zBuffer, "%s_p", zName); - rc->_name[1] = _strdup(zBuffer); - sprintf(zBuffer, "%s_d", zName); - rc->_name[2] = _strdup(zBuffer); - sprintf(zBuffer, "%s_x", zName); - rc->_name[3] = _strdup(zBuffer); + rc->_name = _strdup(zBuffer); rc->precombatspell = NULL; rc->attack[0].type = AT_COMBATSPELL; @@ -220,19 +214,30 @@ extern void add_raceprefix(const char *prefix) race_prefixes[next] = NULL; } -/* Die Bezeichnungen dürfen wegen der Art des Speicherns keine - * Leerzeichen enthalten! */ - -/* "den Zwergen", "Halblingsparteien" */ - bool r_insectstalled(const region * r) { return fval(r->terrain, ARCTIC_REGION); } -const char *rc_name(const race * rc, int n) +const char *rc_name(const race * rc, name_t n) { - return rc ? mkname("race", rc->_name[n]) : NULL; + const char * postfix = 0; + if (!rc) { + return NULL; + } + switch (n) { + case NAME_SINGULAR: postfix = ""; break; + case NAME_PLURAL: postfix = "_p"; break; + case NAME_DEFINITIVE: postfix = "_d"; break; + case NAME_CATEGORY: postfix = "_x"; break; + default: assert(!"invalid name_t enum in rc_name"); + } + if (postfix) { + static char name[64]; // FIXME: static variable return + sprintf(name, "race::%s%s", rc->_name, postfix); + return name; + } + return NULL; } const char *raceprefix(const unit * u) @@ -271,8 +276,8 @@ const char *racename(const struct locale *loc, const unit * u, const race * rc) return lbuf; } - str = LOC(loc, rc_name(rc, u->number != 1)); - return str ? str : rc->_name[0]; + str = LOC(loc, rc_name(rc, (u->number == 1) ? NAME_SINGULAR : NAME_PLURAL)); + return str ? str : rc->_name; } int @@ -313,7 +318,7 @@ rc_specialdamage(const race * ar, const race * dr, void write_race_reference(const race * rc, struct storage *store) { - WRITE_TOK(store, rc ? rc->_name[0] : "none"); + WRITE_TOK(store, rc ? rc->_name : "none"); } variant read_race_reference(struct storage *store) diff --git a/src/kernel/race.h b/src/kernel/race.h index 62793bb12..d5214e8c9 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -119,7 +119,7 @@ extern "C" { typedef struct race { struct param *parameters; - const char *_name[4]; /* neu: name[4]völker */ + const char *_name; /* neu: name[4]völker */ float magres; float maxaura; /* Faktor auf Maximale Aura */ float regaura; /* Faktor auf Regeneration */ @@ -134,7 +134,7 @@ extern "C" { float aggression; /* chance that a monster will attack */ int hitpoints; const char *def_damage; - char armor; + int armor; int at_default; /* Angriffsskill Unbewaffnet (default: -2) */ int df_default; /* Verteidigungsskill Unbewaffnet (default: -2) */ int at_bonus; /* Verändert den Angriffsskill (default: 0) */ @@ -178,11 +178,13 @@ extern "C" { extern race *rc_get_or_create(const char *name); extern const race *rc_find(const char *); - extern const char *rc_name(const race *, int); extern int rc_specialdamage(const race *, const race *, const struct weapon_type *); void free_races(void); + typedef enum name_t { NAME_SINGULAR, NAME_PLURAL, NAME_DEFINITIVE, NAME_CATEGORY } name_t; + const char *rc_name(const race *, name_t); + /* Flags. Do not reorder these without changing json_race() in jsonconf.c */ #define RCF_NPC (1<<0) /* cannot be the race for a player faction (and other limits?) */ #define RCF_KILLPEASANTS (1<<1) /* a monster that eats peasants */ diff --git a/src/kernel/race.test.c b/src/kernel/race.test.c new file mode 100644 index 000000000..ed544cc48 --- /dev/null +++ b/src/kernel/race.test.c @@ -0,0 +1,24 @@ +#include +#include +#include "race.h" +#include +#include + +#include +#include + +static void test_rc_name(CuTest *tc) { + struct race *rc = test_create_race("human"); + CuAssertStrEquals(tc, "race::human", rc_name(rc, NAME_SINGULAR)); + CuAssertStrEquals(tc, "race::human_p", rc_name(rc, NAME_PLURAL)); + CuAssertStrEquals(tc, "race::human_d", rc_name(rc, NAME_DEFINITIVE)); + CuAssertStrEquals(tc, "race::human_x", rc_name(rc, NAME_CATEGORY)); +} + +CuSuite *get_race_suite(void) +{ + CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_rc_name); + return suite; +} + diff --git a/src/kernel/region.c b/src/kernel/region.c index 5ce29b6c8..f75bfb46f 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -386,12 +386,12 @@ static int dummy_data; static region *dummy_ptr = (region *) & dummy_data; /* a funny hack */ typedef struct uidhashentry { - unsigned int uid; + int uid; region *r; } uidhashentry; static uidhashentry uidhash[MAXREGIONS]; -struct region *findregionbyid(unsigned int uid) +struct region *findregionbyid(int uid) { int key = uid % MAXREGIONS; while (uidhash[key].uid != 0 && uidhash[key].uid != uid) @@ -413,7 +413,7 @@ static void unhash_uid(region * r) static void hash_uid(region * r) { - unsigned int uid = r->uid; + int uid = r->uid; for (;;) { if (uid != 0) { int key = uid % MAXREGIONS; @@ -940,7 +940,7 @@ static region *last; static unsigned int max_index = 0; -region *new_region(int x, int y, struct plane *pl, unsigned int uid) +region *new_region(int x, int y, struct plane *pl, int uid) { region *r; @@ -1409,7 +1409,7 @@ int resolve_region_id(variant id, void *address) { region *r = NULL; if (id.i != 0) { - r = findregionbyid((unsigned int)id.i); + r = findregionbyid(id.i); if (r == NULL) { *(region **) address = NULL; return -1; diff --git a/src/kernel/region.h b/src/kernel/region.h index 1e5493ad3..367d77385 100644 --- a/src/kernel/region.h +++ b/src/kernel/region.h @@ -120,7 +120,7 @@ extern "C" { /* an ascending number, to improve the speed of determining the interval in which a faction has its units. See the implementations of firstregion and lastregion */ - unsigned int uid; /* a unique id */ + int uid; /* a unique id */ int x, y; struct plane *_plane; /* to access, use rplane(r) */ char *display; @@ -171,7 +171,7 @@ extern "C" { int koor_distance(int ax, int ay, int bx, int by); direction_t reldirection(const struct region *from, const struct region *to); struct region *findregion(int x, int y); - struct region *findregionbyid(unsigned int uid); + struct region *findregionbyid(int uid); extern struct attrib_type at_direction; extern struct attrib_type at_moveblock; @@ -251,7 +251,7 @@ extern "C" { const char *write_regionname(const struct region *r, const struct faction *f, char *buffer, size_t size); - struct region *new_region(int x, int y, struct plane *pl, unsigned int uid); + struct region *new_region(int x, int y, struct plane *pl, int uid); void remove_region(region ** rlist, region * r); void terraform_region(struct region *r, const struct terrain_type *terrain); bool pnormalize(int *x, int *y, const struct plane *pl); diff --git a/src/kernel/reports.c b/src/kernel/reports.c index 51e2369ce..68283a1f6 100644 --- a/src/kernel/reports.c +++ b/src/kernel/reports.c @@ -331,14 +331,14 @@ void report_race(const struct unit *u, const char **name, const char **illusion) if (illusion) { const race *irace = u_irace(u); if (irace && irace != u_race(u)) { - *illusion = irace->_name[0]; + *illusion = irace->_name; } else { *illusion = NULL; } } if (name) { - *name = u_race(u)->_name[0]; + *name = u_race(u)->_name; if (fval(u_race(u), RCF_SHAPESHIFTANY)) { const char *str = get_racename(u->attribs); if (str) @@ -2166,7 +2166,7 @@ static void eval_race(struct opstack **stack, const void *userdata) const struct locale *lang = report ? report->locale : default_locale; int j = opop(stack).i; const race *r = (const race *)opop(stack).v; - const char *c = LOC(lang, rc_name(r, j != 1)); + const char *c = LOC(lang, rc_name(r, (j == 1) ? NAME_SINGULAR : NAME_PLURAL)); size_t len = strlen(c); variant var; diff --git a/src/kernel/save.c b/src/kernel/save.c index af608f4b1..0180f0ead 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -810,8 +810,8 @@ void write_unit(struct gamedata *data, const unit * u) WRITE_STR(data->store, u->display ? (const char *)u->display : ""); WRITE_INT(data->store, u->number); WRITE_INT(data->store, u->age); - WRITE_TOK(data->store, u_race(u)->_name[0]); - WRITE_TOK(data->store, (irace && irace != u_race(u)) ? irace->_name[0] : ""); + WRITE_TOK(data->store, u_race(u)->_name); + WRITE_TOK(data->store, (irace && irace != u_race(u)) ? irace->_name : ""); write_building_reference(u->building, data->store); write_ship_reference(u->ship, data->store); WRITE_INT(data->store, u->status); @@ -1412,7 +1412,7 @@ void writefaction(struct gamedata *data, const faction * f) WRITE_TOK(data->store, locale_name(f->locale)); WRITE_INT(data->store, f->lastorders); WRITE_INT(data->store, f->age); - WRITE_TOK(data->store, f->race->_name[0]); + WRITE_TOK(data->store, f->race->_name); WRITE_SECTION(data->store); WRITE_INT(data->store, f->magiegebiet); diff --git a/src/kernel/skills.c b/src/kernel/skills.c index 9ae09a162..fef434bf0 100644 --- a/src/kernel/skills.c +++ b/src/kernel/skills.c @@ -158,7 +158,7 @@ int rc_skillmod(const struct race *rc, const region * r, skill_t sk) return 0; } #ifdef FASTER_SKILLMOD - unsigned int index = hashstring(rc->_name[0]) % RCMODMAXHASH; + unsigned int index = hashstring(rc->_name) % RCMODMAXHASH; struct skillmods **imods = &modhash[index]; while (*imods && (*imods)->race != rc) { imods = &(*imods)->next; diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 933fcaaa2..18d284e94 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1781,7 +1781,7 @@ static int parse_races(xmlDocPtr doc) rc->study_speed[sk] = (char)speed; } } else { - log_error("unknown skill '%s' in race '%s'\n", (const char *)propValue, rc->_name[0]); + log_error("unknown skill '%s' in race '%s'\n", (const char *)propValue, rc->_name); } xmlFree(propValue); } @@ -1796,7 +1796,7 @@ static int parse_races(xmlDocPtr doc) parse_function(node, &fun, &propValue); if (fun == NULL) { - log_error("unknown function name '%s' for race %s\n", (const char *)propValue, rc->_name[0]); + log_error("unknown function name '%s' for race %s\n", (const char *)propValue, rc->_name); xmlFree(propValue); continue; } @@ -1816,7 +1816,7 @@ static int parse_races(xmlDocPtr doc) } else if (strcmp((const char *)propValue, "initfamiliar") == 0) { rc->init_familiar = (void (*)(struct unit *))fun; } else { - log_error("unknown function type '%s' for race %s\n", (const char *)propValue, rc->_name[0]); + log_error("unknown function type '%s' for race %s\n", (const char *)propValue, rc->_name); } xmlFree(propValue); } @@ -1871,7 +1871,7 @@ static int parse_races(xmlDocPtr doc) if (attack->data.sp) { attack->level = xml_ivalue(node, "level", 0); if (attack->level <= 0) { - log_error("magical attack '%s' for race '%s' needs a level: %d\n", attack->data.sp->sname, rc->_name[0], attack->level); + log_error("magical attack '%s' for race '%s' needs a level: %d\n", attack->data.sp->sname, rc->_name, attack->level); } } } diff --git a/src/laws.c b/src/laws.c index db48dde0b..1c4ba2954 100755 --- a/src/laws.c +++ b/src/laws.c @@ -1006,7 +1006,7 @@ static void inactivefaction(faction * f) if (inactiveFILE) { fprintf(inactiveFILE, "%s:%s:%d:%d\n", factionid(f), - LOC(default_locale, rc_name(f->race, 1)), + LOC(default_locale, rc_name(f->race, NAME_PLURAL)), modify(count_all(f)), turn - f->lastorders); fclose(inactiveFILE); @@ -1707,7 +1707,7 @@ int prefix_cmd(unit * u, struct order *ord) init_order(ord); s = getstrtoken(); - if (!*s) { + if (!s || !*s) { attrib *a = NULL; if (fval(u, UFL_GROUP)) { a = a_find(u->attribs, &at_group); @@ -1721,8 +1721,7 @@ int prefix_cmd(unit * u, struct order *ord) } return 0; } - - if (findtoken(in->names, s, &var) == E_TOK_NOMATCH) { + else if (findtoken(in->names, s, &var) == E_TOK_NOMATCH) { return 0; } else if (race_prefixes[var.i] == NULL) { @@ -2524,13 +2523,13 @@ static bool display_race(faction * f, unit * u, const race * rc) if (u && u_race(u) != rc) return false; - name = rc_name(rc, 0); + name = rc_name(rc, NAME_SINGULAR); bytes = slprintf(bufp, size, "%s: ", LOC(f->locale, name)); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - key = mkname("raceinfo", rc->_name[0]); + key = mkname("raceinfo", rc->_name); info = locale_getstring(f->locale, key); if (info == NULL) { info = locale_string(f->locale, mkname("raceinfo", "no_info")); diff --git a/src/modules/score.c b/src/modules/score.c index d633d5105..a6b49dc58 100644 --- a/src/modules/score.c +++ b/src/modules/score.c @@ -164,7 +164,7 @@ void score(void) f->score, f->score - average_score_of_age(f->age, f->age / 24 + 1), ((float)f->score / (float)allscores) * 100.0, (float)f->score / f->num_total, - f->name, LOC(default_locale, rc_name(f->race, 0)), factionid(f), + f->name, LOC(default_locale, rc_name(f->race, NAME_SINGULAR)), factionid(f), f->age); } fclose(scoreFP); diff --git a/src/monsters.c b/src/monsters.c index 0edc5cda2..1fe54cd26 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -919,7 +919,7 @@ void spawn_dragons(void) if (verbosity >= 2) { log_printf(stdout, "%d %s in %s.\n", u->number, LOC(default_locale, - rc_name(u_race(u), u->number != 1)), regionname(r, NULL)); + rc_name(u_race(u), (u->number==1) ? NAME_SINGULAR:NAME_PLURAL)), regionname(r, NULL)); } name_unit(u); @@ -994,7 +994,7 @@ void spawn_undead(void) if (verbosity >= 2) { log_printf(stdout, "%d %s in %s.\n", u->number, LOC(default_locale, - rc_name(u_race(u), u->number != 1)), regionname(r, NULL)); + rc_name(u_race(u), (u->number == 1) ? NAME_SINGULAR : NAME_PLURAL)), regionname(r, NULL)); } { diff --git a/src/races/races.c b/src/races/races.c index 441f0f974..306b65e78 100644 --- a/src/races/races.c +++ b/src/races/races.c @@ -43,7 +43,7 @@ static void oldfamiliars(unit * u) char fname[64]; /* these familiars have no special skills. */ - _snprintf(fname, sizeof(fname), "%s_familiar", u_race(u)->_name[0]); + _snprintf(fname, sizeof(fname), "%s_familiar", u_race(u)->_name); create_mage(u, M_GRAY); equip_unit(u, get_equipment(fname)); } diff --git a/src/report.c b/src/report.c index afd2ee3ac..03de0e889 100644 --- a/src/report.c +++ b/src/report.c @@ -2174,7 +2174,7 @@ const char *charset) centre(F, gamedate_season(f->locale), true); rnl(F); sprintf(buf, "%s, %s/%s (%s)", factionname(f), - LOC(f->locale, rc_name(f->race, 1)), + LOC(f->locale, rc_name(f->race, NAME_PLURAL)), LOC(f->locale, mkname("school", magic_school[f->magiegebiet])), f->email); centre(F, buf, true); if (f_get_alliance(f)) { diff --git a/src/spells/spells.c b/src/spells/spells.c index 930cfc633..507f07935 100644 --- a/src/spells/spells.c +++ b/src/spells/spells.c @@ -480,7 +480,7 @@ static const race *select_familiar(const race * magerace, magic_t magiegebiet) retval = magerace->familiars[0]; } if (!retval) { - log_error("select_familiar: No familiar (not even a default) defined for %s.\n", magerace->_name[0]); + log_error("select_familiar: No familiar (not even a default) defined for %s.\n", magerace->_name); } return retval; } @@ -494,7 +494,7 @@ static void make_familiar(unit * familiar, unit * mage) if (u_race(familiar)->init_familiar != NULL) { u_race(familiar)->init_familiar(familiar); } else { - log_error("could not perform initialization for familiar %s.\n", familiar->faction->race->_name[0]); + log_error("could not perform initialization for familiar %s.\n", familiar->faction->race->_name); } /* triggers: */ @@ -524,7 +524,7 @@ static int sp_summon_familiar(castorder * co) } rc = select_familiar(mage->faction->race, mage->faction->magiegebiet); if (rc == NULL) { - log_error("could not find suitable familiar for %s.\n", mage->faction->race->_name[0]); + log_error("could not find suitable familiar for %s.\n", mage->faction->race->_name); return 0; } @@ -1482,7 +1482,7 @@ static int sp_create_irongolem(castorder * co) ADDMSG(&mage->faction->msgs, msg_message("magiccreate_effect", "region command unit amount object", mage->region, co->order, mage, number, - LOC(mage->faction->locale, rc_name(rc_find("irongolem"), 1)))); + LOC(mage->faction->locale, rc_name(rc_find("irongolem"), (u2->number == 1) ? NAME_SINGULAR : NAME_PLURAL)))); return cast_level; } @@ -1543,7 +1543,7 @@ static int sp_create_stonegolem(castorder * co) ADDMSG(&mage->faction->msgs, msg_message("magiccreate_effect", "region command unit amount object", mage->region, co->order, mage, number, - LOC(mage->faction->locale, rc_name(rc_find("stonegolem"), 1)))); + LOC(mage->faction->locale, rc_name(rc_find("stonegolem"), (u2->number == 1) ? NAME_SINGULAR : NAME_PLURAL)))); return cast_level; } @@ -5551,7 +5551,7 @@ int sp_showastral(castorder * co) } icat(u->number); scat(" "); - scat(LOC(mage->faction->locale, rc_name(u_race(u), u->number != 1))); + scat(LOC(mage->faction->locale, rc_name(u_race(u), (u->number==1) ? NAME_SINGULAR:NAME_PLURAL))); scat(", Entfernung "); icat(distance(rl2->data, rt)); scat(")"); diff --git a/src/sqlite.c b/src/sqlite.c index 37ac8f24f..4e7a8ec2e 100644 --- a/src/sqlite.c +++ b/src/sqlite.c @@ -111,7 +111,7 @@ static int insert_faction(sqlite3 *db, int game_id, faction *f) { sqlite3_stmt *stmt = 0; sqlite3_prepare_v2(db, sql, -1, &stmt, 0); sqlite3_bind_int(stmt, 1, game_id); - sqlite3_bind_text(stmt, 2, f->race->_name[0], -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 2, f->race->_name, -1, SQLITE_STATIC); sqlite3_step(stmt); sqlite3_finalize(stmt); return (int)sqlite3_last_insert_rowid(db); diff --git a/src/summary.c b/src/summary.c index aeb313f6a..f131bbf53 100644 --- a/src/summary.c +++ b/src/summary.c @@ -92,11 +92,11 @@ static void out_faction(FILE * file, const struct faction *f) if (alliances != NULL) { fprintf(file, "%s (%s/%d) (%.3s/%.3s), %d Einh., %d Pers., $%d, %d NMR\n", f->name, itoa36(f->no), f_get_alliance(f) ? f->alliance->id : 0, - LOC(default_locale, rc_name(f->race, 0)), magic_school[f->magiegebiet], + LOC(default_locale, rc_name(f->race, NAME_SINGULAR)), magic_school[f->magiegebiet], count_units(f), f->num_total, f->money, turn - f->lastorders); } else { fprintf(file, "%s (%.3s/%.3s), %d Einh., %d Pers., $%d, %d NMR\n", - factionname(f), LOC(default_locale, rc_name(f->race, 0)), + factionname(f), LOC(default_locale, rc_name(f->race, NAME_SINGULAR)), magic_school[f->magiegebiet], count_units(f), f->num_total, f->money, turn - f->lastorders); } @@ -185,7 +185,7 @@ void report_summary(summary * s, summary * o, bool full) if (i != RC_TEMPLATE && i != RC_CLONE && s->factionrace[i]) { const race *rc = get_race(i); if (rc && playerrace(rc)) { - fprintf(F, "%13s%s: %s\n", LOC(default_locale, rc_name(rc, 3)), + fprintf(F, "%13s%s: %s\n", LOC(default_locale, rc_name(rc, NAME_CATEGORY)), LOC(default_locale, "stat_tribe_p"), pcomp(s->factionrace[i], o->factionrace[i])); } @@ -215,7 +215,7 @@ void report_summary(summary * s, summary * o, bool full) for (i = 0; i < MAXRACES; i++) { if (s->poprace[i]) { const race *rc = get_race(i); - fprintf(F, "%20s: %s\n", LOC(default_locale, rc_name(rc, 1)), + fprintf(F, "%20s: %s\n", LOC(default_locale, rc_name(rc, NAME_PLURAL)), rcomp(s->poprace[i], o->poprace[i])); } } @@ -224,7 +224,7 @@ void report_summary(summary * s, summary * o, bool full) if (i != RC_TEMPLATE && i != RC_CLONE && s->poprace[i]) { const race *rc = get_race(i); if (playerrace(rc)) { - fprintf(F, "%20s: %s\n", LOC(default_locale, rc_name(rc, 1)), + fprintf(F, "%20s: %s\n", LOC(default_locale, rc_name(rc, NAME_PLURAL)), rcomp(s->poprace[i], o->poprace[i])); } } diff --git a/src/test_eressea.c b/src/test_eressea.c index 576be8b60..85a00bf64 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -27,6 +27,7 @@ int RunAllTests(void) ADD_TESTS(suite, skill); ADD_TESTS(suite, keyword); ADD_TESTS(suite, order); + ADD_TESTS(suite, race); /* util */ ADD_TESTS(suite, config); ADD_TESTS(suite, base36);