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) { for (s = b->sides; s != b->sides + b->nsides; ++s) {
fighter *fig; fighter *fig;
for (fig = s->fighters; fig; fig = fig->next) { for (fig = s->fighters; fig; fig = fig->next) {
unit *mage = fig->unit; unit *u = fig->unit;
unit *caster = mage; unit *caster = u;
if (fig->alive <= 0) if (fig->alive <= 0)
continue; /* fighter kann im Kampf getoetet worden sein */ continue; /* fighter kann im Kampf getoetet worden sein */
level = effskill(mage, SK_MAGIC, r); level = effskill(u, SK_MAGIC, r);
if (level > 0) { if (level > 0) {
double power; double power;
const spell *sp; const spell *sp;
const struct locale *lang = mage->faction->locale; const struct locale *lang = u->faction->locale;
order *ord; order *ord;
switch (was) { switch (was) {
case DO_PRECOMBATSPELL: case DO_PRECOMBATSPELL:
sp = get_combatspell(mage, 0); sp = mage_get_combatspell(get_mage(u), 0, &sl);
sl = get_combatspelllevel(mage, 0);
break; break;
case DO_POSTCOMBATSPELL: case DO_POSTCOMBATSPELL:
sp = get_combatspell(mage, 2); sp = mage_get_combatspell(get_mage(u), 2, &sl);
sl = get_combatspelllevel(mage, 2);
break; break;
default: default:
/* Fehler! */ /* Fehler! */
return; return;
} }
if (sp == NULL || !u_hasspell(mage, sp)) if (sp == NULL || !u_hasspell(u, sp))
continue; 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) { if (sl > 0 && sl < level) {
level = sl; level = sl;
} }
if (level < 1) { if (level < 1) {
report_failed_spell(b, mage, sp); report_failed_spell(b, u, sp);
continue; continue;
} }
ord = create_order(K_CAST, lang, "'%s'", spell_name(mkname_spell(sp), lang)); 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); free_order(ord);
if (power <= 0) { /* Effekt von Antimagie */ if (power <= 0) { /* Effekt von Antimagie */
report_failed_spell(b, mage, sp); report_failed_spell(b, u, sp);
pay_spell(mage, NULL, sp, level, 1); pay_spell(u, NULL, sp, level, 1);
} }
else if (fumble(r, mage, sp, level)) { else if (fumble(r, u, sp, level)) {
report_failed_spell(b, mage, sp); report_failed_spell(b, u, sp);
pay_spell(mage, NULL, sp, level, 1); pay_spell(u, NULL, sp, level, 1);
} }
else { else {
co = create_castorder_combat(0, fig, sp, level, power); co = create_castorder_combat(0, fig, sp, level, power);
@ -1774,34 +1772,31 @@ static void do_combatspell(troop at)
{ {
const spell *sp; const spell *sp;
fighter *fi = at.fighter; fighter *fi = at.fighter;
unit *mage = fi->unit; unit *u = fi->unit;
battle *b = fi->side->battle; battle *b = fi->side->battle;
region *r = b->region; region *r = b->region;
selist *ql; selist *ql;
int level, qi; int level, qi, sl;
double power; double power;
int fumblechance = 0; int fumblechance = 0;
struct sc_mage *mage = get_mage(u);
sp = get_combatspell(mage, 1); sp = mage_get_combatspell(mage, 1, &sl);
if (sp == NULL || !u_hasspell(mage, sp)) { if (sl <= 0 || sp == NULL || !u_hasspell(u, sp)) {
fi->magic = 0; /* Hat keinen Kampfzauber, kaempft nichtmagisch weiter */ fi->magic = 0; /* Hat keinen Kampfzauber, kaempft nichtmagisch weiter */
return; 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) { if (level < 1) {
fi->magic = 0; /* Kann nicht mehr Zaubern, kaempft nichtmagisch weiter */ fi->magic = 0; /* Kann nicht mehr Zaubern, kaempft nichtmagisch weiter */
return; return;
} }
else { else if (sl < level) {
int sl = get_combatspelllevel(mage, 1);
if (sl < level) {
level = sl; level = sl;
} }
} if (fumble(r, u, sp, level)) {
report_failed_spell(b, u, sp);
if (fumble(r, mage, sp, level)) { pay_spell(u, NULL, sp, level, 1);
report_failed_spell(b, mage, sp);
pay_spell(mage, NULL, sp, level, 1);
return; return;
} }
@ -1817,14 +1812,14 @@ static void do_combatspell(troop at)
/* Antimagie die Fehlschlag erhoeht */ /* Antimagie die Fehlschlag erhoeht */
if (rng_int() % 100 < fumblechance) { if (rng_int() % 100 < fumblechance) {
report_failed_spell(b, mage, sp); report_failed_spell(b, u, sp);
pay_spell(mage, NULL, sp, level, 1); pay_spell(u, NULL, sp, level, 1);
return; return;
} }
power = spellpower(r, mage, sp, level); power = spellpower(r, u, sp, level);
if (power <= 0) { /* Effekt von Antimagie */ if (power <= 0) { /* Effekt von Antimagie */
report_failed_spell(b, mage, sp); report_failed_spell(b, u, sp);
pay_spell(mage, NULL, sp, level, 1); pay_spell(u, NULL, sp, level, 1);
return; return;
} }

View File

@ -524,10 +524,12 @@ int get_combatspelllevel(const unit * u, int nr)
{ {
int level; int level;
if (mage_get_combatspell(get_mage(u), nr, &level) != NULL) { if (mage_get_combatspell(get_mage(u), nr, &level) != NULL) {
if (level > 0) {
int maxlevel = effskill(u, SK_MAGIC, NULL); int maxlevel = effskill(u, SK_MAGIC, NULL);
if (level > maxlevel) { if (level > maxlevel) {
return maxlevel; return maxlevel;
} }
}
return level; return level;
} }
return 0; return 0;
@ -573,21 +575,13 @@ void unset_combatspell(unit * u, spell * sp)
m->combatspells[i].sp = NULL; m->combatspells[i].sp = NULL;
} }
} }
else if (sp->sptyp & PRECOMBATSPELL) { else {
if (sp != get_combatspell(u, 0)) 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; 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].sp = NULL;
m->combatspells[nr].level = 0; m->combatspells[nr].level = 0;