From 5ba3d76efb6e69c82c0e9dfcd2ef22bb02e3c999 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Feb 2017 09:32:03 +0100 Subject: [PATCH] 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: */