From be14394529305cfeeab26e6b06f1621094cedff4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 19 Feb 2017 16:33:24 +0100 Subject: [PATCH 01/10] load locales and rules separately (xml prep work) --- conf/e2/locales.xml | 1 + conf/e2/{config.xml => rules.xml} | 13 ------------- conf/e3/locales.xml | 13 +++++++++++++ conf/e3/{config.xml => rules.xml} | 5 ----- scripts/eressea/xmlconf.lua | 3 ++- 5 files changed, 16 insertions(+), 19 deletions(-) rename conf/e2/{config.xml => rules.xml} (75%) create mode 100644 conf/e3/locales.xml rename conf/e3/{config.xml => rules.xml} (84%) diff --git a/conf/e2/locales.xml b/conf/e2/locales.xml index f71525343..7a31bbc17 100644 --- a/conf/e2/locales.xml +++ b/conf/e2/locales.xml @@ -3,6 +3,7 @@ + diff --git a/conf/e2/config.xml b/conf/e2/rules.xml similarity index 75% rename from conf/e2/config.xml rename to conf/e2/rules.xml index 56c622d04..8d0b01b27 100644 --- a/conf/e2/config.xml +++ b/conf/e2/rules.xml @@ -1,11 +1,5 @@ - - - - - - @@ -26,7 +20,6 @@ - @@ -46,10 +39,4 @@ - - - - - - diff --git a/conf/e3/locales.xml b/conf/e3/locales.xml new file mode 100644 index 000000000..2d94bf202 --- /dev/null +++ b/conf/e3/locales.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/conf/e3/config.xml b/conf/e3/rules.xml similarity index 84% rename from conf/e3/config.xml rename to conf/e3/rules.xml index ac05d5a5a..421b54d7a 100644 --- a/conf/e3/config.xml +++ b/conf/e3/rules.xml @@ -1,8 +1,5 @@ - - - @@ -15,8 +12,6 @@ - - diff --git a/scripts/eressea/xmlconf.lua b/scripts/eressea/xmlconf.lua index 584f8d3e2..84f29eceb 100644 --- a/scripts/eressea/xmlconf.lua +++ b/scripts/eressea/xmlconf.lua @@ -4,7 +4,8 @@ if config.install then end if config.rules then local rules = config.rules .. '/' - assert(0 == read_xml(confdir .. rules .. 'config.xml', confdir .. rules .. 'catalog.xml'), "could not load XML data, did you compile with LIBXML2 ?") assert(0 == eressea.config.read(rules .. 'config.json', confdir), "could not read JSON data") + assert(0 == read_xml(confdir .. rules .. 'rules.xml', confdir .. rules .. 'catalog.xml'), "could not load XML data, did you compile with LIBXML2 ?") + assert(0 == read_xml(confdir .. rules .. 'locales.xml', confdir .. rules .. 'catalog.xml'), "could not load XML data, did you compile with LIBXML2 ?") end eressea.game.reset() From ba1fdcce599110bb95c74b0b3753cbb991cbae91 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Feb 2017 07:47:36 +0100 Subject: [PATCH 02/10] remove race.describe funpointer --- res/e3a/races.xml | 1 - res/eressea/races.xml | 1 - src/kernel/race.c | 4 ---- src/kernel/race.h | 3 --- src/kernel/save.c | 11 ----------- src/kernel/unit.c | 11 +++++++++-- src/kernel/unit.test.c | 14 ++++++++++++-- src/kernel/xmlreader.c | 3 --- src/names.c | 28 ++++++++++------------------ src/names.test.c | 1 - 10 files changed, 31 insertions(+), 46 deletions(-) diff --git a/res/e3a/races.xml b/res/e3a/races.xml index ccc118877..acc002b1a 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -615,7 +615,6 @@ - diff --git a/res/eressea/races.xml b/res/eressea/races.xml index 3cf5136a4..9f3624d70 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -602,7 +602,6 @@ regaura="1.000000" weight="100" capacity="540" speed="1.000000" hp="20" damage="0d0" unarmedattack="0" unarmeddefense="0" attackmodifier="6" defensemodifier="10" scarepeasants="yes" fly="yes" walk="yes" teach="no" invinciblenonmagic="yes"> - diff --git a/src/kernel/race.c b/src/kernel/race.c index 2ede414c7..1385bd932 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -542,10 +542,6 @@ variant read_race_reference(struct storage *store) return result; } -void register_race_description_function(race_desc_func func, const char *name) { - register_function((pf_generic)func, name); -} - void register_race_name_function(race_name_func func, const char *name) { register_function((pf_generic)func, name); } diff --git a/src/kernel/race.h b/src/kernel/race.h index ceb5e59d9..80f2622f3 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -112,7 +112,6 @@ extern "C" { int level; } att; - typedef const char *(*race_desc_func)(const struct race *rc, const struct locale *lang); typedef void (*race_name_func)(struct unit *); typedef struct race { @@ -145,7 +144,6 @@ extern "C" { signed char bonus[MAXSKILLS]; race_name_func generate_name; - race_desc_func describe; void(*age) (struct unit * u); bool(*move_allowed) (const struct region *, const struct region *); struct item *(*itemdrop) (const struct race *, int size); @@ -267,7 +265,6 @@ extern "C" { const char *raceprefix(const struct unit *u); void register_race_name_function(race_name_func, const char *); - void register_race_description_function(race_desc_func, const char *); #ifdef __cplusplus } diff --git a/src/kernel/save.c b/src/kernel/save.c index 3ddaf7a7c..d4045d05f 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -695,17 +695,6 @@ unit *read_unit(struct gamedata *data) else u->irace = NULL; - if (rc->describe) { - const char *rcdisp = rc->describe(rc, u->faction->locale); - if (u->display && rcdisp) { - /* see if the data file contains old descriptions */ - if (strcmp(rcdisp, u->display) == 0) { - free(u->display); - u->display = NULL; - } - } - } - READ_INT(data->store, &n); if (n > 0) { building * b = findbuilding(n); diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 1acebac6d..ab1669ed9 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -531,8 +531,15 @@ const char *u_description(const unit * u, const struct locale *lang) if (u->display && u->display[0]) { return u->display; } - else if (u_race(u)->describe) { - return u_race(u)->describe(u->_race, lang); + else { + char zText[64]; + const char * d; + const race * rc = u_race(u); + snprintf(zText, sizeof(zText), "describe_%s", rc->_name); + d = locale_getstring(lang, zText); + if (d) { + return d; + } } return NULL; } diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index 16ff2890b..c187f7bab 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -390,14 +390,24 @@ static void test_limited_skills(CuTest *tc) { static void test_unit_description(CuTest *tc) { race *rc; unit *u; + struct locale *lang; + test_setup(); + lang = test_create_locale(); rc = test_create_race("hodor"); u = test_create_unit(test_create_faction(rc), test_create_region(0,0,0)); + CuAssertPtrEquals(tc, 0, u->display); - CuAssertStrEquals(tc, 0, u_description(u, u->faction->locale)); + CuAssertStrEquals(tc, 0, u_description(u, lang)); u->display = strdup("Hodor"); CuAssertStrEquals(tc, "Hodor", u_description(u, NULL)); - CuAssertStrEquals(tc, "Hodor", u_description(u, u->faction->locale)); + CuAssertStrEquals(tc, "Hodor", u_description(u, lang)); + + free(u->display); + u->display = NULL; + locale_setstring(lang, "describe_hodor", "HODOR"); + CuAssertStrEquals(tc, "HODOR", u_description(u, lang)); + test_cleanup(); } diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 2cf0b42e8..44a8c161e 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1795,9 +1795,6 @@ static int parse_races(xmlDocPtr doc) if (strcmp((const char *)propValue, "name") == 0) { rc->generate_name = (race_name_func)fun; } - else if (strcmp((const char *)propValue, "describe") == 0) { - rc->describe = (race_desc_func)fun; - } else if (strcmp((const char *)propValue, "age") == 0) { rc->age = (void(*)(struct unit *))fun; } diff --git a/src/names.c b/src/names.c index cf0d9fd09..780386deb 100644 --- a/src/names.c +++ b/src/names.c @@ -45,13 +45,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -static const char *describe_race(const race * rc, const struct locale *lang) -{ - char zText[32]; - sprintf(zText, "describe_%s", rc->_name); - return locale_getstring(lang, zText); -} - static void count_particles(const char *monster, int *num_prefix, int *num_name, int *num_postfix) { char zText[32]; @@ -395,29 +388,29 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars) int result; UNUSED_ARG(buflen); - /* Prüfen, ob Kurz genug */ + /* Pr�fen, ob Kurz genug */ if (strlen(s) <= maxchars) { return s; } - /* Anzahl der Wörter feststellen */ + /* 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 überspringen */ + /* 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 */ + /* Counter erh�hen */ if (*p != 0) ++c; - /* alnums überspringen */ + /* alnums �berspringen */ while (*p != 0 && iswalnum((wint_t)ucs)) { p += size; result = unicode_utf8_to_ucs4(&ucs, p, &size); @@ -425,10 +418,10 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars) } } - /* Buchstaben pro Teilkürzel = MAX(1,max/AnzWort) */ + /* Buchstaben pro Teilk�rzel = MAX(1,max/AnzWort) */ bpt = (c > 0) ? MAX(1, maxchars / c) : 1; - /* Einzelne Wörter anspringen und jeweils die ersten BpT kopieren */ + /* Einzelne W�rter anspringen und jeweils die ersten BpT kopieren */ p = s; c = 0; @@ -438,7 +431,7 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars) assert(result == 0 || "damnit, we're not handling invalid input here!"); while (*p != 0 && c < maxchars) { - /* Leerzeichen überspringen */ + /* Leerzeichen �berspringen */ while (*p != 0 && !iswalnum((wint_t)ucs)) { p += size; @@ -446,7 +439,7 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars) assert(result == 0 || "damnit, we're not handling invalid input here!"); } - /* alnums übertragen */ + /* alnums �bertragen */ for (i = 0; i < bpt && *p != 0 && iswalnum((wint_t)ucs); ++i) { memcpy(bufp, p, size); @@ -458,7 +451,7 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars) assert(result == 0 || "damnit, we're not handling invalid input here!"); } - /* Bis zum nächsten Leerzeichen */ + /* Bis zum n�chsten Leerzeichen */ while (c < maxchars && *p != 0 && iswalnum((wint_t)ucs)) { p += size; @@ -474,7 +467,6 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars) void register_names(void) { - register_race_description_function(describe_race, "describe_race"); /* function name * generate a name for a nonplayerunit * race->generate_name() */ diff --git a/src/names.test.c b/src/names.test.c index 8109fc2d4..01fe0ff41 100644 --- a/src/names.test.c +++ b/src/names.test.c @@ -32,7 +32,6 @@ static void test_names(CuTest * tc) CuAssertPtrNotNull(tc, get_function("namedragon")); CuAssertPtrNotNull(tc, get_function("namedracoid")); CuAssertPtrNotNull(tc, get_function("namegeneric")); - CuAssertPtrNotNull(tc, get_function("describe_race")); test_cleanup(); } From 59f87edbb1ca38e6b078a70d13ef2ea53cd907f2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Feb 2017 09:00:48 +0100 Subject: [PATCH 03/10] remove unused race.move_allowed method --- res/e3a/races.xml | 1 - res/eressea/races.xml | 5 ----- res/races/dragon.xml | 1 - res/races/wyrm.xml | 1 - res/races/youngdragon.xml | 1 - src/kernel/race.h | 1 - src/kernel/xmlreader.c | 4 ---- src/races/races.c | 4 +--- 8 files changed, 1 insertion(+), 17 deletions(-) diff --git a/res/e3a/races.xml b/res/e3a/races.xml index acc002b1a..1036ba223 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -875,7 +875,6 @@ - diff --git a/res/eressea/races.xml b/res/eressea/races.xml index 9f3624d70..6899a8070 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -732,7 +732,6 @@ - @@ -745,7 +744,6 @@ - @@ -758,7 +756,6 @@ - @@ -1141,7 +1138,6 @@ - @@ -1273,7 +1269,6 @@ - diff --git a/res/races/dragon.xml b/res/races/dragon.xml index f8022d0a4..7a36e4b84 100644 --- a/res/races/dragon.xml +++ b/res/races/dragon.xml @@ -6,7 +6,6 @@ dragon="yes"> - diff --git a/res/races/wyrm.xml b/res/races/wyrm.xml index 3ee48ca67..dab1a9e1f 100644 --- a/res/races/wyrm.xml +++ b/res/races/wyrm.xml @@ -5,7 +5,6 @@ defensemodifier="10" scarepeasants="yes" fly="yes" walk="yes" teach="no" getitem="yes" resistbash="yes" dragon="yes" income="5000"> - diff --git a/res/races/youngdragon.xml b/res/races/youngdragon.xml index d5b23b601..0ac2d35be 100644 --- a/res/races/youngdragon.xml +++ b/res/races/youngdragon.xml @@ -6,7 +6,6 @@ teach="no" getitem="yes" resistbash="yes" dragon="yes" income="150"> - diff --git a/src/kernel/race.h b/src/kernel/race.h index 80f2622f3..32ff05ebd 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -145,7 +145,6 @@ extern "C" { race_name_func generate_name; void(*age) (struct unit * u); - bool(*move_allowed) (const struct region *, const struct region *); struct item *(*itemdrop) (const struct race *, int size); void(*init_familiar) (struct unit *); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 44a8c161e..508516671 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1798,10 +1798,6 @@ static int parse_races(xmlDocPtr doc) else if (strcmp((const char *)propValue, "age") == 0) { rc->age = (void(*)(struct unit *))fun; } - else if (strcmp((const char *)propValue, "move") == 0) { - rc->move_allowed = - (bool(*)(const struct region *, const struct region *))fun; - } else if (strcmp((const char *)propValue, "itemdrop") == 0) { rc->itemdrop = (struct item * (*)(const struct race *, int))fun; } diff --git a/src/races/races.c b/src/races/races.c index 8af9cf2ed..bb699520e 100644 --- a/src/races/races.c +++ b/src/races/races.c @@ -88,15 +88,13 @@ static void equip_newunits(const struct equipment *eq, struct unit *u) } } -/* Die Funktionen werden über den hier registrierten Namen in races.xml +/* Die Funktionen werden �ber den hier registrierten Namen in races.xml * in die jeweilige Rassendefiniton eingebunden */ void register_races(void) { /* function initfamiliar */ register_function((pf_generic)oldfamiliars, "oldfamiliars"); - register_function((pf_generic)allowed_dragon, "movedragon"); - register_function((pf_generic)allowed_swim, "moveswimming"); register_function((pf_generic)allowed_fly, "moveflying"); register_function((pf_generic)allowed_walk, "movewalking"); From 04154628e6ed8dd91b3c2bc5c7d07e7da1184c43 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Feb 2017 09:18:04 +0100 Subject: [PATCH 04/10] remove funpointer for spoils --- res/e3a/races.xml | 7 ------- res/eressea/races.xml | 11 ----------- res/races/aquarian.xml | 1 - res/races/cat.xml | 1 - res/races/demon.xml | 1 - res/races/dwarf.xml | 3 +-- res/races/elf.xml | 3 +-- res/races/goblin-2.xml | 1 - res/races/goblin-3.xml | 1 - res/races/goblin.xml | 1 - res/races/halfling.xml | 3 +-- res/races/human.xml | 1 - res/races/insect.xml | 3 +-- res/races/troll.xml | 1 - src/battle.c | 12 +++++------- src/kernel/item.c | 3 +-- src/kernel/item.h | 1 + src/kernel/race.h | 1 - src/kernel/xmlreader.c | 3 --- 19 files changed, 11 insertions(+), 47 deletions(-) diff --git a/res/e3a/races.xml b/res/e3a/races.xml index 1036ba223..e2cc60e55 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -34,7 +34,6 @@ - @@ -48,7 +47,6 @@ - @@ -76,7 +74,6 @@ - @@ -103,7 +100,6 @@ - @@ -123,7 +119,6 @@ - @@ -142,7 +137,6 @@ - @@ -165,7 +159,6 @@ - diff --git a/res/eressea/races.xml b/res/eressea/races.xml index 6899a8070..70dd1af9f 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -12,7 +12,6 @@ - @@ -780,7 +779,6 @@ - @@ -799,7 +797,6 @@ - @@ -825,7 +822,6 @@ - @@ -858,7 +854,6 @@ - @@ -888,7 +883,6 @@ - @@ -919,7 +913,6 @@ - @@ -951,7 +944,6 @@ - @@ -1149,7 +1141,6 @@ - @@ -1179,7 +1170,6 @@ - @@ -1206,7 +1196,6 @@ - diff --git a/res/races/aquarian.xml b/res/races/aquarian.xml index a0e1189b7..19fd3aee7 100644 --- a/res/races/aquarian.xml +++ b/res/races/aquarian.xml @@ -1,7 +1,6 @@ - diff --git a/res/races/cat.xml b/res/races/cat.xml index 75bc8019a..5986c223c 100644 --- a/res/races/cat.xml +++ b/res/races/cat.xml @@ -1,7 +1,6 @@ - diff --git a/res/races/demon.xml b/res/races/demon.xml index 0ce4c86ff..69d98145f 100644 --- a/res/races/demon.xml +++ b/res/races/demon.xml @@ -6,7 +6,6 @@ unarmedattack="-2" unarmeddefense="-2" playerrace="yes" walk="yes" shapeshift="yes" giveperson="yes" giveunit="yes" getitem="yes" recruitethereal="yes" equipment="yes" healing="1.5"> - diff --git a/res/races/dwarf.xml b/res/races/dwarf.xml index c5c4f2fcf..043b76aa7 100644 --- a/res/races/dwarf.xml +++ b/res/races/dwarf.xml @@ -1,7 +1,6 @@ - @@ -30,4 +29,4 @@ - \ No newline at end of file + diff --git a/res/races/elf.xml b/res/races/elf.xml index ee1278a26..683ee823b 100644 --- a/res/races/elf.xml +++ b/res/races/elf.xml @@ -1,7 +1,6 @@ - @@ -26,4 +25,4 @@ - \ No newline at end of file + diff --git a/res/races/goblin-2.xml b/res/races/goblin-2.xml index f8964d7c0..f26fa780e 100644 --- a/res/races/goblin-2.xml +++ b/res/races/goblin-2.xml @@ -5,7 +5,6 @@ speed="1.0" hp="16" damage="1d5" unarmedattack="-2" unarmeddefense="0" playerrace="yes" walk="yes" giveperson="yes" giveunit="yes" getitem="yes" equipment="yes" healing="2.0"> - diff --git a/res/races/goblin-3.xml b/res/races/goblin-3.xml index 4ad83967d..3fd594939 100644 --- a/res/races/goblin-3.xml +++ b/res/races/goblin-3.xml @@ -5,7 +5,6 @@ speed="1.0" hp="16" damage="1d5" unarmedattack="-2" unarmeddefense="0" playerrace="yes" walk="yes" giveperson="yes" giveunit="yes" getitem="yes" equipment="yes" healing="2.0"> - diff --git a/res/races/goblin.xml b/res/races/goblin.xml index 101cdaa86..a05d127e3 100644 --- a/res/races/goblin.xml +++ b/res/races/goblin.xml @@ -6,7 +6,6 @@ unarmedattack="-2" unarmeddefense="0" playerrace="yes" walk="yes" giveperson="yes" giveunit="yes" getitem="yes" equipment="yes" healing="2.0"> - diff --git a/res/races/halfling.xml b/res/races/halfling.xml index 4801685a0..3628d2b35 100644 --- a/res/races/halfling.xml +++ b/res/races/halfling.xml @@ -1,8 +1,7 @@ - - + diff --git a/res/races/human.xml b/res/races/human.xml index 8f1ad5cb4..f91ba7daf 100644 --- a/res/races/human.xml +++ b/res/races/human.xml @@ -1,7 +1,6 @@ - diff --git a/res/races/insect.xml b/res/races/insect.xml index dc9faa06d..75e16f7af 100644 --- a/res/races/insect.xml +++ b/res/races/insect.xml @@ -1,7 +1,6 @@ - @@ -27,4 +26,4 @@ - \ No newline at end of file + diff --git a/res/races/troll.xml b/res/races/troll.xml index c70020fa2..9168a6d0e 100644 --- a/res/races/troll.xml +++ b/res/races/troll.xml @@ -6,7 +6,6 @@ unarmedattack="-2" unarmeddefense="-2" playerrace="yes" walk="yes" giveperson="yes" giveunit="yes" getitem="yes" equipment="yes" healing="1.5"> - diff --git a/src/battle.c b/src/battle.c index 9ce22918a..0ff8eecaa 100644 --- a/src/battle.c +++ b/src/battle.c @@ -925,14 +925,12 @@ void kill_troop(troop dt) if (!df->alive) { char eqname[64]; const struct equipment *eq; - if (u_race(du)->itemdrop) { - item *drops = u_race(du)->itemdrop(u_race(du), du->number - df->run.number); - - if (drops != NULL) { - i_merge(&du->items, &drops); - } + const race *rc = u_race(du); + item *drops = item_spoil(rc, du->number - df->run.number); + if (drops != NULL) { + i_merge(&du->items, &drops); } - sprintf(eqname, "%s_spoils", u_race(du)->_name); + sprintf(eqname, "%s_spoils", rc->_name); eq = get_equipment(eqname); if (eq != NULL) { equip_items(&du->items, eq); diff --git a/src/kernel/item.c b/src/kernel/item.c index 177e44831..c37e3d40c 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -1175,7 +1175,7 @@ attrib_type at_resourcelimit = { finalize_resourcelimit, }; -static item *default_spoil(const struct race *rc, int size) +item *item_spoil(const struct race *rc, int size) { item *itm = NULL; @@ -1303,7 +1303,6 @@ void register_resources(void) register_function((pf_generic)res_changepermaura, "changepermaura"); register_function((pf_generic)res_changehp, "changehp"); register_function((pf_generic)res_changeaura, "changeaura"); - register_function((pf_generic)default_spoil, "defaultdrops"); register_item_use(use_potion, "usepotion"); register_item_use(use_potion_delayed, "usepotion_delayed"); diff --git a/src/kernel/item.h b/src/kernel/item.h index e6301c314..79e6f103d 100644 --- a/src/kernel/item.h +++ b/src/kernel/item.h @@ -309,6 +309,7 @@ extern "C" { extern const struct potion_type *oldpotiontype[]; const struct resource_type *get_resourcetype(resource_t rt); + struct item *item_spoil(const struct race *rc, int size); int get_item(const struct unit * u, const struct item_type *itype); int set_item(struct unit * u, const struct item_type *itype, int value); diff --git a/src/kernel/race.h b/src/kernel/race.h index 32ff05ebd..380b843bd 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -145,7 +145,6 @@ extern "C" { race_name_func generate_name; void(*age) (struct unit * u); - struct item *(*itemdrop) (const struct race *, int size); void(*init_familiar) (struct unit *); struct rcoption *options; /* rarely used properties */ diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 508516671..97fab3b8d 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1798,9 +1798,6 @@ static int parse_races(xmlDocPtr doc) else if (strcmp((const char *)propValue, "age") == 0) { rc->age = (void(*)(struct unit *))fun; } - else if (strcmp((const char *)propValue, "itemdrop") == 0) { - rc->itemdrop = (struct item * (*)(const struct race *, int))fun; - } else if (strcmp((const char *)propValue, "initfamiliar") == 0) { rc->init_familiar = (void(*)(struct unit *))fun; } From 5ba3d76efb6e69c82c0e9dfcd2ef22bb02e3c999 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Feb 2017 09:32:03 +0100 Subject: [PATCH 05/10] remove race.init_familiar funpointer --- res/e3a/races.xml | 19 ------------------- res/eressea/races.xml | 21 --------------------- src/kernel/race.c | 2 +- src/kernel/race.h | 2 +- src/kernel/xmlreader.c | 4 +--- src/spells.c | 15 ++++++++++----- 6 files changed, 13 insertions(+), 50 deletions(-) diff --git a/res/e3a/races.xml b/res/e3a/races.xml index e2cc60e55..e81d31b92 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -10,7 +10,6 @@ - @@ -183,7 +182,6 @@ - @@ -210,7 +208,6 @@ - @@ -232,7 +229,6 @@ - @@ -254,7 +250,6 @@ - @@ -278,7 +273,6 @@ - @@ -302,7 +296,6 @@ - @@ -325,7 +318,6 @@ - @@ -352,7 +344,6 @@ - @@ -375,7 +366,6 @@ - @@ -400,7 +390,6 @@ - @@ -427,7 +416,6 @@ - @@ -451,7 +439,6 @@ - @@ -475,7 +462,6 @@ - @@ -498,7 +484,6 @@ - @@ -526,7 +511,6 @@ - @@ -550,7 +534,6 @@ - @@ -573,7 +556,6 @@ - @@ -597,7 +579,6 @@ - diff --git a/res/eressea/races.xml b/res/eressea/races.xml index 70dd1af9f..470a33a3f 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -28,7 +28,6 @@ - @@ -62,7 +61,6 @@ - @@ -91,7 +89,6 @@ - @@ -119,7 +116,6 @@ - @@ -149,7 +145,6 @@ - @@ -179,7 +174,6 @@ - @@ -210,7 +204,6 @@ - @@ -245,7 +238,6 @@ - @@ -276,7 +268,6 @@ - @@ -309,7 +300,6 @@ - @@ -341,7 +331,6 @@ - @@ -371,7 +360,6 @@ - @@ -402,7 +390,6 @@ - @@ -432,7 +419,6 @@ - @@ -464,7 +450,6 @@ - @@ -496,7 +481,6 @@ - @@ -526,7 +510,6 @@ - @@ -559,7 +542,6 @@ - @@ -589,7 +571,6 @@ - @@ -882,7 +863,6 @@ - @@ -943,7 +923,6 @@ - diff --git a/src/kernel/race.c b/src/kernel/race.c index 1385bd932..e3983bffe 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -226,7 +226,7 @@ race_list *get_familiarraces(void) if (!init) { race *rc = races; for (; rc != NULL; rc = rc->next) { - if (rc->init_familiar != NULL) { + if (rc->flags & RCF_FAMILIAR) { racelist_insert(&familiarraces, rc); } } diff --git a/src/kernel/race.h b/src/kernel/race.h index 380b843bd..1322d3aad 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -145,7 +145,6 @@ extern "C" { race_name_func generate_name; void(*age) (struct unit * u); - void(*init_familiar) (struct unit *); struct rcoption *options; /* rarely used properties */ @@ -226,6 +225,7 @@ extern "C" { #define RCF_IRONGOLEM (1<<28) /* race gets irongolem properties */ #define RCF_ATTACK_MOVED (1<<29) /* may attack if it has moved */ #define RCF_MIGRANTS (1<<30) /* may have migrant units (human bonus) */ +#define RCF_FAMILIAR (1<<31) /* may be a familiar */ /* Economic flags */ #define ECF_KEEP_ITEM (1<<1) /* gibt Gegenst�nde weg */ diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 97fab3b8d..2ba8e2b75 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1798,9 +1798,6 @@ static int parse_races(xmlDocPtr doc) else if (strcmp((const char *)propValue, "age") == 0) { rc->age = (void(*)(struct unit *))fun; } - 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); } @@ -1822,6 +1819,7 @@ static int parse_races(xmlDocPtr doc) propValue = xmlGetProp(node, BAD_CAST "race"); assert(propValue != NULL); frc = rc_get_or_create((const char *)propValue); + frc->flags |= RCF_FAMILIAR; if (xml_bvalue(node, "default", false)) { rc->familiars[k] = rc->familiars[0]; rc->familiars[0] = frc; diff --git a/src/spells.c b/src/spells.c index 091d3d076..95b26434f 100644 --- a/src/spells.c +++ b/src/spells.c @@ -34,10 +34,10 @@ #include /* kernel includes */ -#include -#include #include #include +#include +#include #include #include #include @@ -514,11 +514,16 @@ static const race *select_familiar(const race * magerace, magic_t magiegebiet) static void make_familiar(unit * familiar, unit * mage) { /* skills and spells: */ - if (u_race(familiar)->init_familiar != NULL) { - u_race(familiar)->init_familiar(familiar); + const struct equipment *eq; + char eqname[64]; + const race * rc = u_race(familiar); + snprintf(eqname, sizeof(eqname), "%s_familiar", rc->_name); + eq = get_equipment(eqname); + if (eq != NULL) { + equip_items(&familiar->items, eq); } else { - log_error("could not perform initialization for familiar %s.\n", familiar->faction->race->_name); + log_error("could not perform initialization for familiar %s.\n", rc->_name); } /* triggers: */ From 4bd295e3b283c6dae43ca593ecf8af8fd4e7f1d6 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Feb 2017 20:42:31 +0100 Subject: [PATCH 06/10] remove the nearly unused illusion race --- res/core/messages.xml | 14 -------------- res/e3a/races.xml | 7 ------- res/eressea/races.xml | 6 ------ src/kernel/race.c | 15 +++++++++++---- src/kernel/race.h | 4 ++-- src/races/CMakeLists.txt | 1 - src/races/illusion.c | 38 -------------------------------------- src/races/races.c | 2 -- src/reports.c | 5 ++--- 9 files changed, 15 insertions(+), 77 deletions(-) delete mode 100644 src/races/illusion.c diff --git a/res/core/messages.xml b/res/core/messages.xml index 3fae49eb3..e312fcc7c 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -3266,20 +3266,6 @@ "$unit($unit) marschiert in eine Antimagiezone und löst sich auf." "$unit($unit) walks into an antimagical zone and dissolves." - - - - - "$unit($unit) hat sich unbemerkt verflüchtigt." - "$unit($unit) has dissolved without a trace." - - - - - - "$unit($unit) wird sich bald verflüchtigen." - "$unit($unit) will dissolve soon." - diff --git a/res/e3a/races.xml b/res/e3a/races.xml index e81d31b92..83d356f75 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -696,13 +696,6 @@ - - - - - - - diff --git a/res/eressea/races.xml b/res/eressea/races.xml index 470a33a3f..bce464d78 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -745,12 +745,6 @@ - - - - - - diff --git a/src/kernel/race.c b/src/kernel/race.c index e3983bffe..56b0590ae 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -66,7 +66,7 @@ static int rc_changes = 1; static const char *racenames[MAXRACES] = { "dwarf", "elf", NULL, "goblin", "human", "troll", "demon", "insect", - "halfling", "cat", "aquarian", "orc", "snotling", "undead", "illusion", + "halfling", "cat", "aquarian", "orc", "snotling", "undead", NULL, "youngdragon", "dragon", "wyrm", "ent", "catdragon", "dracoid", NULL, "spell", "irongolem", "stonegolem", "shadowdemon", "shadowmaster", "mountainguard", "alp", "toad", "braineater", "peasant", @@ -296,9 +296,16 @@ static race *rc_find_i(const char *name) while (rc && strcmp(rname, rc->_name) != 0) { rc = rc->next; } - if (!rc && strcmp(name, "uruk") == 0) { - rc = rc_find_i("orc"); - log_warning("a reference was made to the retired race '%s', returning '%s'.", name, rc->_name); + if (!rc) { + const char *rc_depr[] = { "uruk", "orc", "illusion", "template", NULL }; + int i; + for (i = 0; rc_depr[i]; i += 2) { + if (strcmp(name, rc_depr[i]) == 0) { + rc = rc_find_i(rc_depr[i + 1]); + log_warning("a reference was made to the retired race '%s', returning '%s'.", name, rc->_name); + break; + } + } } return rc; } diff --git a/src/kernel/race.h b/src/kernel/race.h index 1322d3aad..1039402b0 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -65,8 +65,8 @@ extern "C" { RC_ORC, RC_SNOTLING, RC_UNDEAD, - RC_ILLUSION, - RC_FIREDRAGON, + + RC_FIREDRAGON = 15, RC_DRAGON, RC_WYRM, RC_TREEMAN, diff --git a/src/races/CMakeLists.txt b/src/races/CMakeLists.txt index 1f3044e3a..ff6025581 100644 --- a/src/races/CMakeLists.txt +++ b/src/races/CMakeLists.txt @@ -1,7 +1,6 @@ PROJECT(races C) SET(_FILES dragons.c -illusion.c races.c zombies.c ) diff --git a/src/races/illusion.c b/src/races/illusion.c deleted file mode 100644 index 7411ae4d5..000000000 --- a/src/races/illusion.c +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Eressea PB(E)M host Copyright (C) 1998-2015 - * Christian Schlittchen (corwin@amber.kn-bremen.de) - * Katja Zedel (katze@felidae.kn-bremen.de) - * Henning Peters (faroul@beyond.kn-bremen.de) - * Enno Rehling (enno@eressea.de) - * Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) - * - * This program may not be used, modified or distributed without - * prior permission by the authors of Eressea. - */ - -#include - -/* kernel includes */ -#include -#include -#include -#include - -/* libc includes */ -#include -#include - -#define ILLUSIONMAX 6 - -void age_illusion(unit * u) -{ - if (u->faction->race != get_race(RC_ILLUSION)) { - if (u->age == ILLUSIONMAX) { - ADDMSG(&u->faction->msgs, msg_message("warnillusiondissolve", "unit", u)); - } - else if (u->age > ILLUSIONMAX) { - set_number(u, 0); - ADDMSG(&u->faction->msgs, msg_message("illusiondissolve", "unit", u)); - } - } -} diff --git a/src/races/races.c b/src/races/races.c index bb699520e..7ca9e976a 100644 --- a/src/races/races.c +++ b/src/races/races.c @@ -31,7 +31,6 @@ void age_firedragon(struct unit *u); void age_dragon(struct unit *u); -void age_illusion(struct unit *u); void age_undead(struct unit *u); void age_skeleton(struct unit *u); void age_zombie(struct unit *u); @@ -101,7 +100,6 @@ void register_races(void) /* function age for race->age() */ register_function((pf_generic)age_undead, "ageundead"); - register_function((pf_generic)age_illusion, "ageillusion"); register_function((pf_generic)age_skeleton, "ageskeleton"); register_function((pf_generic)age_zombie, "agezombie"); register_function((pf_generic)age_ghoul, "ageghoul"); diff --git a/src/reports.c b/src/reports.c index 7d8374ff5..a49957b9d 100644 --- a/src/reports.c +++ b/src/reports.c @@ -123,13 +123,12 @@ const char *options[MAXOPTIONS] = { bool omniscient(const faction *f) { - static const race *rc_template, *rc_illusion; + static const race *rc_template; static int cache; if (rc_changed(&cache)) { - rc_illusion = get_race(RC_ILLUSION); rc_template = get_race(RC_TEMPLATE); } - return (f->race == rc_template || f->race == rc_illusion); + return (f->race == rc_template); } From 44f6336e1f8d150430a7f66a6955ddfa5b010040 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Feb 2017 21:04:50 +0100 Subject: [PATCH 07/10] do not register unused functions. --- src/races/races.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/src/races/races.c b/src/races/races.c index 7ca9e976a..a05f3d211 100644 --- a/src/races/races.c +++ b/src/races/races.c @@ -36,16 +36,6 @@ void age_skeleton(struct unit *u); void age_zombie(struct unit *u); void age_ghoul(struct unit *u); -static void oldfamiliars(unit * u) -{ - char fname[64]; - /* these familiars have no special skills. - */ - snprintf(fname, sizeof(fname), "%s_familiar", u_race(u)->_name); - create_mage(u, M_GRAY); - equip_unit(u, get_equipment(fname)); -} - static void equip_newunits(const struct equipment *eq, struct unit *u) { struct region *r = u->region; @@ -91,12 +81,7 @@ static void equip_newunits(const struct equipment *eq, struct unit *u) * in die jeweilige Rassendefiniton eingebunden */ void register_races(void) { - /* function initfamiliar */ - register_function((pf_generic)oldfamiliars, "oldfamiliars"); - - register_function((pf_generic)allowed_swim, "moveswimming"); - register_function((pf_generic)allowed_fly, "moveflying"); - register_function((pf_generic)allowed_walk, "movewalking"); + register_function((pf_generic)equip_newunits, "equip_newunits"); /* function age for race->age() */ register_function((pf_generic)age_undead, "ageundead"); @@ -105,9 +90,4 @@ void register_races(void) register_function((pf_generic)age_ghoul, "ageghoul"); register_function((pf_generic)age_dragon, "agedragon"); register_function((pf_generic)age_firedragon, "agefiredragon"); - - /* function itemdrop - * to generate battle spoils - * race->itemdrop() */ - register_function((pf_generic)equip_newunits, "equip_newunits"); } From a1dc3dc8e4f43088cf0898a259b81c191e375021 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Feb 2017 21:19:13 +0100 Subject: [PATCH 08/10] remove race.age from XML data (set in rc_create) --- res/e3a/races.xml | 4 ---- res/eressea/races.xml | 6 ------ src/kernel/race.c | 4 ++++ src/kernel/xmlreader.c | 3 --- src/races/races.c | 12 ++++++------ 5 files changed, 10 insertions(+), 19 deletions(-) diff --git a/res/e3a/races.xml b/res/e3a/races.xml index 83d356f75..b7111b4f1 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -699,7 +699,6 @@ - @@ -752,7 +751,6 @@ - @@ -788,7 +786,6 @@ - @@ -820,7 +817,6 @@ - diff --git a/res/eressea/races.xml b/res/eressea/races.xml index bce464d78..b9077d98b 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -723,7 +723,6 @@ - @@ -735,7 +734,6 @@ - @@ -748,7 +746,6 @@ - @@ -1019,7 +1016,6 @@ - @@ -1053,7 +1049,6 @@ - @@ -1083,7 +1078,6 @@ - diff --git a/src/kernel/race.c b/src/kernel/race.c index 56b0590ae..4e8e0817c 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -327,6 +327,7 @@ race *rc_create(const char *zName) { race *rc; int i; + char zText[64]; assert(zName); rc = (race *)calloc(sizeof(race), 1); @@ -350,6 +351,9 @@ race *rc_create(const char *zName) rc->index = num_races++; ++rc_changes; rc->next = races; + + snprintf(zText, sizeof(zText), "age_%s", zName); + rc->age = (void(*) (struct unit *))get_function(zText); return races = rc; } diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 2ba8e2b75..5c294d13a 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1795,9 +1795,6 @@ static int parse_races(xmlDocPtr doc) if (strcmp((const char *)propValue, "name") == 0) { rc->generate_name = (race_name_func)fun; } - else if (strcmp((const char *)propValue, "age") == 0) { - rc->age = (void(*)(struct unit *))fun; - } else { log_error("unknown function type '%s' for race %s\n", (const char *)propValue, rc->_name); } diff --git a/src/races/races.c b/src/races/races.c index a05f3d211..92a3d3e3d 100644 --- a/src/races/races.c +++ b/src/races/races.c @@ -84,10 +84,10 @@ void register_races(void) register_function((pf_generic)equip_newunits, "equip_newunits"); /* function age for race->age() */ - register_function((pf_generic)age_undead, "ageundead"); - register_function((pf_generic)age_skeleton, "ageskeleton"); - register_function((pf_generic)age_zombie, "agezombie"); - register_function((pf_generic)age_ghoul, "ageghoul"); - register_function((pf_generic)age_dragon, "agedragon"); - register_function((pf_generic)age_firedragon, "agefiredragon"); + register_function((pf_generic)age_undead, "age_undead"); + register_function((pf_generic)age_skeleton, "age_skeleton"); + register_function((pf_generic)age_zombie, "age_zombie"); + register_function((pf_generic)age_ghoul, "age_ghoul"); + register_function((pf_generic)age_dragon, "age_dragon"); + register_function((pf_generic)age_firedragon, "age_youngdragon"); } From 7e4b0ac71772361c11b345dfbbc9ee232b34ee21 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Feb 2017 21:21:05 +0100 Subject: [PATCH 09/10] fix XML file --- res/races/dragon.xml | 1 - res/races/youngdragon.xml | 1 - 2 files changed, 2 deletions(-) diff --git a/res/races/dragon.xml b/res/races/dragon.xml index 7a36e4b84..f42037312 100644 --- a/res/races/dragon.xml +++ b/res/races/dragon.xml @@ -5,7 +5,6 @@ income="1000" walk="yes" teach="no" getitem="yes" resistbash="yes" dragon="yes"> - diff --git a/res/races/youngdragon.xml b/res/races/youngdragon.xml index 0ac2d35be..df10a44e9 100644 --- a/res/races/youngdragon.xml +++ b/res/races/youngdragon.xml @@ -5,7 +5,6 @@ defensemodifier="4" scarepeasants="yes" fly="yes" walk="yes" teach="no" getitem="yes" resistbash="yes" dragon="yes" income="150"> - From bfb5a9b69231c1b53ae9d3ad700582d332beb125 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Feb 2017 22:07:36 +0100 Subject: [PATCH 10/10] set age_unit and name_unit funpointers in rc_create. no more in XML races. rename juju-zombie => juju. --- res/core/de/strings.xml | 8 ++++---- res/core/fr/strings.xml | 4 ++-- res/e3a/races.xml | 19 +------------------ res/eressea/races.xml | 23 +---------------------- src/kernel/race.c | 12 ++++++++---- src/kernel/race.h | 8 ++++---- src/kernel/unit.c | 9 ++++++--- src/kernel/unit.test.c | 2 +- src/kernel/xmlreader.c | 24 ------------------------ src/laws.c | 5 +++-- src/names.c | 23 ++++++++++------------- src/names.test.c | 35 ++++++++++++++++++++--------------- 12 files changed, 60 insertions(+), 112 deletions(-) diff --git a/res/core/de/strings.xml b/res/core/de/strings.xml index 3aa71393d..97ded6e8d 100644 --- a/res/core/de/strings.xml +++ b/res/core/de/strings.xml @@ -2379,19 +2379,19 @@ ghoul - + Juju-Zombie juju-zombie - + Juju-Zombies juju-zombies - + Juju-Zombies juju-zombies - + Juju-Zombie juju-zombie diff --git a/res/core/fr/strings.xml b/res/core/fr/strings.xml index d1801b338..7eb091570 100644 --- a/res/core/fr/strings.xml +++ b/res/core/fr/strings.xml @@ -1912,10 +1912,10 @@ zombie - + zombies juju - + zombie juju diff --git a/res/e3a/races.xml b/res/e3a/races.xml index b7111b4f1..2e5a81aee 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -415,7 +415,6 @@ - @@ -588,7 +587,6 @@ - @@ -643,19 +641,16 @@ - - - @@ -667,7 +662,6 @@ - @@ -683,7 +677,6 @@ - @@ -691,14 +684,12 @@ - - @@ -731,7 +722,6 @@ - @@ -750,7 +740,6 @@ - @@ -766,9 +755,8 @@ - + - @@ -785,7 +773,6 @@ - @@ -800,7 +787,6 @@ - @@ -816,7 +802,6 @@ - @@ -831,13 +816,11 @@ - - diff --git a/res/eressea/races.xml b/res/eressea/races.xml index b9077d98b..6deefacc9 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -330,7 +330,6 @@ - @@ -581,7 +580,6 @@ - @@ -652,19 +650,16 @@ - - - @@ -676,7 +671,6 @@ - @@ -691,7 +685,6 @@ - @@ -705,13 +698,11 @@ - - @@ -722,7 +713,6 @@ - @@ -733,7 +723,6 @@ - @@ -745,7 +734,6 @@ - @@ -997,7 +985,6 @@ - @@ -1015,7 +1002,6 @@ - @@ -1030,9 +1016,8 @@ - + - @@ -1048,7 +1033,6 @@ - @@ -1062,7 +1046,6 @@ - @@ -1077,7 +1060,6 @@ - @@ -1091,12 +1073,10 @@ - - @@ -1224,7 +1204,6 @@ - diff --git a/src/kernel/race.c b/src/kernel/race.c index 4e8e0817c..4a3a04916 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -74,7 +74,7 @@ static const char *racenames[MAXRACES] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "seaserpent", "shadowknight", NULL, "skeleton", "skeletonlord", "zombie", - "juju-zombie", "ghoul", "ghast", NULL, NULL, "template", + "juju", "ghoul", "ghast", NULL, NULL, "template", "clone" }; @@ -297,7 +297,7 @@ static race *rc_find_i(const char *name) rc = rc->next; } if (!rc) { - const char *rc_depr[] = { "uruk", "orc", "illusion", "template", NULL }; + const char *rc_depr[] = { "uruk", "orc", "illusion", "template", "juju-zombie", "juju", NULL }; int i; for (i = 0; rc_depr[i]; i += 2) { if (strcmp(name, rc_depr[i]) == 0) { @@ -353,7 +353,11 @@ race *rc_create(const char *zName) rc->next = races; snprintf(zText, sizeof(zText), "age_%s", zName); - rc->age = (void(*) (struct unit *))get_function(zText); + rc->age_unit = (race_func)get_function(zText); + + snprintf(zText, sizeof(zText), "name_%s", zName); + rc->name_unit = (race_func)get_function(zText); + return races = rc; } @@ -553,6 +557,6 @@ variant read_race_reference(struct storage *store) return result; } -void register_race_name_function(race_name_func func, const char *name) { +void register_race_function(race_func func, const char *name) { register_function((pf_generic)func, name); } diff --git a/src/kernel/race.h b/src/kernel/race.h index 1039402b0..e464c9447 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -112,7 +112,7 @@ extern "C" { int level; } att; - typedef void (*race_name_func)(struct unit *); + typedef void (*race_func) (struct unit *); typedef struct race { char *_name; @@ -143,8 +143,8 @@ extern "C" { struct att attack[RACE_ATTACKS]; signed char bonus[MAXSKILLS]; - race_name_func generate_name; - void(*age) (struct unit * u); + race_func name_unit; + race_func age_unit; struct rcoption *options; /* rarely used properties */ @@ -262,7 +262,7 @@ extern "C" { variant read_race_reference(struct storage *store); const char *raceprefix(const struct unit *u); - void register_race_name_function(race_name_func, const char *); + void register_race_function(race_func, const char *); #ifdef __cplusplus } diff --git a/src/kernel/unit.c b/src/kernel/unit.c index ab1669ed9..4592d0bc7 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1460,8 +1460,11 @@ void default_name(const unit *u, char name[], int len) { void name_unit(unit * u) { const race *rc = u_race(u); - if (rc->generate_name) { - rc->generate_name(u); + if (rc->name_unit) { + rc->name_unit(u); + } + else if (u->faction->flags & FFL_NPC) { + unit_setname(u, NULL); } else { char name[32]; @@ -1514,7 +1517,7 @@ unit *create_unit(region * r, faction * f, int number, const struct race *urace, if (dname) { u->_name = strdup(dname); } - else if (urace->generate_name || playerrace(urace)) { + else if (urace->name_unit || playerrace(urace)) { name_unit(u); } diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index c187f7bab..7c7bb087b 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -487,7 +487,7 @@ static void test_name_unit(CuTest *tc) { test_setup(); rc = test_create_race("skeleton"); u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); - rc->generate_name = gen_name; + rc->name_unit = gen_name; name_unit(u); CuAssertStrEquals(tc, "Hodor", unit_getname(u)); test_cleanup(); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 5c294d13a..695f91d69 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1778,30 +1778,6 @@ static int parse_races(xmlDocPtr doc) } xmlXPathFreeObject(result); - /* reading eressea/races/race/function */ - xpath->node = node; - result = xmlXPathEvalExpression(BAD_CAST "function", xpath); - for (k = 0; k != result->nodesetval->nodeNr; ++k) { - xmlNodePtr node = result->nodesetval->nodeTab[k]; - pf_generic fun; - - parse_function(node, &fun, &propValue); - if (fun == NULL) { - log_error("unknown function name '%s' for race %s\n", (const char *)propValue, rc->_name); - xmlFree(propValue); - continue; - } - assert(propValue != NULL); - if (strcmp((const char *)propValue, "name") == 0) { - rc->generate_name = (race_name_func)fun; - } - else { - log_error("unknown function type '%s' for race %s\n", (const char *)propValue, rc->_name); - } - xmlFree(propValue); - } - xmlXPathFreeObject(result); - /* reading eressea/races/race/familiar */ xpath->node = node; result = xmlXPathEvalExpression(BAD_CAST "familiar", xpath); diff --git a/src/laws.c b/src/laws.c index e314e2d85..253b45b89 100644 --- a/src/laws.c +++ b/src/laws.c @@ -164,9 +164,10 @@ static void age_unit(region * r, unit * u) } } else { + const race *rc = u_race(u); ++u->age; - if (u->number > 0 && u_race(u)->age) { - u_race(u)->age(u); + if (u->number > 0 && rc->age_unit) { + rc->age_unit(u); } } if (u->region && is_astral(u->region)) { diff --git a/src/names.c b/src/names.c index 780386deb..bc740a704 100644 --- a/src/names.c +++ b/src/names.c @@ -212,11 +212,6 @@ const char *silbe3[SIL3] = { "bus", }; -static void generic_name(unit * u) -{ - unit_setname(u, NULL); -} - static void dragon_name(unit * u) { char name[NAMESIZE + 1]; @@ -469,12 +464,14 @@ void register_names(void) { /* function name * generate a name for a nonplayerunit - * race->generate_name() */ - 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"); - register_race_name_function(dragon_name, "namedragon"); - register_race_name_function(generic_name, "namegeneric"); + * race->name_unit() */ + + register_race_function(undead_name, "name_undead"); + register_race_function(skeleton_name, "name_skeleton"); + register_race_function(zombie_name, "name_zombie"); + register_race_function(ghoul_name, "name_ghoul"); + register_race_function(dracoid_name, "name_dracoid"); + register_race_function(dragon_name, "name_dragon"); + register_race_function(dragon_name, "name_youngdragon"); + register_race_function(dragon_name, "name_wyrm"); } diff --git a/src/names.test.c b/src/names.test.c index 01fe0ff41..7d62d4752 100644 --- a/src/names.test.c +++ b/src/names.test.c @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -12,31 +13,33 @@ static void test_names(CuTest * tc) { - race_name_func foo; unit *u; race *rc; test_cleanup(); register_names(); + CuAssertPtrNotNull(tc, get_function("name_undead")); + CuAssertPtrNotNull(tc, get_function("name_skeleton")); + CuAssertPtrNotNull(tc, get_function("name_zombie")); + CuAssertPtrNotNull(tc, get_function("name_ghoul")); + CuAssertPtrNotNull(tc, get_function("name_dragon")); + CuAssertPtrNotNull(tc, get_function("name_youngdragon")); + CuAssertPtrNotNull(tc, get_function("name_wyrm")); + CuAssertPtrNotNull(tc, get_function("name_dracoid")); default_locale = test_create_locale(); - u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); rc = test_create_race("undead"); + u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); locale_setstring(default_locale, "undead_name_0", "Graue"); locale_setstring(default_locale, "undead_postfix_0", "Kobolde"); - CuAssertPtrNotNull(tc, foo = (race_name_func)get_function("nameundead")); - rc->generate_name = foo; - rc->generate_name(u); + CuAssertPtrNotNull(tc, rc->name_unit); + CuAssertTrue(tc, rc->name_unit == (race_func)get_function("name_undead")); + name_unit(u); CuAssertStrEquals(tc, "Graue Kobolde", u->_name); - CuAssertPtrNotNull(tc, get_function("nameskeleton")); - CuAssertPtrNotNull(tc, get_function("namezombie")); - CuAssertPtrNotNull(tc, get_function("nameghoul")); - CuAssertPtrNotNull(tc, get_function("namedragon")); - CuAssertPtrNotNull(tc, get_function("namedracoid")); - CuAssertPtrNotNull(tc, get_function("namegeneric")); test_cleanup(); } static void test_monster_names(CuTest *tc) { unit *u; + faction *f; race *rc; test_setup(); @@ -45,11 +48,13 @@ static void test_monster_names(CuTest *tc) { locale_setstring(default_locale, "race::irongolem", "Eisengolem"); locale_setstring(default_locale, "race::irongolem_p", "Eisengolems"); rc = test_create_race("irongolem"); - u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); + f = test_create_faction(rc); + f->flags |= FFL_NPC; + u = test_create_unit(f, test_create_region(0, 0, 0)); + unit_setname(u, "Hodor"); CuAssertPtrNotNull(tc, u->_name); - rc->generate_name = (race_name_func)get_function("namegeneric"); - rc->generate_name(u); - CuAssertPtrEquals(tc, 0, u->_name); + name_unit(u); + CuAssertPtrEquals(tc, NULL, u->_name); CuAssertStrEquals(tc, "Eisengolem", unit_getname(u)); u->number = 2; CuAssertStrEquals(tc, "Eisengolems", unit_getname(u));