set_familiar code reduction.

remembering that at_skillmod is not persistent.
This commit is contained in:
Enno Rehling 2017-10-06 17:32:56 +02:00
parent 4452f93009
commit 9bfc0139f5
1 changed files with 3 additions and 30 deletions

View File

@ -2181,10 +2181,8 @@ void set_familiar(unit * mage, unit * familiar)
a = a->next; a = a->next;
} }
if (a == NULL) { if (a == NULL) {
attrib *an = a_add(&mage->attribs, a_new(&at_skillmod)); a = make_skillmod(NOSKILL, sm_familiar, 0.0, 0);
skillmod_data *smd = (skillmod_data *)an->data.v; a_add(&mage->attribs, a);
smd->special = sm_familiar;
smd->skill = NOSKILL;
} }
a = a_find(mage->attribs, &at_familiar); a = a_find(mage->attribs, &at_familiar);
@ -2228,19 +2226,7 @@ void remove_familiar(unit * mage)
bool create_newfamiliar(unit * mage, unit * familiar) bool create_newfamiliar(unit * mage, unit * familiar)
{ {
/* if the skill modifier for the mage does not yet exist, add it */ set_familiar(mage, familiar);
attrib *a;
attrib *afam = a_find(mage->attribs, &at_familiar);
attrib *amage = a_find(familiar->attribs, &at_familiarmage);
if (afam == NULL) {
afam = a_add(&mage->attribs, a_new(&at_familiar));
}
afam->data.v = familiar;
if (amage == NULL) {
amage = a_add(&familiar->attribs, a_new(&at_familiarmage));
}
amage->data.v = mage;
/* 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 */
@ -2248,19 +2234,6 @@ bool create_newfamiliar(unit * mage, unit * familiar)
/* Wenn der Vertraute stirbt, dann bekommt der Magier einen Schock */ /* Wenn der Vertraute stirbt, dann bekommt der Magier einen Schock */
add_trigger(&familiar->attribs, "destroy", trigger_shock(mage)); add_trigger(&familiar->attribs, "destroy", trigger_shock(mage));
a = a_find(mage->attribs, &at_skillmod);
while (a && a->type == &at_skillmod) {
skillmod_data *smd = (skillmod_data *)a->data.v;
if (smd->special == sm_familiar)
break;
a = a->next;
}
if (a == NULL) {
attrib *an = a_add(&mage->attribs, a_new(&at_skillmod));
skillmod_data *smd = (skillmod_data *)an->data.v;
smd->special = sm_familiar;
smd->skill = NOSKILL;
}
return true; return true;
} }