Unify impaired movement direction checks

This commit is contained in:
Pasi Kallinen
2022-07-17 12:23:49 +03:00
parent 1ae2bc7063
commit 6fe0f7c132
5 changed files with 22 additions and 16 deletions

View File

@@ -281,7 +281,7 @@ extern void dtoxy(coord *, int);
extern int movecmd(char, int); extern int movecmd(char, int);
extern int dxdy_moveok(void); extern int dxdy_moveok(void);
extern int getdir(const char *); extern int getdir(const char *);
extern void confdir(void); extern void confdir(boolean);
extern const char *directionname(int); extern const char *directionname(int);
extern int isok(coordxy, coordxy); extern int isok(coordxy, coordxy);
extern int get_adjacent_loc(const char *, const char *, coordxy, coordxy, coord *); 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); extern int wiz_debug_cmd_traveldisplay(void);
#endif #endif
extern boolean u_rooted(void); extern boolean u_rooted(void);
extern boolean u_maybe_impaired(void);
extern const char *u_locomotion(const char *); extern const char *u_locomotion(const char *);
extern void domove(void); extern void domove(void);
extern void runmode_delay_output(void); extern void runmode_delay_output(void);

View File

@@ -355,8 +355,7 @@ use_stethoscope(struct obj *obj)
You_hear("your heart beat."); You_hear("your heart beat.");
return res; return res;
} }
if (Stunned || (Confusion && !rn2(5))) confdir(FALSE);
confdir();
if (!u.dx && !u.dy) { if (!u.dx && !u.dy) {
ustatusline(); ustatusline();
return res; return res;
@@ -2850,8 +2849,7 @@ use_whip(struct obj *obj)
rx = mtmp->mx; rx = mtmp->mx;
ry = mtmp->my; ry = mtmp->my;
} else { } else {
if (Stunned || (Confusion && !rn2(5))) confdir(FALSE);
confdir();
rx = u.ux + u.dx; rx = u.ux + u.dx;
ry = u.uy + u.dy; ry = u.uy + u.dy;
if (!isok(rx, ry)) { if (!isok(rx, ry)) {

View File

@@ -4607,8 +4607,8 @@ getdir(const char *s)
You_cant("orient yourself that direction."); You_cant("orient yourself that direction.");
return 0; return 0;
} }
if (!u.dz && (Stunned || (Confusion && !rn2(5)))) if (!u.dz)
confdir(); confdir(FALSE);
return 1; return 1;
} }
@@ -4789,14 +4789,16 @@ help_dir(
return TRUE; return TRUE;
} }
/* if hero is impaired, pick random movement direction */
void 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.dx = xdir[x];
u.dy = ydir[x]; u.dy = ydir[x];
return; }
} }
const char * const char *

View File

@@ -1058,8 +1058,7 @@ use_pick_axe2(struct obj *obj)
g.context.botl = 1; g.context.botl = 1;
return ECMD_TIME; return ECMD_TIME;
} else if (u.dz == 0) { } else if (u.dz == 0) {
if (Stunned || (Confusion && !rn2(5))) confdir(FALSE);
confdir();
rx = u.ux + u.dx; rx = u.ux + u.dx;
ry = u.uy + u.dy; ry = u.uy + u.dy;
if (!isok(rx, ry)) { if (!isok(rx, ry)) {

View File

@@ -2046,11 +2046,17 @@ slippery_ice_fumbling(void)
HFumbling &= ~FROMOUTSIDE; HFumbling &= ~FROMOUTSIDE;
} }
boolean
u_maybe_impaired(void)
{
return (Stunned || (Confusion && !rn2(5)));
}
/* change movement dir if impaired. return TRUE if can't move */ /* change movement dir if impaired. return TRUE if can't move */
static boolean static boolean
impaired_movement(coordxy *x, coordxy *y) impaired_movement(coordxy *x, coordxy *y)
{ {
if (Stunned || (Confusion && !rn2(5))) { if (u_maybe_impaired()) {
register int tries = 0; register int tries = 0;
do { do {
@@ -2058,7 +2064,7 @@ impaired_movement(coordxy *x, coordxy *y)
nomul(0); nomul(0);
return TRUE; return TRUE;
} }
confdir(); confdir(TRUE);
*x = u.ux + u.dx; *x = u.ux + u.dx;
*y = u.uy + u.dy; *y = u.uy + u.dy;
} while (!isok(*x, *y) || bad_rock(g.youmonst.data, *x, *y)); } while (!isok(*x, *y) || bad_rock(g.youmonst.data, *x, *y));