From 4380580174b8e6b478bc142f368ea1c1caa70f98 Mon Sep 17 00:00:00 2001 From: ennewalker Date: Sat, 4 Oct 2008 00:45:30 +0000 Subject: Mouse clicks on the dungeon when not safe now travel one square in that direction, rather than only allowing clicks one square away from the character. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7115 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/tilereg.cc | 54 ++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 18 deletions(-) (limited to 'crawl-ref/source/tilereg.cc') diff --git a/crawl-ref/source/tilereg.cc b/crawl-ref/source/tilereg.cc index d50b4459e4..661d721992 100644 --- a/crawl-ref/source/tilereg.cc +++ b/crawl-ref/source/tilereg.cc @@ -781,6 +781,25 @@ void DungeonRegion::on_resize() // TODO enne } +static int _adjacent_cmd(const coord_def &gc, const MouseEvent &event) +{ + coord_def dir = gc - you.pos(); + for (int i = 0; i < 9; i++) + { + if (dir_dx[i] != dir.x || dir_dy[i] != dir.y) + continue; + + if (event.mod & MOD_SHIFT) + return cmd_shift[i]; + else if (event.mod & MOD_CTRL) + return cmd_ctrl[i]; + else + return cmd_normal[i]; + } + + return 0; +} + int DungeonRegion::handle_mouse(MouseEvent &event) { tiles.clear_text_tags(TAG_CELL_DESC); @@ -873,29 +892,28 @@ int DungeonRegion::handle_mouse(MouseEvent &event) if (event.button != MouseEvent::LEFT) return 0; - // If adjacent, return that key (modified by shift or ctrl, etc...) - coord_def dir = gc - you.pos(); - for (unsigned int i = 0; i < 9; i++) + if (!in_bounds(gc)) + return 0; + + int cmd = _adjacent_cmd(gc, event); + if (cmd) + return cmd; + + if (i_feel_safe()) { - if (dir_dx[i] == dir.x && dir_dy[i] == dir.y) - { - if (event.mod & MOD_SHIFT) - return cmd_shift[i]; - else if (event.mod & MOD_CTRL) - return cmd_ctrl[i]; - else - return cmd_normal[i]; - } + start_travel(gc); + return CK_MOUSE_CMD; } - // Otherwise, travel to that grid. - if (!in_bounds(gc)) - return 0; + // If not safe, then take one step towards the click. + travel_pathfind tp; + tp.set_src_dst(you.pos(), gc); + const coord_def dest = tp.pathfind(RMODE_TRAVEL); - // Activate travel. - start_travel(gc); + if (!dest.x && !dest.y) + return 0; - return CK_MOUSE_CMD; + return _adjacent_cmd(dest, event); } void DungeonRegion::to_screen_coords(const coord_def &gc, coord_def &pc) const -- cgit v1.2.3-54-g00ecf