From 557f5458eacb9cec3bffae4e1403b1f72a6b4807 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 21 Apr 2021 18:05:26 +0200 Subject: [PATCH] don't cast level 0 combat spells --- src/battle.c | 67 ++++++++++++++++++++++++---------------------------- src/magic.c | 26 ++++++++------------ 2 files changed, 41 insertions(+), 52 deletions(-) diff --git a/src/battle.c b/src/battle.c index 8427a18b2..09a786597 100644 --- a/src/battle.c +++ b/src/battle.c @@ -1685,54 +1685,52 @@ void do_combatmagic(battle * b, combatmagic_t was) for (s = b->sides; s != b->sides + b->nsides; ++s) { fighter *fig; for (fig = s->fighters; fig; fig = fig->next) { - unit *mage = fig->unit; - unit *caster = mage; + unit *u = fig->unit; + unit *caster = u; if (fig->alive <= 0) continue; /* fighter kann im Kampf getoetet worden sein */ - level = effskill(mage, SK_MAGIC, r); + level = effskill(u, SK_MAGIC, r); if (level > 0) { double power; const spell *sp; - const struct locale *lang = mage->faction->locale; + const struct locale *lang = u->faction->locale; order *ord; switch (was) { case DO_PRECOMBATSPELL: - sp = get_combatspell(mage, 0); - sl = get_combatspelllevel(mage, 0); + sp = mage_get_combatspell(get_mage(u), 0, &sl); break; case DO_POSTCOMBATSPELL: - sp = get_combatspell(mage, 2); - sl = get_combatspelllevel(mage, 2); + sp = mage_get_combatspell(get_mage(u), 2, &sl); break; default: /* Fehler! */ return; } - if (sp == NULL || !u_hasspell(mage, sp)) + if (sp == NULL || !u_hasspell(u, sp)) continue; - level = max_spell_level(mage, caster, sp, level, 1, NULL); + level = max_spell_level(u, caster, sp, level, 1, NULL); if (sl > 0 && sl < level) { level = sl; } if (level < 1) { - report_failed_spell(b, mage, sp); + report_failed_spell(b, u, sp); continue; } ord = create_order(K_CAST, lang, "'%s'", spell_name(mkname_spell(sp), lang)); - power = spellpower(r, mage, sp, level); + power = spellpower(r, u, sp, level); free_order(ord); if (power <= 0) { /* Effekt von Antimagie */ - report_failed_spell(b, mage, sp); - pay_spell(mage, NULL, sp, level, 1); + report_failed_spell(b, u, sp); + pay_spell(u, NULL, sp, level, 1); } - else if (fumble(r, mage, sp, level)) { - report_failed_spell(b, mage, sp); - pay_spell(mage, NULL, sp, level, 1); + else if (fumble(r, u, sp, level)) { + report_failed_spell(b, u, sp); + pay_spell(u, NULL, sp, level, 1); } else { co = create_castorder_combat(0, fig, sp, level, power); @@ -1774,34 +1772,31 @@ static void do_combatspell(troop at) { const spell *sp; fighter *fi = at.fighter; - unit *mage = fi->unit; + unit *u = fi->unit; battle *b = fi->side->battle; region *r = b->region; selist *ql; - int level, qi; + int level, qi, sl; double power; int fumblechance = 0; + struct sc_mage *mage = get_mage(u); - sp = get_combatspell(mage, 1); - if (sp == NULL || !u_hasspell(mage, sp)) { + sp = mage_get_combatspell(mage, 1, &sl); + if (sl <= 0 || sp == NULL || !u_hasspell(u, sp)) { fi->magic = 0; /* Hat keinen Kampfzauber, kaempft nichtmagisch weiter */ return; } - level = max_spell_level(mage, mage, sp, fi->magic, 1, NULL); + level = max_spell_level(u, u, sp, fi->magic, 1, NULL); if (level < 1) { fi->magic = 0; /* Kann nicht mehr Zaubern, kaempft nichtmagisch weiter */ return; } - else { - int sl = get_combatspelllevel(mage, 1); - if (sl < level) { - level = sl; - } + else if (sl < level) { + level = sl; } - - if (fumble(r, mage, sp, level)) { - report_failed_spell(b, mage, sp); - pay_spell(mage, NULL, sp, level, 1); + if (fumble(r, u, sp, level)) { + report_failed_spell(b, u, sp); + pay_spell(u, NULL, sp, level, 1); return; } @@ -1817,14 +1812,14 @@ static void do_combatspell(troop at) /* Antimagie die Fehlschlag erhoeht */ if (rng_int() % 100 < fumblechance) { - report_failed_spell(b, mage, sp); - pay_spell(mage, NULL, sp, level, 1); + report_failed_spell(b, u, sp); + pay_spell(u, NULL, sp, level, 1); return; } - power = spellpower(r, mage, sp, level); + power = spellpower(r, u, sp, level); if (power <= 0) { /* Effekt von Antimagie */ - report_failed_spell(b, mage, sp); - pay_spell(mage, NULL, sp, level, 1); + report_failed_spell(b, u, sp); + pay_spell(u, NULL, sp, level, 1); return; } diff --git a/src/magic.c b/src/magic.c index 682cf4dce..497486cd9 100644 --- a/src/magic.c +++ b/src/magic.c @@ -524,9 +524,11 @@ int get_combatspelllevel(const unit * u, int nr) { int level; if (mage_get_combatspell(get_mage(u), nr, &level) != NULL) { - int maxlevel = effskill(u, SK_MAGIC, NULL); - if (level > maxlevel) { - return maxlevel; + if (level > 0) { + int maxlevel = effskill(u, SK_MAGIC, NULL); + if (level > maxlevel) { + return maxlevel; + } } return level; } @@ -573,21 +575,13 @@ void unset_combatspell(unit * u, spell * sp) m->combatspells[i].sp = NULL; } } - else if (sp->sptyp & PRECOMBATSPELL) { - if (sp != get_combatspell(u, 0)) - return; - } - else if (sp->sptyp & COMBATSPELL) { - if (sp != get_combatspell(u, 1)) { + else { + if (sp->sptyp & PRECOMBATSPELL) nr = 0; + else if (sp->sptyp & COMBATSPELL) nr = 1; + else if (sp->sptyp & POSTCOMBATSPELL) nr = 2; + if (sp != mage_get_combatspell(m, nr, NULL)) { return; } - nr = 1; - } - else if (sp->sptyp & POSTCOMBATSPELL) { - if (sp != get_combatspell(u, 2)) { - return; - } - nr = 2; } m->combatspells[nr].sp = NULL; m->combatspells[nr].level = 0;