Skip to content

Commit

Permalink
Fix extra turn spent travelling into obstacles
Browse files Browse the repository at this point in the history
This actually fixes two closely-related bugs: travelling into a wall
when adjacent to it, and when not adjacent to it.  In both cases, you
must target the stone behind the wall to trigger the bug.

The core problem was that domove() was continuing to do moving logic
after travelling hit an obstacle, causing it to return 1 even though the
player hadn't moved.

From there, travelling into a wall when next to it spent a turn because
it itself always returned 1 instead of the result of domove().
Travelling into a wall when not starting next to it spent a turn because
the result of domove() in command_input() didn't set flags.move to 0
like do_command() normally does.

This also removes useless lines in domove() that set flags.move to 0,
since NitroHack already does this when a command function returns 0.

This bug also exists in upstream NitroHack.
  • Loading branch information
tung committed Sep 1, 2012
1 parent ab81299 commit 4f43437
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
7 changes: 6 additions & 1 deletion libnitrohack/src/allmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,12 @@ int command_input(int cmdidx, int rep, struct nh_cmd_arg *arg)
if (flags.mv) {
if (multi < COLNO && !--multi)
flags.travel = iflags.travel1 = flags.mv = flags.run = 0;
domove(u.dx, u.dy, 0);
if (!domove(u.dx, u.dy, 0)) {
/* Don't use a move when travelling into an obstacle.
* Handle this the same way as do_command(). */
flags.move = FALSE;
multi = 0;
}
} else
do_command(saved_cmd, multi, FALSE, arg);
}
Expand Down
6 changes: 2 additions & 4 deletions libnitrohack/src/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1831,10 +1831,8 @@ static int dotravel(int x, int y)
multi = max(COLNO,ROWNO);
u.last_str_turn = 0;
flags.mv = TRUE;

domove(0, 0, 0);

return 1;

return domove(0, 0, 0);
}

/*cmd.c*/
11 changes: 8 additions & 3 deletions libnitrohack/src/hack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,14 @@ int domove(schar dx, schar dy, schar dz)
findtravelpath(TRUE, &dx, &dy);
iflags.travel1 = 0;
}


/* Travel hit an obstacle, or domove() was called with
* dx, dy and dz all zero, which they shouldn't do. */
if (dx == 0 && dy == 0) { /* dz is always zero here from above */
nomul(0, NULL);
return 0;
}

if (((wtcap = near_capacity()) >= OVERLOADED
|| (wtcap > SLT_ENCUMBER &&
(Upolyd ? (u.mh < 5 && u.mh != u.mhmax)
Expand Down Expand Up @@ -1511,15 +1518,13 @@ int domove(schar dx, schar dy, schar dz)
if (IS_DOOR(tmpr->typ) && tmpr->doormask != D_BROKEN &&
tmpr->doormask != D_NODOOR && tmpr->doormask != D_ISOPEN) {
if (!doopen(dx, dy, 0)) {
flags.move = 0;
nomul(0, NULL);
return 0;
}
return 1;
}

if (!test_move(u.ux, u.uy, dx, dy, dz, DO_MOVE)) {
flags.move = 0;
nomul(0, NULL);
return 0;
}
Expand Down

0 comments on commit 4f43437

Please sign in to comment.