From 6f2a50cffaccd8af991a513f2453506ade0cf140 Mon Sep 17 00:00:00 2001 From: haranp Date: Sat, 4 Oct 2008 17:47:41 +0000 Subject: Changed '!' in targeting from target-select to target-select-ignoring-range. Added '@', which is to '!' as '.' is to the old '5'. Fixed 2146628: cancelling targeting was incorrectly checking range. The behaviour of allow_self_target is now slightly different (see forthcoming mail on crawl-ref-discuss.) git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7128 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/cmd-keys.h | 3 +- crawl-ref/source/cmd-name.h | 2 + crawl-ref/source/directn.cc | 129 ++++++++++++++++++++++++++++--------------- crawl-ref/source/enum.h | 2 + crawl-ref/source/initfile.cc | 2 +- 5 files changed, 92 insertions(+), 46 deletions(-) diff --git a/crawl-ref/source/cmd-keys.h b/crawl-ref/source/cmd-keys.h index 5fe8909a75..2cffddfe32 100644 --- a/crawl-ref/source/cmd-keys.h +++ b/crawl-ref/source/cmd-keys.h @@ -147,7 +147,8 @@ {CONTROL('P'), CMD_TARGET_SHOW_PROMPT}, {CONTROL('C'), CMD_TARGET_CYCLE_BEAM}, {':', CMD_TARGET_HIDE_BEAM}, -{'!', CMD_TARGET_SELECT}, +{'!', CMD_TARGET_SELECT_FORCE}, +{'@', CMD_TARGET_SELECT_FORCE_ENDPOINT}, {'\r', CMD_TARGET_SELECT}, {'5', CMD_TARGET_SELECT}, {'.', CMD_TARGET_SELECT_ENDPOINT}, diff --git a/crawl-ref/source/cmd-name.h b/crawl-ref/source/cmd-name.h index 5cae13caff..af588cd2a9 100644 --- a/crawl-ref/source/cmd-name.h +++ b/crawl-ref/source/cmd-name.h @@ -161,6 +161,8 @@ {CMD_TARGET_MAYBE_PREV_TARGET, "CMD_TARGET_MAYBE_PREV_TARGET"}, {CMD_TARGET_SELECT, "CMD_TARGET_SELECT"}, {CMD_TARGET_SELECT_ENDPOINT, "CMD_TARGET_SELECT_ENDPOINT"}, +{CMD_TARGET_SELECT_FORCE, "CMD_TARGET_SELECT_FORCE"}, +{CMD_TARGET_SELECT_FORCE_ENDPOINT, "CMD_TARGET_SELECT_FORCE_ENDPOINT"}, {CMD_TARGET_OBJ_CYCLE_BACK, "CMD_TARGET_OBJ_CYCLE_BACK"}, {CMD_TARGET_OBJ_CYCLE_FORWARD, "CMD_TARGET_OBJ_CYCLE_FORWARD"}, {CMD_TARGET_CYCLE_FORWARD, "CMD_TARGET_CYCLE_FORWARD"}, diff --git a/crawl-ref/source/directn.cc b/crawl-ref/source/directn.cc index 5f582fc35a..6f3429bab5 100644 --- a/crawl-ref/source/directn.cc +++ b/crawl-ref/source/directn.cc @@ -341,6 +341,8 @@ static void _direction_again(dist& moves, targeting_type restricts, if (key_command == CMD_TARGET_PREV_TARGET || key_command == CMD_TARGET_SELECT_ENDPOINT || key_command == CMD_TARGET_SELECT + || key_command == CMD_TARGET_SELECT_FORCE_ENDPOINT + || key_command == CMD_TARGET_SELECT_FORCE || key_command == CMD_TARGET_MAYBE_PREV_TARGET) { break; @@ -356,8 +358,11 @@ static void _direction_again(dist& moves, targeting_type restricts, return; } - if (key_command == CMD_TARGET_SELECT_ENDPOINT) + if (key_command == CMD_TARGET_SELECT_ENDPOINT + || key_command == CMD_TARGET_SELECT_FORCE_ENDPOINT) + { moves.isEndpoint = true; + } if (you.prev_grd_targ != coord_def(0, 0)) { @@ -739,6 +744,62 @@ private: FixedArray orig_colours; }; +bool _dist_ok(const dist& moves, int range, targ_mode_type mode, + bool may_target_self, bool cancel_at_self) +{ + if (!moves.isCancel && moves.isTarget) + { + if (!see_grid(moves.target)) + { + mpr("Sorry, you can't target what you can't see.", + MSGCH_EXAMINE_FILTER); + return (false); + } + + if (moves.target == you.pos()) + { + // may_target_self == makes (some) sense to target yourself + // (SPFLAG_AREA) + + // cancel_at_self == not allowed to target yourself + // (SPFLAG_NOT_SELF) + + if (cancel_at_self) + { + mpr("Sorry, you can't target yourself.", MSGCH_EXAMINE_FILTER); + return (false); + } + + if (!may_target_self && mode == TARG_ENEMY) + { + if (Options.allow_self_target == CONFIRM_CANCEL) + { + mpr("That would be overly suicidal.", MSGCH_EXAMINE_FILTER); + return (false); + } + else if (Options.allow_self_target == CONFIRM_PROMPT) + { + return yesno("Really target yourself?", false, 'n'); + } + } + } + + // Check range + if (range >= 0 && grid_distance(moves.target, you.pos()) > range) + { + mpr("That is beyond the maximum range.", MSGCH_EXAMINE_FILTER); + return (false); + } + } + + // Some odd cases + if (!moves.isValid && !moves.isCancel) + return yesno("Are you sure you want to fizzle?", false, 'n'); + + return (true); +} + + void direction(dist& moves, targeting_type restricts, targ_mode_type mode, int range, bool just_looking, bool needs_path, bool may_target_monster, @@ -829,6 +890,8 @@ void direction(dist& moves, targeting_type restricts, while (true) { + bool allow_out_of_range = false; + // Prompts might get scrolled off if you have too few lines available. // We'll live with that. if ( !just_looking && (show_prompt || beh->should_redraw()) ) @@ -1118,8 +1181,20 @@ void direction(dist& moves, targeting_type restricts, break; } + // some modifiers to the basic selection command + case CMD_TARGET_SELECT_FORCE: case CMD_TARGET_SELECT_ENDPOINT: - moves.isEndpoint = true; + case CMD_TARGET_SELECT_FORCE_ENDPOINT: + if (key_command == CMD_TARGET_SELECT_ENDPOINT + || key_command == CMD_TARGET_SELECT_FORCE_ENDPOINT) + { + moves.isEndpoint = true; + } + if (key_command == CMD_TARGET_SELECT_FORCE + || key_command == CMD_TARGET_SELECT_FORCE_ENDPOINT) + { + allow_out_of_range = true; + } // intentional fall-through case CMD_TARGET_SELECT: // finalize current choice if (!moves.isEndpoint @@ -1318,51 +1393,14 @@ void direction(dist& moves, targeting_type restricts, if (loop_done == true) { - // This is where we either finalize everything, or else - // decide that we're not really done and continue looping. + // Confirm that the loop is really done. If it is, + // break out. If not, just continue looping. if (just_looking) // easy out break; - // A bunch of confirmation tests; if we survive them all, - // then break out. - - // Confirm self-targeting on TARG_ENEMY (option-controlled.) - // Conceivably we might want to confirm on TARG_ANY too. - if (moves.isTarget - && moves.target == you.pos() - && mode == TARG_ENEMY - && (cancel_at_self - || Options.allow_self_target == CONFIRM_CANCEL - && !may_target_self - || (Options.allow_self_target == CONFIRM_PROMPT - || Options.allow_self_target == CONFIRM_CANCEL - && may_target_self) - && !yesno("Really target yourself?", false, 'n'))) - { - if (cancel_at_self) - mpr("Sorry, you can't target yourself."); - else if (Options.allow_self_target == CONFIRM_CANCEL - && !may_target_self) - { - mpr("That would be overly suicidal.", MSGCH_EXAMINE_FILTER); - } - - show_prompt = true; - } - else if (moves.isTarget && !see_grid(moves.target)) - { - mpr("Sorry, you can't target what you can't see.", - MSGCH_EXAMINE_FILTER); - } - else if (range >= 0 - && grid_distance(moves.target, you.pos()) > range) - { - mpr("That is beyond the maximum range.", MSGCH_EXAMINE_FILTER); - } - // Ask for confirmation if we're quitting for some odd reason. - else if (moves.isValid || moves.isCancel - || yesno("Are you sure you want to fizzle?", false, 'n')) + if (_dist_ok(moves, allow_out_of_range ? -1 : range, + mode, may_target_self, cancel_at_self)) { // Finalize whatever is inside the loop // (moves-internal finalizations can be done later). @@ -1370,10 +1408,13 @@ void direction(dist& moves, targeting_type restricts, moves.ray = ray; break; } + else + { + show_prompt = true; + } } // We'll go on looping. Redraw whatever is necessary. - if ( !in_viewport_bounds(grid2view(moves.target)) ) { // Tried to step out of bounds diff --git a/crawl-ref/source/enum.h b/crawl-ref/source/enum.h index 64c48819e6..f68fd730de 100644 --- a/crawl-ref/source/enum.h +++ b/crawl-ref/source/enum.h @@ -578,6 +578,8 @@ enum command_type CMD_TARGET_MAYBE_PREV_TARGET, CMD_TARGET_SELECT, CMD_TARGET_SELECT_ENDPOINT, + CMD_TARGET_SELECT_FORCE, + CMD_TARGET_SELECT_FORCE_ENDPOINT, CMD_TARGET_OBJ_CYCLE_BACK, CMD_TARGET_OBJ_CYCLE_FORWARD, CMD_TARGET_CYCLE_FORWARD, diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc index 12b3f47370..4dfaf1ac3e 100644 --- a/crawl-ref/source/initfile.cc +++ b/crawl-ref/source/initfile.cc @@ -2036,7 +2036,6 @@ void game_options::read_option_line(const std::string &str, bool runscript) else if (field == "safe") easy_confirm = CONFIRM_SAFE_EASY; } - else BOOL_OPTION(easy_quit_item_prompts); else if (key == "allow_self_target") { if (field == "yes") @@ -2046,6 +2045,7 @@ void game_options::read_option_line(const std::string &str, bool runscript) else if (field == "prompt") allow_self_target = CONFIRM_PROMPT; } + else BOOL_OPTION(easy_quit_item_prompts); else BOOL_OPTION_NAMED("easy_quit_item_lists", easy_quit_item_prompts); else BOOL_OPTION(easy_open); else BOOL_OPTION(easy_unequip); -- cgit v1.2.3-54-g00ecf