From 0537d39b17b10ca8d3dd0e7e51dcff99f12b1667 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 7 Oct 2017 03:22:35 +0200 Subject: [PATCH] add a fix for 2367 to fix_familiars --- src/kernel/save.c | 82 ++++++++++++++++++++++++++++----------------- src/util/gamedata.h | 2 +- 2 files changed, 52 insertions(+), 32 deletions(-) diff --git a/src/kernel/save.c b/src/kernel/save.c index 23d6f3e71..e3a63156c 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -24,8 +24,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "alchemy.h" #include "alliance.h" #include "ally.h" -#include "connection.h" #include "building.h" +#include "connection.h" +#include "equipment.h" #include "faction.h" #include "group.h" #include "item.h" @@ -1600,41 +1601,60 @@ static void fix_familiars(void) { if (u->_race != u->faction->race && (u->_race->flags & RCF_FAMILIAR)) { /* unit is potentially a familiar */ attrib * a = a_find(u->attribs, &at_mage); - if (a) { - /* unit is magical */ - attrib * am = a_find(u->attribs, &at_familiarmage); - if (!am) { - /* but it is not a familiar? */ - attrib * ae = a_find(u->attribs, &at_eventhandler); - if (ae) { - trigger **tlist; - tlist = get_triggers(ae, "destroy"); - if (tlist) { - trigger *t; - unit *um = NULL; - for (t = *tlist; t; t = t->next) { - if (t->type == &tt_shock) { - um = (unit *)t->data.v; - break; - } + attrib * am = a_find(u->attribs, &at_familiarmage); + if (am) { + sc_mage *mage = a ? (sc_mage *)a->data.v : NULL; + /* a familiar */ + if (!mage) { + log_error("%s seems to be a familiar with no magic.", + unitname(u)); + mage = create_mage(u, M_GRAY); + } + if (!mage->spellbook) { + char eqname[32]; + equipment *eq; + + snprintf(eqname, sizeof(eqname), "fam_%s", u->_race->_name); + eq = get_equipment(eqname); + if (eq && eq->spells) { + log_error("%s seems to be a familiar with no spells.", + unitname(u)); + /* magical familiar, no spells */ + equip_unit_mask(u, eq, EQUIP_SPELLS); + } + } + } + else if (a) { + /* not a familiar, but magical */ + attrib * ae = a_find(u->attribs, &at_eventhandler); + if (ae) { + trigger **tlist; + tlist = get_triggers(ae, "destroy"); + if (tlist) { + trigger *t; + unit *um = NULL; + for (t = *tlist; t; t = t->next) { + if (t->type == &tt_shock) { + um = (unit *)t->data.v; + break; } - if (um) { - attrib *af = a_find(um->attribs, &at_familiar); - log_error("%s seems to be a broken familiar of %s.", - unitname(u), unitname(um)); - if (af) { - unit * uf = (unit *)af->data.v; - log_error("%s already has a familiar: %s.", - unitname(um), unitname(uf)); - } - else { - set_familiar(um, u); - } + } + if (um) { + attrib *af = a_find(um->attribs, &at_familiar); + log_error("%s seems to be a broken familiar of %s.", + unitname(u), unitname(um)); + if (af) { + unit * uf = (unit *)af->data.v; + log_error("%s already has a familiar: %s.", + unitname(um), unitname(uf)); } else { - log_error("%s seems to be a broken familiar with no trigger.", unitname(u)); + set_familiar(um, u); } } + else { + log_error("%s seems to be a broken familiar with no trigger.", unitname(u)); + } } } } diff --git a/src/util/gamedata.h b/src/util/gamedata.h index 82df55cc3..22c1d9052 100644 --- a/src/util/gamedata.h +++ b/src/util/gamedata.h @@ -39,7 +39,7 @@ /* unfinished: */ #define CRYPT_VERSION 400 /* passwords are encrypted */ -#define RELEASE_VERSION SKILLSORT_VERSION /* current datafile */ +#define RELEASE_VERSION LANDDISPLAY_VERSION /* current datafile */ #define MIN_VERSION UIDHASH_VERSION /* minimal datafile we support */ #define MAX_VERSION RELEASE_VERSION /* change this if we can need to read the future datafile, and we can do so */