don't cast level 0 combat spells

This commit is contained in:
Enno Rehling 2021-04-21 18:05:26 +02:00
parent ca787ed447
commit 557f5458ea
2 changed files with 41 additions and 52 deletions

View File

@ -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) {
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;
}

View File

@ -524,10 +524,12 @@ int get_combatspelllevel(const unit * u, int nr)
{
int level;
if (mage_get_combatspell(get_mage(u), nr, &level) != NULL) {
if (level > 0) {
int maxlevel = effskill(u, SK_MAGIC, NULL);
if (level > maxlevel) {
return maxlevel;
}
}
return level;
}
return 0;
@ -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))
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;
}
else if (sp->sptyp & COMBATSPELL) {
if (sp != get_combatspell(u, 1)) {
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;