add a fix for 2367 to fix_familiars

This commit is contained in:
Enno Rehling 2017-10-07 03:22:35 +02:00
parent bb54e0d5ab
commit 0537d39b17
2 changed files with 52 additions and 32 deletions

View File

@ -24,8 +24,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "alchemy.h" #include "alchemy.h"
#include "alliance.h" #include "alliance.h"
#include "ally.h" #include "ally.h"
#include "connection.h"
#include "building.h" #include "building.h"
#include "connection.h"
#include "equipment.h"
#include "faction.h" #include "faction.h"
#include "group.h" #include "group.h"
#include "item.h" #include "item.h"
@ -1600,41 +1601,60 @@ static void fix_familiars(void) {
if (u->_race != u->faction->race && (u->_race->flags & RCF_FAMILIAR)) { if (u->_race != u->faction->race && (u->_race->flags & RCF_FAMILIAR)) {
/* unit is potentially a familiar */ /* unit is potentially a familiar */
attrib * a = a_find(u->attribs, &at_mage); attrib * a = a_find(u->attribs, &at_mage);
if (a) { attrib * am = a_find(u->attribs, &at_familiarmage);
/* unit is magical */ if (am) {
attrib * am = a_find(u->attribs, &at_familiarmage); sc_mage *mage = a ? (sc_mage *)a->data.v : NULL;
if (!am) { /* a familiar */
/* but it is not a familiar? */ if (!mage) {
attrib * ae = a_find(u->attribs, &at_eventhandler); log_error("%s seems to be a familiar with no magic.",
if (ae) { unitname(u));
trigger **tlist; mage = create_mage(u, M_GRAY);
tlist = get_triggers(ae, "destroy"); }
if (tlist) { if (!mage->spellbook) {
trigger *t; char eqname[32];
unit *um = NULL; equipment *eq;
for (t = *tlist; t; t = t->next) {
if (t->type == &tt_shock) { snprintf(eqname, sizeof(eqname), "fam_%s", u->_race->_name);
um = (unit *)t->data.v; eq = get_equipment(eqname);
break; 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); if (um) {
log_error("%s seems to be a broken familiar of %s.", attrib *af = a_find(um->attribs, &at_familiar);
unitname(u), unitname(um)); log_error("%s seems to be a broken familiar of %s.",
if (af) { unitname(u), unitname(um));
unit * uf = (unit *)af->data.v; if (af) {
log_error("%s already has a familiar: %s.", unit * uf = (unit *)af->data.v;
unitname(um), unitname(uf)); log_error("%s already has a familiar: %s.",
} unitname(um), unitname(uf));
else {
set_familiar(um, u);
}
} }
else { 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));
}
} }
} }
} }

View File

@ -39,7 +39,7 @@
/* unfinished: */ /* unfinished: */
#define CRYPT_VERSION 400 /* passwords are encrypted */ #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 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 */ #define MAX_VERSION RELEASE_VERSION /* change this if we can need to read the future datafile, and we can do so */