knockback knocking riding hero out of saddle

I've implemented targetted dismount such that being knocked out of
the saddle will place the hero opposite the attacker in preference
to a random spot adjacent to the steed.  If that opposite spot
isn't appropriate, the two spots next to it get tried.

In these map fragments, H is knocking mounted hero off of u.  The
digits indicate priority of potential destinations.

|.....   |..21.
|...2.   |..u2.
|.Hu1.   |.H...
|...2.   |.....

If spot 1 isn't acceptable, both of spots 2 (in random order) will
be tried next.  If those aren't acceptable either, it will try the
other 5 spots adjacent to the steed (the one of those with the
attacker will always be unacceptable).  And as before, it none of
those work, it uses enexto() to pick a random spot as close to the
steed as feasible.

Not knockback:  when dismounting due to polymorph, avoid diagonal
adjacent spots if hero's new form can't move diagonally.  (The hero
can't already be in no-diagonal form because riding requires that
the rider be humanoid.  I keep thinking the restriction is "can't
be polymorphed" but that isn't correct.)
This commit is contained in:
PatR
2022-10-27 15:33:49 -07:00
parent 69f62e5872
commit da32b572a6
3 changed files with 106 additions and 40 deletions

View File

@@ -4732,10 +4732,15 @@ mhitm_knockback(
/* do the actual knockback effect */
if (u_def) {
/* normally dx,dy indicates direction hero is throwing, zapping, &c
but here it is used to pass the preferred direction for dismount
to dismount_steed (used for DISMOUNT_KNOCKED only) */
u.dx = sgn(u.ux - magr->mx); /* [sgn() is superfluous here] */
u.dy = sgn(u.uy - magr->my); /* [ditto] */
if (u.usteed)
dismount_steed(DISMOUNT_KNOCKED);
else
hurtle(u.ux - magr->mx, u.uy - magr->my, rnd(2), FALSE);
hurtle(u.dx, u.dy, rnd(2), FALSE);
set_apparxy(magr); /* update magr's idea of where you are */
if (!rn2(4))