Skip to content

Commit

Permalink
Issue #199. Move to attacked creature if too far away.
Browse files Browse the repository at this point in the history
Option on Controls tab.  If moving, the tile is highlighted.
  • Loading branch information
pjbroad committed Oct 17, 2024
1 parent 4724318 commit ebbffac
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions elconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions gamewin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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;
}
Expand Down
13 changes: 13 additions & 0 deletions gamewin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
5 changes: 5 additions & 0 deletions text.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ebbffac

Please sign in to comment.