forked from github/server
Bug 2451: fix equip_unit for spells,
update the familiar-fixing code from bug 2517.
This commit is contained in:
parent
62e6489c7a
commit
73540d733d
4 changed files with 60 additions and 28 deletions
|
@ -132,7 +132,7 @@ function equip_unit(u, name, flags)
|
||||||
end
|
end
|
||||||
local spells = set['spells']
|
local spells = set['spells']
|
||||||
if spells then
|
if spells then
|
||||||
for name, level in ipairs(spells) do
|
for name, level in pairs(spells) do
|
||||||
u:add_spell(name, level)
|
u:add_spell(name, level)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1293,24 +1293,6 @@ ship *read_ship(gamedata *data)
|
||||||
return sh;
|
return sh;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fix_fam_mage(unit *u) {
|
|
||||||
struct sc_mage *mage = get_mage(u);
|
|
||||||
magic_t mtype = mage_get_type(mage);
|
|
||||||
if (mtype != M_GRAY) {
|
|
||||||
int skill = get_level(u, SK_MAGIC);
|
|
||||||
/* unit should be a familiar that has aura and a spell-list */
|
|
||||||
if (skill > 0) {
|
|
||||||
struct spellbook * sb = mage_get_spellbook(mage);
|
|
||||||
if (!sb) {
|
|
||||||
unit_set_magic(u, M_GRAY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
a_removeall(&u->attribs, &at_mage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void fix_fam_triggers(unit *u) {
|
static void fix_fam_triggers(unit *u) {
|
||||||
attrib * a = a_find(u->attribs, &at_mage);
|
attrib * a = a_find(u->attribs, &at_mage);
|
||||||
attrib * am = a_find(u->attribs, &at_familiarmage);
|
attrib * am = a_find(u->attribs, &at_familiarmage);
|
||||||
|
|
65
src/magic.c
65
src/magic.c
|
@ -166,8 +166,8 @@ void unit_add_spell(unit * u, struct spell * sp, int level)
|
||||||
sc_mage *mage = get_mage(u);
|
sc_mage *mage = get_mage(u);
|
||||||
|
|
||||||
if (!mage) {
|
if (!mage) {
|
||||||
log_error("adding new spell %s to a previously non-mage unit %s\n", sp->sname, unitname(u));
|
log_error("adding new spell %s to a previously non-magical unit %s\n", sp->sname, unitname(u));
|
||||||
mage = create_mage(u, u->faction ? u->faction->magiegebiet : M_GRAY);
|
mage = create_mage(u, M_GRAY);
|
||||||
}
|
}
|
||||||
if (!mage->spellbook) {
|
if (!mage->spellbook) {
|
||||||
mage->spellbook = create_spellbook(0);
|
mage->spellbook = create_spellbook(0);
|
||||||
|
@ -350,7 +350,7 @@ static int read_mage(variant *var, void *owner, struct gamedata *data)
|
||||||
read_spellbook(&mage->spellbook, data, get_spell_level_mage, mage);
|
read_spellbook(&mage->spellbook, data, get_spell_level_mage, mage);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
read_spellbook(0, data, 0, mage);
|
read_spellbook(NULL, data, NULL, mage);
|
||||||
}
|
}
|
||||||
return AT_READ_OK;
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
@ -2210,18 +2210,67 @@ void remove_familiar(unit * mage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void create_newfamiliar(unit * mage, unit * fam)
|
static void equip_familiar(unit *fam) {
|
||||||
{
|
/* items, skills and spells: */
|
||||||
/* skills and spells: */
|
|
||||||
char eqname[64];
|
char eqname[64];
|
||||||
const race *rc = u_race(fam);
|
const race *rc = u_race(fam);
|
||||||
|
|
||||||
set_familiar(mage, fam);
|
|
||||||
|
|
||||||
snprintf(eqname, sizeof(eqname), "fam_%s", rc->_name);
|
snprintf(eqname, sizeof(eqname), "fam_%s", rc->_name);
|
||||||
if (!equip_unit(fam, eqname)) {
|
if (!equip_unit(fam, eqname)) {
|
||||||
log_info("could not perform initialization for familiar %s.\n", rc->_name);
|
log_info("could not perform initialization for familiar %s.\n", rc->_name);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int copy_spell_cb(spellbook_entry *sbe, void *udata) {
|
||||||
|
spellbook *sb = (spellbook *)udata;
|
||||||
|
spell * sp = spellref_get(&sbe->spref);
|
||||||
|
if (!spellbook_get(sb, sp)) {
|
||||||
|
spellbook_add(sb, sp, sbe->level);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Einmalige Reparatur von Vertrauten (Bugs 2451, 2517).
|
||||||
|
*/
|
||||||
|
void fix_fam_mage(unit *u) {
|
||||||
|
sc_mage *dmage;
|
||||||
|
unit *du = unit_create(0);
|
||||||
|
|
||||||
|
u_setrace(du, u_race(u));
|
||||||
|
dmage = create_mage(du, M_GRAY);
|
||||||
|
equip_familiar(du);
|
||||||
|
if (dmage) {
|
||||||
|
sc_mage *mage = get_mage(u);
|
||||||
|
if (!mage) {
|
||||||
|
mage = create_mage(u, dmage->magietyp);
|
||||||
|
}
|
||||||
|
else if (dmage->magietyp != mage->magietyp) {
|
||||||
|
mage->magietyp = dmage->magietyp;
|
||||||
|
}
|
||||||
|
if (dmage->spellbook) {
|
||||||
|
if (!mage->spellbook) {
|
||||||
|
mage->spellbook = create_spellbook(NULL);
|
||||||
|
spellbook_foreach(dmage->spellbook, copy_spell_cb, mage->spellbook);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (mage->spellbook) {
|
||||||
|
spellbook_clear(mage->spellbook);
|
||||||
|
mage->spellbook = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free_unit(du);
|
||||||
|
}
|
||||||
|
|
||||||
|
void create_newfamiliar(unit * mage, unit * fam)
|
||||||
|
{
|
||||||
|
|
||||||
|
create_mage(fam, M_GRAY);
|
||||||
|
set_familiar(mage, fam);
|
||||||
|
equip_familiar(fam);
|
||||||
|
|
||||||
/* TODO: Diese Attribute beim Tod des Familiars entfernen: */
|
/* TODO: Diese Attribute beim Tod des Familiars entfernen: */
|
||||||
/* Wenn der Magier stirbt, dann auch der Vertraute */
|
/* Wenn der Magier stirbt, dann auch der Vertraute */
|
||||||
add_trigger(&mage->attribs, "destroy", trigger_killunit(fam));
|
add_trigger(&mage->attribs, "destroy", trigger_killunit(fam));
|
||||||
|
|
|
@ -326,7 +326,8 @@ extern "C" {
|
||||||
void remove_familiar(struct unit *mage);
|
void remove_familiar(struct unit *mage);
|
||||||
void create_newfamiliar(struct unit *mage, struct unit *familiar);
|
void create_newfamiliar(struct unit *mage, struct unit *familiar);
|
||||||
void create_newclone(struct unit *mage, struct unit *familiar);
|
void create_newclone(struct unit *mage, struct unit *familiar);
|
||||||
struct unit *has_clone(struct unit *mage);
|
|
||||||
|
void fix_fam_mage(struct unit *u);
|
||||||
|
|
||||||
const char *spell_info(const struct spell *sp,
|
const char *spell_info(const struct spell *sp,
|
||||||
const struct locale *lang);
|
const struct locale *lang);
|
||||||
|
|
Loading…
Reference in a new issue