From 3d3428066bfc2d2417d82e9e67ec65088de833da Mon Sep 17 00:00:00 2001 From: dshaligram Date: Sun, 31 Dec 2006 09:27:05 +0000 Subject: Semi-controlled blink fix (Haran). git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup-0.1.7@752 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/spells4.cc | 69 +++++++++++---------------------------------- 1 file changed, 17 insertions(+), 52 deletions(-) diff --git a/crawl-ref/source/spells4.cc b/crawl-ref/source/spells4.cc index 4f005c81ac..f0101ee42f 100644 --- a/crawl-ref/source/spells4.cc +++ b/crawl-ref/source/spells4.cc @@ -3082,61 +3082,26 @@ static int quadrant_blink(int x, int y, int pow, int garbage) if (pow > 100) pow = 100; - // setup: Brent's new algorithm - // we are interested in two things: distance of a test point from - // the ideal 'line', and the distance of a test point from two - // actual points, one in the 'correct' direction and one in the - // 'incorrect' direction. - - // scale distance by 10 for more interesting numbers. - int l,m; // for line equation lx + my = 0 - l = (x - you.x_pos); - m = (you.y_pos - y); - - int tx, ty; // test x,y - int rx, ry; // x,y relative to you. - int sx, sy; // test point in the correct direction - int bx = x; // best x - int by = y; // best y - - int best_dist = 10000; - - sx = l; - sy = -m; - - // for each point (a,b), distance from the line is | la + mb | - - for(int tries = pow * pow / 500 + 1; tries > 0; tries--) - { - if (!random_near_space(you.x_pos, you.y_pos, tx, ty)) + const int dist = random2(6) + 2; // 2-7 + const int ox = you.x_pos + (x - you.x_pos) * dist; + const int oy = you.y_pos + (y - you.y_pos) * dist; + + int tx, ty; + for ( int i = 0; i < (pow*pow) / 500 + 1; ++i ) + { + // find a space near our target... + if ( !random_near_space(ox, oy, tx, ty) ) return 0; - - rx = tx - you.x_pos; - ry = ty - you.y_pos; - - int dist = l * rx + m * ry; - dist *= 10 * dist; // square and multiply by 10 - - // check distance to test points - int dist1 = distance(rx, ry, sx, sy) * 10; - int dist2 = distance(rx, ry, -sx, -sy) * 10; - - // 'good' points will always be closer to test point 1 - if (dist2 < dist1) - dist += 80; // make the point less attractive - - if (dist < best_dist) - { - best_dist = dist; - bx = tx; - by = ty; - } + + // which is close enough, and also far enough from us + if ( distance(ox, oy, tx, ty) <= 10 && + distance(you.x_pos, you.y_pos, tx, ty) >= 8 ) + break; } - you.x_pos = bx; - you.y_pos = by; - - return (1); + you.x_pos = tx; + you.y_pos = ty; + return 1; } int cast_semi_controlled_blink(int pow) -- cgit v1.2.3-54-g00ecf