From: copperwater Date: Wed, 30 Jan 2019 13:17:52 +0000 (-0500) Subject: Pets are more careful about attacking monsters at low health X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=882efdcf58673fcda11210717fc164172a8b1502;p=nethack Pets are more careful about attacking monsters at low health 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. --- diff --git a/doc/fixes37.0 b/doc/fixes37.0 index 34dece0ba..a06c27ea4 100644 --- a/doc/fixes37.0 +++ b/doc/fixes37.0 @@ -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 diff --git a/src/dogmove.c b/src/dogmove.c index fa5b0a389..02327bd5e 100644 --- a/src/dogmove.c +++ b/src/dogmove.c @@ -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))