]> granicus.if.org Git - nethack/commitdiff
fix #H261 - bias in Bresenham's algorithm in walk_path
authornethack.rankin <nethack.rankin>
Thu, 29 Mar 2007 04:03:35 +0000 (04:03 +0000)
committernethack.rankin <nethack.rankin>
Thu, 29 Mar 2007 04:03:35 +0000 (04:03 +0000)
     From a bug report, walk_path() was
favoring orthogonal steps at beginning of the path and diagonal ones at
end, when intermixing diagonal and orthoganal produced a more accurate
representation of the real path.  Only mattered for long distance jumps
3x2 or 3x1 steps away; hurtling always moves in a straight line and short
(2x1 knight) jumps aren't affected by the patch supplied with the report.

doc/fixes34.4
src/dothrow.c

index 6180adf091c3d16aa7fb74af1c2455f1f35a3a41..8d4a77b4b3effd300df78319fe5b0ea0af4a0a58 100644 (file)
@@ -342,6 +342,7 @@ lit candle or potion of oil which burned out while equipped would leave stale
 wielded/worn figurine which auto-transformed had same stale pointer bug
 format names of not yet id'd artifacts such that obj type shows for non-weapons
 make quest leader and nemesis be unlikely to be affected by traps
+use a more precise jumping path for far, non-straight line destinations
 
 
 Platform- and/or Interface-Specific Fixes
index 04abedddc70f4c3576fbe4565f08040434248e57..42bf9fbba757a27cdf67066dd280e6b350c5309b 100644 (file)
@@ -433,10 +433,10 @@ walk_path(src_cc, dest_cc, check_proc, arg)
            prev_x = x;
            prev_y = y;
            y += y_change;
-           err += dx;
-           if (err >= dy) {
+           err += dx << 1;
+           if (err > dy) {
                x += x_change;
-               err -= dy;
+               err -= dy << 1;
            }
        /* check for early exit condition */
        if (!(keep_going = (*check_proc)(arg, x, y)))
@@ -447,10 +447,10 @@ walk_path(src_cc, dest_cc, check_proc, arg)
            prev_x = x;
            prev_y = y;
            x += x_change;
-           err += dy;
-           if (err >= dx) {
+           err += dy << 1;
+           if (err > dx) {
                y += y_change;
-               err -= dx;
+               err -= dx << 1;
            }
        /* check for early exit condition */
        if (!(keep_going = (*check_proc)(arg, x, y)))