From ebbffaced8e4c04ee536301c1ee379652f8338db Mon Sep 17 00:00:00 2001 From: Paul Broadhead Date: Thu, 17 Oct 2024 19:30:26 +0100 Subject: [PATCH] Issue #199. Move to attacked creature if too far away. Option on Controls tab. If moving, the tile is highlighted. --- elconfig.c | 1 + gamewin.c | 26 ++++++++++++++++++++++++++ gamewin.h | 13 +++++++++++++ text.c | 5 +++++ 4 files changed, 45 insertions(+) diff --git a/elconfig.c b/elconfig.c index a8f309556..50c43a789 100755 --- a/elconfig.c +++ b/elconfig.c @@ -2923,6 +2923,7 @@ static void init_ELC_vars(void) add_var(OPT_BOOL,"sit_lock","sl",&sit_lock,change_var,0,"Sit Lock","Enable this to prevent your character from moving by accident when you are sitting.",CONTROLS); add_var(OPT_BOOL,"always_pathfinding", "alwayspathfinding", &always_pathfinding, change_var, 0, "Extend the range of the walk cursor", "Extends the range of the walk cursor to as far as you can see. Using this option, movement may be slightly less responsive on larger maps.", CONTROLS); add_var(OPT_BOOL,"target_close_clicked_creature", "targetcloseclickedcreature", &target_close_clicked_creature, change_var, 1, "Target creature if you click close to it", "When enabled, if you click close to a creature that is in range, you will attack it or select it as the target for an active spell.", CONTROLS); + add_var(OPT_BOOL,"move_to_attacked", "movetoattacked", &move_to_attacked_far_away_creature, change_var, 1, "Move to attacked creature if too far away", "If you attack a creature that is too far away, you will move to the clicked location instead.", CONTROLS); add_var(OPT_BOOL,"open_close_clicked_bag", "openupcloseclickedbag", &open_close_clicked_bag, change_var, 1, "Open a bag if you click close to it", "When enabled, if you click close to a bag that is in range, you will open it.", CONTROLS); add_var(OPT_BOOL, "pf_search_destination_area", "pfsearchdest", &pf_search_destination_area, change_var, 1, "Less strict pathfinding", "When enabled, the pathfinder will search for a reachable spot in the immediate area of the destination when an unwalkable spot is clicked. This option requires \"Extend the range of the walk cursor\" to be enabled.", CONTROLS); diff --git a/gamewin.c b/gamewin.c index 9475802c2..ca11712da 100644 --- a/gamewin.c +++ b/gamewin.c @@ -69,6 +69,7 @@ int include_use_cursor_on_animals = 0; int cm_banner_disabled = 0; int auto_disable_ranging_lock = 1; int target_close_clicked_creature = 1; +int move_to_attacked_far_away_creature = 1; int open_close_clicked_bag = 1; int show_fps = 0; @@ -87,6 +88,8 @@ static int fps_center_x = 0; static int fps_default_width = 0; static int action_mode = ACTION_WALK; static int last_action_mode = ACTION_WALK; +static short last_attack_actor_coord_x = -1; +static short last_attack_actor_coord_y = 1; // Set the game root window action mode void set_gamewin_action_mode(int new_mode) @@ -270,6 +273,25 @@ static void toggle_target_close_clicked_creature(void) LOG_TO_CONSOLE(c_green1, close_click_targetting_off_str); } +// +// Called when we see the "You are too far away! Get closer!" message. +// Using the tile coordinates of the creature last attacked, move +// to the location and highlight the spot. If we don't move, the message +// will get displayed. +// +int check_move_to_attacked(void) +{ + if (move_to_attacked_far_away_creature && (last_attack_actor_coord_x >= 0) && (last_attack_actor_coord_y >= 0)) + { + move_to(&last_attack_actor_coord_x, &last_attack_actor_coord_y, 1); + add_highlight(last_attack_actor_coord_x, last_attack_actor_coord_y, HIGHLIGHT_SOFT_FAIL); + last_attack_actor_coord_x = last_attack_actor_coord_y = -1; + return 1; + } + else + return 0; +} + void draw_special_cursors(void) { const float RET_WID = 4.0f; @@ -1103,6 +1125,8 @@ static int click_game_handler(window_info *win, int mx, int my, Uint32 flags) { add_highlight(this_actor->x_tile_pos,this_actor->y_tile_pos, HIGHLIGHT_TYPE_ATTACK_TARGET); + last_attack_actor_coord_x = (short)this_actor->x_tile_pos; + last_attack_actor_coord_y = (short)this_actor->y_tile_pos; release_locked_actors_list_and_invalidate(actors_list, &me); } } @@ -1246,6 +1270,8 @@ static int click_game_handler(window_info *win, int mx, int my, Uint32 flags) else if (!is_ranging_locked && !is_sit_locked) { add_highlight(x, y, HIGHLIGHT_TYPE_ATTACK_TARGET); + last_attack_actor_coord_x = (short)x; + last_attack_actor_coord_y = (short)y; attack_someone(actor_id); return 1; } diff --git a/gamewin.h b/gamewin.h index 0060f75f0..b64f39897 100644 --- a/gamewin.h +++ b/gamewin.h @@ -44,10 +44,23 @@ extern int include_use_cursor_on_animals; extern int cm_banner_disabled; extern int auto_disable_ranging_lock; extern int target_close_clicked_creature; +extern int move_to_attacked_far_away_creature; extern int open_close_clicked_bag; extern int show_fps; /*!< flag that indicates whether to display FPS or not */ /*! @} */ +/*! + * \brief Return true if moving to the attacked creature. + * + * If we have the coordinates of the last clicked + * creature, and the option is enabled, move there + * and highlight the spot. + * + * \callgraph + * \retval int 0 not moving, 1 for moving + */ +int check_move_to_attacked(void); + /*! * \brief Return the true if the ranging lock is on. * diff --git a/text.c b/text.c index 2c914f8fc..1fbc79acc 100644 --- a/text.c +++ b/text.c @@ -14,6 +14,7 @@ #include "elconfig.h" #include "errors.h" #include "filter.h" +#include "gamewin.h" #include "gl_init.h" #include "hud_misc_window.h" #include "highlight.h" @@ -690,6 +691,10 @@ int filter_or_ignore_text (char *text_to_add, int len, int size, Uint8 channel) else if (!strncasecmp(text_to_add+1, "Your buddy list is now empty.", 29)) { clear_buddy(); } + else if (!strncasecmp(text_to_add+1, "You are too far away! Get closer!", 33)) { + if (check_move_to_attacked()) + return 0; + } else { int match_index; for (match_index = 0; match_index < rate_limit_count; ++match_index)