diff --git a/include/extern.h b/include/extern.h index c3adf532c..2bb00c5af 100644 --- a/include/extern.h +++ b/include/extern.h @@ -281,7 +281,7 @@ extern void dtoxy(coord *, int); extern int movecmd(char, int); extern int dxdy_moveok(void); extern int getdir(const char *); -extern void confdir(void); +extern void confdir(boolean); extern const char *directionname(int); extern int isok(coordxy, coordxy); extern int get_adjacent_loc(const char *, const char *, coordxy, coordxy, coord *); @@ -944,6 +944,7 @@ extern boolean test_move(coordxy, coordxy, coordxy, coordxy, int); extern int wiz_debug_cmd_traveldisplay(void); #endif extern boolean u_rooted(void); +extern boolean u_maybe_impaired(void); extern const char *u_locomotion(const char *); extern void domove(void); extern void runmode_delay_output(void); diff --git a/src/apply.c b/src/apply.c index 8155db70a..55dc7aed1 100644 --- a/src/apply.c +++ b/src/apply.c @@ -355,8 +355,7 @@ use_stethoscope(struct obj *obj) You_hear("your heart beat."); return res; } - if (Stunned || (Confusion && !rn2(5))) - confdir(); + confdir(FALSE); if (!u.dx && !u.dy) { ustatusline(); return res; @@ -2850,8 +2849,7 @@ use_whip(struct obj *obj) rx = mtmp->mx; ry = mtmp->my; } else { - if (Stunned || (Confusion && !rn2(5))) - confdir(); + confdir(FALSE); rx = u.ux + u.dx; ry = u.uy + u.dy; if (!isok(rx, ry)) { diff --git a/src/cmd.c b/src/cmd.c index 27ee39213..0c4998c09 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -4607,8 +4607,8 @@ getdir(const char *s) You_cant("orient yourself that direction."); return 0; } - if (!u.dz && (Stunned || (Confusion && !rn2(5)))) - confdir(); + if (!u.dz) + confdir(FALSE); return 1; } @@ -4789,14 +4789,16 @@ help_dir( return TRUE; } +/* if hero is impaired, pick random movement direction */ void -confdir(void) +confdir(boolean force_impairment) { - register coordxy x = NODIAG(u.umonnum) ? dirs_ord[rn2(4)] : rn2(N_DIRS); + if (force_impairment || u_maybe_impaired()) { + register coordxy x = NODIAG(u.umonnum) ? dirs_ord[rn2(4)] : rn2(N_DIRS); - u.dx = xdir[x]; - u.dy = ydir[x]; - return; + u.dx = xdir[x]; + u.dy = ydir[x]; + } } const char * diff --git a/src/dig.c b/src/dig.c index 6dce498f7..f5a9e87b9 100644 --- a/src/dig.c +++ b/src/dig.c @@ -1058,8 +1058,7 @@ use_pick_axe2(struct obj *obj) g.context.botl = 1; return ECMD_TIME; } else if (u.dz == 0) { - if (Stunned || (Confusion && !rn2(5))) - confdir(); + confdir(FALSE); rx = u.ux + u.dx; ry = u.uy + u.dy; if (!isok(rx, ry)) { diff --git a/src/hack.c b/src/hack.c index 7005d2347..52764330a 100644 --- a/src/hack.c +++ b/src/hack.c @@ -2046,11 +2046,17 @@ slippery_ice_fumbling(void) HFumbling &= ~FROMOUTSIDE; } +boolean +u_maybe_impaired(void) +{ + return (Stunned || (Confusion && !rn2(5))); +} + /* change movement dir if impaired. return TRUE if can't move */ static boolean impaired_movement(coordxy *x, coordxy *y) { - if (Stunned || (Confusion && !rn2(5))) { + if (u_maybe_impaired()) { register int tries = 0; do { @@ -2058,7 +2064,7 @@ impaired_movement(coordxy *x, coordxy *y) nomul(0); return TRUE; } - confdir(); + confdir(TRUE); *x = u.ux + u.dx; *y = u.uy + u.dy; } while (!isok(*x, *y) || bad_rock(g.youmonst.data, *x, *y));