Allow pets to use ranged attacks
This is the Pet ranged attack -patch by Darshan Shaligram, with the spellcaster parts removed to keep it simpler. Pets will now throw, spit and breathe at other monsters.
This commit is contained in:
49
src/mhitm.c
49
src/mhitm.c
@@ -356,6 +356,17 @@ register struct monst *magr, *mdef;
|
||||
attk = 1;
|
||||
switch (mattk->aatyp) {
|
||||
case AT_WEAP: /* "hand to hand" attacks */
|
||||
if (distmin(magr->mx,magr->my,mdef->mx,mdef->my) > 1) {
|
||||
/* D: Do a ranged attack here! */
|
||||
strike = thrwmm(magr, mdef);
|
||||
if (DEADMONSTER(mdef))
|
||||
res[i] = MM_DEF_DIED;
|
||||
|
||||
if (DEADMONSTER(magr))
|
||||
res[i] |= MM_AGR_DIED;
|
||||
|
||||
break;
|
||||
}
|
||||
if (magr->weapon_check == NEED_WEAPON || !MON_WEP(magr)) {
|
||||
magr->weapon_check = NEED_HTH_WEAPON;
|
||||
if (mon_wield_item(magr) != 0)
|
||||
@@ -379,7 +390,9 @@ register struct monst *magr, *mdef;
|
||||
case AT_TENT:
|
||||
/* Nymph that teleported away on first attack? */
|
||||
if (distmin(magr->mx, magr->my, mdef->mx, mdef->my) > 1)
|
||||
return MM_MISS;
|
||||
/* Continue because the monster may have a ranged
|
||||
* attack */
|
||||
continue;
|
||||
/* Monsters won't attack cockatrices physically if they
|
||||
* have a weapon instead. This instinct doesn't work for
|
||||
* players, or under conflict or confusion.
|
||||
@@ -428,6 +441,10 @@ register struct monst *magr, *mdef;
|
||||
break;
|
||||
|
||||
case AT_EXPL:
|
||||
/* D: Prevent explosions from a distance */
|
||||
if (distmin(magr->mx,magr->my,mdef->mx,mdef->my) > 1)
|
||||
continue;
|
||||
|
||||
res[i] = explmm(magr, mdef, mattk);
|
||||
if (res[i] == MM_MISS) { /* cancelled--no attack */
|
||||
strike = 0;
|
||||
@@ -441,6 +458,9 @@ register struct monst *magr, *mdef;
|
||||
strike = 0;
|
||||
break;
|
||||
}
|
||||
/* D: Prevent engulf from a distance */
|
||||
if (distmin(magr->mx,magr->my,mdef->mx,mdef->my) > 1)
|
||||
continue;
|
||||
/* Engulfing attacks are directed at the hero if
|
||||
* possible. -dlc
|
||||
*/
|
||||
@@ -454,13 +474,38 @@ register struct monst *magr, *mdef;
|
||||
}
|
||||
break;
|
||||
|
||||
case AT_BREA:
|
||||
if (!monnear(magr, mdef->mx, mdef->my)) {
|
||||
strike = breamm(magr, mattk, mdef);
|
||||
|
||||
/* We don't really know if we hit or not, but pretend
|
||||
* we did */
|
||||
if (strike) res[i] |= MM_HIT;
|
||||
if (DEADMONSTER(mdef)) res[i] = MM_DEF_DIED;
|
||||
if (DEADMONSTER(magr)) res[i] |= MM_AGR_DIED;
|
||||
}
|
||||
else
|
||||
strike = 0;
|
||||
break;
|
||||
case AT_SPIT:
|
||||
if (!monnear(magr, mdef->mx, mdef->my)) {
|
||||
strike = spitmm(magr, mattk, mdef);
|
||||
|
||||
/* We don't really know if we hit or not, but pretend
|
||||
* we did */
|
||||
if (strike) res[i] |= MM_HIT;
|
||||
if (DEADMONSTER(mdef)) res[i] = MM_DEF_DIED;
|
||||
if (DEADMONSTER(magr)) res[i] |= MM_AGR_DIED;
|
||||
}
|
||||
break;
|
||||
default: /* no attack */
|
||||
strike = 0;
|
||||
attk = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (attk && !(res[i] & MM_AGR_DIED))
|
||||
if (attk && !(res[i] & MM_AGR_DIED)
|
||||
&& distmin(magr->mx,magr->my,mdef->mx,mdef->my) <= 1)
|
||||
res[i] = passivemm(magr, mdef, strike, res[i] & MM_DEF_DIED);
|
||||
|
||||
if (res[i] & MM_DEF_DIED)
|
||||
|
||||
Reference in New Issue
Block a user