]> granicus.if.org Git - nethack/commitdiff
Pets are more careful about attacking monsters at low health
authorcopperwater <aosdict@gmail.com>
Wed, 30 Jan 2019 13:17:52 +0000 (08:17 -0500)
committerPasi Kallinen <paxed@alt.org>
Sat, 22 May 2021 13:44:58 +0000 (16:44 +0300)
Another SliceHack feature. However, the math implemented by SliceHack
seemed incorrect, so I tweaked it.

Pets previously attacked monsters of up to one level higher than them as
long as they were above 25% health. Now, they will attack monsters as
follows:
100%: up to level + 2 (pets could not attack this high before)
80%+: up to level + 1
60%+: up to same level
40%+: up to level - 1
25%+: up to level - 2

The case that prevents any attacks below 25% health still exists.

doc/fixes37.0
src/dogmove.c

index 34dece0ba64deb9895252722d3484a0f4e3cf491..a06c27ea40d233a605c4924cc167ba9d5d69b6df 100644 (file)
@@ -531,6 +531,7 @@ make anti-magic fields drain more energy and prevent them from showing up
        too early in the dungeon
 eating magical monsters such as wizards or shamans may give a mild buzz
 make exploding spheres create an actual explosion
+pets are more careful about attacking monsters at low health
 
 
 Fixes to 3.7.0-x Problems that Were Exposed Via git Repository
index fa5b0a38912af4c5a298a14e9ba77c8e7c49cda9..02327bd5ef423678596c3fde60a18f5534154aeb 100644 (file)
@@ -971,8 +971,18 @@ dog_move(register struct monst *mtmp,
         if ((info[i] & ALLOW_M) && MON_AT(nx, ny)) {
             int mstatus;
             register struct monst *mtmp2 = m_at(nx, ny);
+            /* weight the audacity of the pet to attack a differently-leveled
+             * foe based on its fraction of max HP:
+             *       100%:  up to level + 2
+             * 80% and up:  up to level + 1
+             * 60% to 80%:  up to level
+             * 40% to 60%:  up to level - 1
+             * 25% to 40%:  up to level - 2
+             *  below 25%:  prevented from attacking at all by a different case
+             */
+            int balk = mtmp->m_lev + ((5 * mtmp->mhp) / mtmp->mhpmax) - 2;
 
-            if ((int) mtmp2->m_lev >= (int) mtmp->m_lev + 2
+            if ((int) mtmp2->m_lev >= balk
                 || (mtmp2->data == &mons[PM_FLOATING_EYE] && rn2(10)
                     && mtmp->mcansee && haseyes(mtmp->data) && mtmp2->mcansee
                     && (perceives(mtmp->data) || !mtmp2->minvis))