From 1a4223faac8d3f63dcfa4a51ec32d48b5a7a953a Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Mon, 29 Apr 2019 18:50:08 +0300 Subject: [PATCH] Unify code for cure self spell --- src/mcastu.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/mcastu.c b/src/mcastu.c index 7da15e77e..ca6d256cb 100644 --- a/src/mcastu.c +++ b/src/mcastu.c @@ -38,6 +38,7 @@ enum mcast_cleric_spells { STATIC_DCL void FDECL(cursetxt, (struct monst *, BOOLEAN_P)); STATIC_DCL int FDECL(choose_magic_spell, (int)); STATIC_DCL int FDECL(choose_clerical_spell, (int)); +STATIC_DCL int FDECL(m_cure_self, (struct monst *, int)); STATIC_DCL void FDECL(cast_wizard_spell, (struct monst *, int, int)); STATIC_DCL void FDECL(cast_cleric_spell, (struct monst *, int, int)); STATIC_DCL boolean FDECL(is_undirected_spell, (unsigned int, int)); @@ -336,6 +337,21 @@ boolean foundyou; return (ret); } +STATIC_OVL int +m_cure_self(mtmp, dmg) +struct monst *mtmp; +{ + if (mtmp->mhp < mtmp->mhpmax) { + if (canseemon(mtmp)) + pline("%s looks better.", Monnam(mtmp)); + /* note: player healing does 6d4; this used to do 1d8 */ + if ((mtmp->mhp += d(3, 6)) > mtmp->mhpmax) + mtmp->mhp = mtmp->mhpmax; + dmg = 0; + } + return dmg; +} + /* monster wizard and cleric spellcasting functions */ /* If dmg is zero, then the monster is not casting at you. @@ -474,14 +490,7 @@ int spellnum; dmg = 0; break; case MGC_CURE_SELF: - if (mtmp->mhp < mtmp->mhpmax) { - if (canseemon(mtmp)) - pline("%s looks better.", Monnam(mtmp)); - /* note: player healing does 6d4; this used to do 1d8 */ - if ((mtmp->mhp += d(3, 6)) > mtmp->mhpmax) - mtmp->mhp = mtmp->mhpmax; - dmg = 0; - } + dmg = m_cure_self(mtmp, dmg); break; case MGC_PSI_BOLT: /* prior to 3.4.0 Antimagic was setting the damage to 1--this @@ -695,14 +704,7 @@ int spellnum; dmg = 0; break; case CLC_CURE_SELF: - if (mtmp->mhp < mtmp->mhpmax) { - if (canseemon(mtmp)) - pline("%s looks better.", Monnam(mtmp)); - /* note: player healing does 6d4; this used to do 1d8 */ - if ((mtmp->mhp += d(3, 6)) > mtmp->mhpmax) - mtmp->mhp = mtmp->mhpmax; - dmg = 0; - } + dmg = m_cure_self(mtmp, dmg); break; case CLC_OPEN_WOUNDS: if (Antimagic) {