add some assertions to make sure update_gbdream is not called without a magician

This commit is contained in:
Enno Rehling 2015-08-02 21:17:21 +02:00
parent 65b7fc7ff8
commit a119f7617f
2 changed files with 8 additions and 4 deletions

View File

@ -530,6 +530,8 @@ int alliedunit(const unit * u, const faction * f2, int mode)
ally *sf;
int automode;
assert(u);
assert(f2);
assert(u->region); /* the unit should be in a region, but it's possible that u->number==0 (TEMP units) */
if (u->faction == f2)
return mode;

View File

@ -1278,10 +1278,12 @@ static int update_gbdream(const unit * u, int bonus, curse *c, const curse_type
if (curse_active(c) && c->type == gbdream_ct) {
double effect = curse_geteffect(c);
unit *mage = c->magician;
/* wir suchen jeweils den groessten Bonus und den groestsen Malus */
/* wir suchen jeweils den groessten Bonus und den groessten Malus */
if (sign * effect > sign * bonus) {
if (mage == NULL || mage->number == 0
|| sign>0?alliedunit(mage, u->faction, HELP_GUARD):!alliedunit(mage, u->faction, HELP_GUARD)) {
bool allied;
assert(mage && mage->number > 0);
allied = alliedunit(mage, u->faction, HELP_GUARD);
if ((sign>0)?allied:!allied) {
bonus = (int)effect;
}
}
@ -1327,9 +1329,9 @@ int att_modification(const unit * u, skill_t sk)
while (a && a->type == &at_curse) {
curse *c = (curse *)a->data.v;
assert(c->magician); // update_gbdream makes no sense if there is no caster (calls alliedunit)
bonus = update_gbdream(u, bonus, c, gbdream_ct, 1);
malus = update_gbdream(u, malus, c, gbdream_ct, -1);
a = a->next;
}
result = result + bonus + malus;