Unify ad_elec

This commit is contained in:
Pasi Kallinen
2020-11-30 20:15:13 +02:00
parent 6abfe7e548
commit 8a78c49fea
4 changed files with 83 additions and 45 deletions

View File

@@ -2762,6 +2762,7 @@ E void FDECL(mhitm_ad_dren, (struct monst *, struct attack *, struct monst *, st
E void FDECL(mhitm_ad_drli, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
E void FDECL(mhitm_ad_fire, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
E void FDECL(mhitm_ad_cold, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
E void FDECL(mhitm_ad_elec, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
E int FDECL(damageum, (struct monst *, struct attack *, int));
E void FDECL(missum, (struct monst *, struct attack *, BOOLEAN_P));
E int FDECL(passive, (struct monst *, struct obj *, BOOLEAN_P, int,

View File

@@ -1026,22 +1026,9 @@ int dieroll;
return mhm.hitflags;
break;
case AD_ELEC:
if (cancelled) {
mhm.damage = 0;
break;
}
if (g.vis && canseemon(mdef))
pline("%s gets zapped!", Monnam(mdef));
mhm.damage += destroy_mitem(mdef, WAND_CLASS, AD_ELEC);
if (resists_elec(mdef)) {
if (g.vis && canseemon(mdef))
pline_The("zap doesn't shock %s!", mon_nam(mdef));
shieldeff(mdef->mx, mdef->my);
golemeffects(mdef, AD_ELEC, mhm.damage);
mhm.damage = 0;
}
/* only rings damage resistant players in destroy_item */
mhm.damage += destroy_mitem(mdef, RING_CLASS, AD_ELEC);
mhitm_ad_elec(magr, mattk, mdef, &mhm);
if (mhm.done)
return mhm.hitflags;
break;
case AD_ACID:
if (magr->mcan) {

View File

@@ -1108,19 +1108,9 @@ register struct attack *mattk;
return mhm.hitflags;
break;
case AD_ELEC:
hitmsg(mtmp, mattk);
if (uncancelled) {
You("get zapped!");
if (Shock_resistance) {
pline_The("zap doesn't shock you!");
mhm.damage = 0;
}
if ((int) mtmp->m_lev > rn2(20))
destroy_item(WAND_CLASS, AD_ELEC);
if ((int) mtmp->m_lev > rn2(20))
destroy_item(RING_CLASS, AD_ELEC);
} else
mhm.damage = 0;
mhitm_ad_elec(mtmp, mattk, &g.youmonst, &mhm);
if (mhm.done)
return mhm.hitflags;
break;
case AD_SLEE:
hitmsg(mtmp, mattk);

View File

@@ -2140,6 +2140,79 @@ struct mhitm_data *mhm;
}
}
void
mhitm_ad_elec(magr, mattk, mdef, mhm)
struct monst *magr;
struct attack *mattk;
struct monst *mdef;
struct mhitm_data *mhm;
{
struct permonst *pd = mdef->data;
if (magr == &g.youmonst) {
/* uhitm */
int armpro = magic_negation(mdef);
/* since hero can't be cancelled, only defender's armor applies */
boolean negated = !(rn2(10) >= 3 * armpro);
if (negated) {
mhm->damage = 0;
return;
}
if (!Blind)
pline("%s is zapped!", Monnam(mdef));
mhm->damage += destroy_mitem(mdef, WAND_CLASS, AD_ELEC);
if (resists_elec(mdef)) {
if (!Blind)
pline_The("zap doesn't shock %s!", mon_nam(mdef));
golemeffects(mdef, AD_ELEC, mhm->damage);
shieldeff(mdef->mx, mdef->my);
mhm->damage = 0;
}
/* only rings damage resistant players in destroy_item */
mhm->damage += destroy_mitem(mdef, RING_CLASS, AD_ELEC);
} else if (mdef == &g.youmonst) {
/* mhitu */
int armpro = magic_negation(mdef);
boolean uncancelled = !magr->mcan && (rn2(10) >= 3 * armpro);
hitmsg(magr, mattk);
if (uncancelled) {
You("get zapped!");
if (Shock_resistance) {
pline_The("zap doesn't shock you!");
mhm->damage = 0;
}
if ((int) magr->m_lev > rn2(20))
destroy_item(WAND_CLASS, AD_ELEC);
if ((int) magr->m_lev > rn2(20))
destroy_item(RING_CLASS, AD_ELEC);
} else
mhm->damage = 0;
} else {
/* mhitm */
int armpro = magic_negation(mdef);
boolean cancelled = magr->mcan || !(rn2(10) >= 3 * armpro);
if (cancelled) {
mhm->damage = 0;
return;
}
if (g.vis && canseemon(mdef))
pline("%s gets zapped!", Monnam(mdef));
mhm->damage += destroy_mitem(mdef, WAND_CLASS, AD_ELEC);
if (resists_elec(mdef)) {
if (g.vis && canseemon(mdef))
pline_The("zap doesn't shock %s!", mon_nam(mdef));
shieldeff(mdef->mx, mdef->my);
golemeffects(mdef, AD_ELEC, mhm->damage);
mhm->damage = 0;
}
/* only rings damage resistant players in destroy_item */
mhm->damage += destroy_mitem(mdef, RING_CLASS, AD_ELEC);
}
}
/* Template for monster hits monster for AD_FOO.
- replace "break" with return
@@ -2251,22 +2324,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */
return mhm.hitflags;
break;
case AD_ELEC:
if (negated) {
mhm.damage = 0;
break;
}
if (!Blind)
pline("%s is zapped!", Monnam(mdef));
mhm.damage += destroy_mitem(mdef, WAND_CLASS, AD_ELEC);
if (resists_elec(mdef)) {
if (!Blind)
pline_The("zap doesn't shock %s!", mon_nam(mdef));
golemeffects(mdef, AD_ELEC, mhm.damage);
shieldeff(mdef->mx, mdef->my);
mhm.damage = 0;
}
/* only rings damage resistant players in destroy_item */
mhm.damage += destroy_mitem(mdef, RING_CLASS, AD_ELEC);
mhitm_ad_elec(&g.youmonst, mattk, mdef, &mhm);
if (mhm.done)
return mhm.hitflags;
break;
case AD_ACID:
if (resists_acid(mdef))