diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-10-15 11:31:01 +0200 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-10-15 11:36:21 +0200 |
commit | ebf5a248635cf60c77083a6f6e2c13a6ac765cda (patch) | |
tree | 736c407dc0a3b7f83129eea2522b40049de25638 | |
parent | 26cadc029618115ae85103c807ea38b7f52c3838 (diff) | |
download | crawl-ref-ebf5a248635cf60c77083a6f6e2c13a6ac765cda.tar.gz crawl-ref-ebf5a248635cf60c77083a6f6e2c13a6ac765cda.zip |
Remove fallback calculation from find_ray.
There is now a separate fallback_ray() that needs to be called
explicitly. I've manually converted uses of find_ray with
allow_fallback == true.
find_ray with allow_fallback set always returned true, yet there
were a number of places that used the return value, in particular
in directn.cc. I'll check these later.
-rw-r--r-- | crawl-ref/source/beam.cc | 7 | ||||
-rw-r--r-- | crawl-ref/source/decks.cc | 2 | ||||
-rw-r--r-- | crawl-ref/source/directn.cc | 44 | ||||
-rw-r--r-- | crawl-ref/source/l_los.cc | 2 | ||||
-rw-r--r-- | crawl-ref/source/los.cc | 48 | ||||
-rw-r--r-- | crawl-ref/source/los.h | 8 | ||||
-rw-r--r-- | crawl-ref/source/mon-los.cc | 5 | ||||
-rw-r--r-- | crawl-ref/source/spells4.cc | 2 | ||||
-rw-r--r-- | crawl-ref/source/xom.cc | 2 |
9 files changed, 65 insertions, 55 deletions
diff --git a/crawl-ref/source/beam.cc b/crawl-ref/source/beam.cc index de692872c5..e87cfbd906 100644 --- a/crawl-ref/source/beam.cc +++ b/crawl-ref/source/beam.cc @@ -1591,7 +1591,10 @@ void bolt::apply_beam_conducts() void bolt::choose_ray() { if (!chose_ray || reflections > 0) - find_ray(source, target, true, ray, 0, true); + { + if (!find_ray(source, target, ray, 0, true)) + fallback_ray(source, target, ray); + } } // Draw the bolt at p if needed. @@ -2844,7 +2847,7 @@ bool check_line_of_sight(const coord_def& source, const coord_def& target) // Note that we are guaranteed to be within the player LOS range, // so fallback is unnecessary. ray_def ray; - return find_ray(source, target, false, ray); + return find_ray(source, target, ray); } // When a mimic is hit by a ranged attack, it teleports away (the slow diff --git a/crawl-ref/source/decks.cc b/crawl-ref/source/decks.cc index f067d84a15..5c13839431 100644 --- a/crawl-ref/source/decks.cc +++ b/crawl-ref/source/decks.cc @@ -1584,7 +1584,7 @@ static void _move_stair(coord_def stair_pos, bool away) } ray_def ray; - if (!find_ray(begin, towards, true, ray, 0, true)) + if (!find_ray(begin, towards, ray, 0, true)) { mpr("Couldn't find ray between player and stairs.", MSGCH_ERROR); return; diff --git a/crawl-ref/source/directn.cc b/crawl-ref/source/directn.cc index e3d758a195..3ea523968b 100644 --- a/crawl-ref/source/directn.cc +++ b/crawl-ref/source/directn.cc @@ -410,7 +410,8 @@ static void _direction_again(dist& moves, targetting_type restricts, moves.target = you.prev_grd_targ; ray_def ray; - find_ray(you.pos(), moves.target, true, ray, 0, true); + if (!find_ray(you.pos(), moves.target, ray, 0, true)) + fallback_ray(you.pos(), moves.target, ray); moves.ray = ray; } else if (you.prev_targ == MHITYOU) @@ -446,7 +447,8 @@ static void _direction_again(dist& moves, targetting_type restricts, moves.target = montarget->pos(); ray_def ray; - find_ray(you.pos(), moves.target, true, ray, 0, true); + if (!find_ray(you.pos(), moves.target, ray, 0, true)) + fallback_ray(you.pos(), moves.target, ray); moves.ray = ray; } @@ -968,7 +970,8 @@ static bool _blocked_ray(const coord_def &where, dungeon_feature_type* feat = NULL) { ray_def ray; - find_ray(you.pos(), where, true, ray, 0, true); + if (!find_ray(you.pos(), where, ray, 0, true)) + fallback_ray(you.pos(), where, ray); ray.advance_through(where); while (ray.pos() != where) @@ -1048,7 +1051,8 @@ void direction(dist& moves, targetting_type restricts, // If we show the beam on startup, we have to initialise it. if (show_beam) - find_ray(you.pos(), moves.target, true, ray); + if (!find_ray(you.pos(), moves.target, ray)) + fallback_ray(you.pos(), moves.target, ray); bool skip_iter = false; bool found_autotarget = false; @@ -1319,8 +1323,12 @@ void direction(dist& moves, targetting_type restricts, #ifdef WIZARD case CMD_TARGET_CYCLE_BEAM: - show_beam = find_ray(you.pos(), moves.target, - true, ray, (show_beam ? 1 : 0)); + // XXX: show_beam was conditional on find_ray + // with fallback succeeding. + if (!find_ray(you.pos(), moves.target, + ray, (show_beam ? 1 : 0))) + fallback_ray(you.pos(), moves.target, ray); + show_beam = true; need_beam_redraw = true; break; #endif @@ -1340,8 +1348,12 @@ void direction(dist& moves, targetting_type restricts, break; } - show_beam = find_ray(you.pos(), moves.target, - true, ray, 0, true); + // XXX: show_beam was conditional on find_ray + // with fallback succeeding. + if (!find_ray(you.pos(), moves.target, + ray, 0, true)) + fallback_ray(you.pos(), moves.target, ray); + show_beam = true; need_beam_redraw = show_beam; } break; @@ -1693,8 +1705,10 @@ void direction(dist& moves, targetting_type restricts, if (show_beam) { - show_beam = find_ray(you.pos(), moves.target, - true, ray, 0, true); + // XXX: show_beam was conditional on find_ray + // with fallback succeeding. + if (!find_ray(you.pos(), moves.target, ray, 0, true)) + fallback_ray(you.pos(), moves.target, ray); } } @@ -1720,10 +1734,12 @@ void direction(dist& moves, targetting_type restricts, // Tiles always need a beam redraw if show_beam is true (and valid...) if (!need_beam_redraw) { - need_beam_redraw = show_beam - && find_ray(you.pos(), moves.target, true, ray, - 0, true) - && !_blocked_ray(moves.target); + if (show_beam) + { + if (!find_ray(you.pos(), moves.target, ray, 0, true)) + fallback_ray(you.pos(), moves.target, ray); + need_beam_redraw = !_blocked_ray(moves.target); + } } #endif if (need_beam_redraw) diff --git a/crawl-ref/source/l_los.cc b/crawl-ref/source/l_los.cc index 1fe19e75bd..3d4c38f498 100644 --- a/crawl-ref/source/l_los.cc +++ b/crawl-ref/source/l_los.cc @@ -25,7 +25,7 @@ LUAFN(los_find_ray) GETCOORD(a, 1, 2, map_bounds); GETCOORD(b, 3, 4, map_bounds); ray_def *ray = new ray_def; - if (find_ray(a, b, false, *ray, 0, true)) + if (find_ray(a, b, *ray, 0, true)) { lua_push_ray(ls, ray); return (1); diff --git a/crawl-ref/source/los.cc b/crawl-ref/source/los.cc index 8598f8ce00..bc148d057f 100644 --- a/crawl-ref/source/los.cc +++ b/crawl-ref/source/los.cc @@ -559,8 +559,8 @@ struct trans }; // Find ray in positive quadrant. -bool _find_ray_se(const coord_def& target, bool allow_fallback, - ray_def& ray, int cycle_dir, bool find_best, +bool _find_ray_se(const coord_def& target, ray_def& ray, + int cycle_dir, bool find_best, bool ignore_solid, trans t) { ASSERT(target.x >= 0 && target.y >= 0 && !target.origin()); @@ -569,7 +569,7 @@ bool _find_ray_se(const coord_def& target, bool allow_fallback, int imbalance = INFINITE_DISTANCE; const double want_slope = _calc_slope(target.x, target.y); double slope_diff = VERTICAL_SLOPE * 10.0; - double ray_slope_diff; + double ray_slope_diff = slope_diff; std::vector<coord_def> unaliased_ray; for (unsigned int fray = 0; fray < fullrays.size(); ++fray) @@ -652,33 +652,12 @@ bool _find_ray_se(const coord_def& target, bool allow_fallback, } } - if (find_best && found) - return (true); - - if (allow_fallback) - { -#ifdef DEBUG_DIAGNOSTICS - coord_def src = t.transform(coord_def(0,0)); - coord_def trg = t.transform(target); - mprf(MSGCH_DIAGNOSTICS, - "falling back in ray search: (%d,%d) to (%d,%d)", - src.x, src.y, trg.x, trg.y); -#endif - ray.accx = 0.5; - ray.accy = 0.5; - if (target.x == 0) - ray.slope = VERTICAL_SLOPE; - else - ray.slope = target.y / target.x; - ray.fullray_idx = -1; - return (true); - } - return (false); + return (found); } bool find_ray(const coord_def& source, const coord_def& target, - bool allow_fallback, ray_def& ray, int cycle_dir, - bool find_shortest, bool ignore_solid) + ray_def& ray, int cycle_dir, + bool find_best, bool ignore_solid) { if (target == source) { @@ -707,8 +686,7 @@ bool find_ray(const coord_def& source, const coord_def& target, ray.quadx = 1; ray.quady = 1; - if (!_find_ray_se(abs, allow_fallback, ray, cycle_dir, - find_shortest, ignore_solid, t)) + if (!_find_ray_se(abs, ray, cycle_dir, find_best, ignore_solid, t)) return false; if (signx < 0) @@ -724,6 +702,16 @@ bool find_ray(const coord_def& source, const coord_def& target, return true; } +void fallback_ray(const coord_def& source, const coord_def& target, + ray_def& ray) +{ + ray.accx = source.x + 0.5; + ray.accy = source.y + 0.5; + coord_def diff = target - source; + ray.slope = _calc_slope(std::abs(diff.x), std::abs(diff.y)); + _set_ray_quadrant(ray, source.x, source.y, target.x, target.y); +} + // Count the number of matching features between two points along // a beam-like path; the path will pass through solid features. // By default, it excludes end points from the count. @@ -739,7 +727,7 @@ int num_feats_between(const coord_def& source, const coord_def& target, int max_dist = grid_distance(source, target); // We don't need to find the shortest beam, any beam will suffice. - find_ray( source, target, true, ray, 0, false, true ); + fallback_ray(source, target, ray); if (exclude_endpoints && ray.pos() == source) { diff --git a/crawl-ref/source/los.h b/crawl-ref/source/los.h index 1c258d34a8..d448037c7e 100644 --- a/crawl-ref/source/los.h +++ b/crawl-ref/source/los.h @@ -18,9 +18,11 @@ void setLOSRadius(int newLR); int get_los_radius_squared(); // XXX struct ray_def; -bool find_ray( const coord_def& source, const coord_def& target, - bool allow_fallback, ray_def& ray, int cycle_dir = 0, - bool find_shortest = false, bool ignore_solid = false ); +bool find_ray(const coord_def& source, const coord_def& target, + ray_def& ray, int cycle_dir = 0, bool find_shortest = false, + bool ignore_solid = false); +void fallback_ray(const coord_def& source, const coord_def& target, + ray_def& ray); int num_feats_between(const coord_def& source, const coord_def& target, dungeon_feature_type min_feat, diff --git a/crawl-ref/source/mon-los.cc b/crawl-ref/source/mon-los.cc index 8de3f8a2b0..16458b4c97 100644 --- a/crawl-ref/source/mon-los.cc +++ b/crawl-ref/source/mon-los.cc @@ -364,8 +364,9 @@ void monster_los::check_los_beam(int dx, int dy) continue; dist = 0; - find_ray( coord_def(gridx, gridy), coord_def(tx, ty), - true, ray, 0, true, true ); + if (!find_ray(coord_def(gridx, gridy), coord_def(tx, ty), + ray, 0, true, true)) + fallback_ray(coord_def(gridx, gridy), coord_def(tx, ty), ray); if (ray.x() == gridx && ray.y() == gridy) ray.advance(true); diff --git a/crawl-ref/source/spells4.cc b/crawl-ref/source/spells4.cc index 2bf09e4eb8..b3f96e5ca3 100644 --- a/crawl-ref/source/spells4.cc +++ b/crawl-ref/source/spells4.cc @@ -1369,7 +1369,7 @@ bool cast_fragmentation(int pow, const dist& spd) const char *what = NULL; ray_def ray; - if (!find_ray(you.pos(), spd.target, false, ray)) + if (!find_ray(you.pos(), spd.target, ray)) { mpr("There's a wall in the way!"); return (false); diff --git a/crawl-ref/source/xom.cc b/crawl-ref/source/xom.cc index f38beccec9..4f3fd68277 100644 --- a/crawl-ref/source/xom.cc +++ b/crawl-ref/source/xom.cc @@ -2935,7 +2935,7 @@ static bool _move_stair(coord_def stair_pos, bool away) } ray_def ray; - if (!find_ray(begin, towards, true, ray, 0, true)) + if (!find_ray(begin, towards, ray, 0, true)) { mpr("Couldn't find ray between player and stairs.", MSGCH_ERROR); return (stairs_moved); |