From b02539ff4ac1d21c8845c2af8378fb7bd9ff2ad8 Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Thu, 15 Oct 2009 13:43:09 +0200 Subject: Simplify ray handling in directn.cc. Existence of a valid ray is now tracked with a separate boolean have_beam. fallback_ray has been removed almost completely. The change appears fine in console crawl; tiles untested at the moment. find_ray now correctly returns false for rays with source == target. Also rename CMD_TARGET_HIDE_BEAM to CMD_TARGET_TOGGLE_BEAM. --- crawl-ref/source/cmd-keys.h | 2 +- crawl-ref/source/cmd-name.h | 2 +- crawl-ref/source/directn.cc | 88 ++++++++++++++------------------------------- crawl-ref/source/enum.h | 2 +- crawl-ref/source/los.cc | 5 +-- 5 files changed, 30 insertions(+), 69 deletions(-) diff --git a/crawl-ref/source/cmd-keys.h b/crawl-ref/source/cmd-keys.h index d680c708ed..931a36f740 100644 --- a/crawl-ref/source/cmd-keys.h +++ b/crawl-ref/source/cmd-keys.h @@ -166,7 +166,7 @@ {' ', CMD_TARGET_SELECT}, // XXX hack: can also be CMD_TARGET_CANCEL {CONTROL('P'), CMD_TARGET_SHOW_PROMPT}, {CONTROL('C'), CMD_TARGET_CYCLE_BEAM}, -{':', CMD_TARGET_HIDE_BEAM}, +{':', CMD_TARGET_TOGGLE_BEAM}, {'!', CMD_TARGET_SELECT_FORCE}, {'@', CMD_TARGET_SELECT_FORCE_ENDPOINT}, {'\r', CMD_TARGET_SELECT}, diff --git a/crawl-ref/source/cmd-name.h b/crawl-ref/source/cmd-name.h index a262f1cb85..c6be67526e 100644 --- a/crawl-ref/source/cmd-name.h +++ b/crawl-ref/source/cmd-name.h @@ -179,7 +179,7 @@ {CMD_TARGET_CYCLE_MLIST, "CMD_TARGET_CYCLE_MLIST"}, {CMD_TARGET_CYCLE_MLIST_END, "CMD_TARGET_CYCLE_MLIST_END"}, {CMD_TARGET_TOGGLE_MLIST, "CMD_TARGET_TOGGLE_MLIST"}, -{CMD_TARGET_HIDE_BEAM, "CMD_TARGET_HIDE_BEAM"}, +{CMD_TARGET_TOGGLE_BEAM, "CMD_TARGET_TOGGLE_BEAM"}, {CMD_TARGET_CENTER, "CMD_TARGET_CENTER"}, {CMD_TARGET_CANCEL, "CMD_TARGET_CANCEL"}, {CMD_TARGET_SHOW_PROMPT, "CMD_TARGET_SHOW_PROMPT"}, diff --git a/crawl-ref/source/directn.cc b/crawl-ref/source/directn.cc index 53f214c599..8e64e63e93 100644 --- a/crawl-ref/source/directn.cc +++ b/crawl-ref/source/directn.cc @@ -409,10 +409,8 @@ static void _direction_again(dist& moves, targetting_type restricts, moves.target = you.prev_grd_targ; - ray_def ray; - if (!find_ray(you.pos(), moves.target, ray, 0, true)) - fallback_ray(you.pos(), moves.target, ray); - moves.ray = ray; + moves.choseRay = find_ray(you.pos(), moves.target, + moves.ray, 0, true); } else if (you.prev_targ == MHITYOU) { @@ -446,10 +444,8 @@ static void _direction_again(dist& moves, targetting_type restricts, moves.target = montarget->pos(); - ray_def ray; - if (!find_ray(you.pos(), moves.target, ray, 0, true)) - fallback_ray(you.pos(), moves.target, ray); - moves.ray = ray; + moves.choseRay = find_ray(you.pos(), moves.target, + moves.ray, 0, true); } moves.isValid = true; @@ -966,6 +962,7 @@ bool _dist_ok(const dist& moves, int range, targ_mode_type mode, return (true); } +// XXX: fold this into generalized find_ray. static bool _blocked_ray(const coord_def &where, dungeon_feature_type* feat = NULL) { @@ -1030,7 +1027,7 @@ void direction(dist& moves, targetting_type restricts, if (restricts == DIR_DIR) { - direction_choose_compass( moves, beh ); + direction_choose_compass(moves, beh); return; } @@ -1041,6 +1038,7 @@ void direction(dist& moves, targetting_type restricts, int dir = 0; bool show_beam = Options.show_beam && !just_looking && needs_path; + bool have_beam = false; ray_def ray; coord_def objfind_pos, monsfind_pos; @@ -1051,8 +1049,7 @@ void direction(dist& moves, targetting_type restricts, // If we show the beam on startup, we have to initialise it. if (show_beam) - if (!find_ray(you.pos(), moves.target, ray)) - fallback_ray(you.pos(), moves.target, ray); + have_beam = find_ray(you.pos(), moves.target, ray); bool skip_iter = false; bool found_autotarget = false; @@ -1320,17 +1317,14 @@ void direction(dist& moves, targetting_type restricts, #ifdef WIZARD case CMD_TARGET_CYCLE_BEAM: - // 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; + have_beam = find_ray(you.pos(), moves.target, + ray, (show_beam ? 1 : 0)); need_beam_redraw = true; break; #endif - case CMD_TARGET_HIDE_BEAM: + case CMD_TARGET_TOGGLE_BEAM: if (show_beam) { show_beam = false; @@ -1345,13 +1339,10 @@ void direction(dist& moves, targetting_type restricts, break; } - // 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); + have_beam = find_ray(you.pos(), moves.target, + ray, 0, true); show_beam = true; - need_beam_redraw = show_beam; + need_beam_redraw = true; } break; @@ -1416,13 +1407,7 @@ void direction(dist& moves, targetting_type restricts, moves.target = montarget->pos(); if (!just_looking) { - // We have to turn off show_beam, because - // when jumping to a previous target we don't - // care about the beam; otherwise Bad Things - // will happen because the ray is invalid, - // and we don't get a chance to update it before - // breaking from the loop. - show_beam = false; + have_beam = false; loop_done = true; } } @@ -1678,14 +1663,12 @@ void direction(dist& moves, targetting_type restricts, { // Finalise whatever is inside the loop // (moves-internal finalizations can be done later). - moves.choseRay = show_beam; + moves.choseRay = have_beam; moves.ray = ray; break; } else - { show_prompt = true; - } } // We'll go on looping. Redraw whatever is necessary. @@ -1702,22 +1685,14 @@ void direction(dist& moves, targetting_type restricts, if (show_beam) { - // 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); + have_beam = find_ray(you.pos(), moves.target, + ray, 0, true); + need_beam_redraw = true; } } - if (force_redraw) - have_moved = true; - - if (have_moved) + if (have_moved || force_redraw) { - // If the target x,y has changed, the beam must have changed. - if (show_beam) - need_beam_redraw = true; - if (!skip_iter) // Don't clear before we get a chance to see. mesclr(true); // Maybe not completely necessary. @@ -1729,24 +1704,15 @@ void direction(dist& moves, targetting_type restricts, #ifdef USE_TILE // Tiles always need a beam redraw if show_beam is true (and valid...) - if (!need_beam_redraw) - { - 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); - } - } + if (show_beam) + need_beam_redraw = true; #endif if (need_beam_redraw) { #ifndef USE_TILE viewwindow(true, false); #endif - if (show_beam - && in_vlos(grid2view(moves.target)) - && moves.target != you.pos() ) + if (show_beam && have_beam) { // Draw the new ray with magenta '*'s, not including // your square or the target square. @@ -1756,9 +1722,7 @@ void direction(dist& moves, targetting_type restricts, { if (raycopy.pos() != you.pos()) { - // Sanity: don't loop forever if the ray is problematic - if (!in_los(raycopy.pos())) - break; + ASSERT(in_los(raycopy.pos())); const bool in_range = (range < 0) || grid_distance(raycopy.pos(), you.pos()) <= range; @@ -2019,8 +1983,8 @@ static bool _mons_is_valid_target(const monsters *mon, int mode, int range) } #ifndef USE_TILE -static bool _find_mlist( const coord_def& where, int idx, bool need_path, - int range = -1) +static bool _find_mlist(const coord_def& where, int idx, bool need_path, + int range = -1) { if (static_cast(mlist.size()) <= idx) return (false); diff --git a/crawl-ref/source/enum.h b/crawl-ref/source/enum.h index fccb77c580..9db5a63bbd 100644 --- a/crawl-ref/source/enum.h +++ b/crawl-ref/source/enum.h @@ -661,7 +661,7 @@ enum command_type CMD_TARGET_CYCLE_MLIST = 2000, // for indices a-z in the monster list CMD_TARGET_CYCLE_MLIST_END = 2025, CMD_TARGET_TOGGLE_MLIST, - CMD_TARGET_HIDE_BEAM, + CMD_TARGET_TOGGLE_BEAM, CMD_TARGET_CENTER, CMD_TARGET_CANCEL, CMD_TARGET_SHOW_PROMPT, diff --git a/crawl-ref/source/los.cc b/crawl-ref/source/los.cc index bc148d057f..2fc20bdb10 100644 --- a/crawl-ref/source/los.cc +++ b/crawl-ref/source/los.cc @@ -660,10 +660,7 @@ bool find_ray(const coord_def& source, const coord_def& target, bool find_best, bool ignore_solid) { if (target == source) - { - // XXX: directn expects true, even if the ray is invalid - return true; - } + return false; const int signx = ((target.x - source.x >= 0) ? 1 : -1); const int signy = ((target.y - source.y >= 0) ? 1 : -1); -- cgit v1.2.3-54-g00ecf