From b6c07346e3f3f24607c4f4a3a9b3659e6effd36e Mon Sep 17 00:00:00 2001 From: Paul Broadhead Date: Sun, 3 Dec 2017 16:15:59 +0000 Subject: [PATCH] Added options from the Android client to attack a creature if you click close to one, and to open a ground bag if you click close to one. Both options are enabled by default. --- actors.c | 35 +++++++++++++++++++++++++++++++++++ actors.h | 14 ++++++++++++++ bags.c | 33 +++++++++++++++++++++++++++++++++ bags.h | 14 ++++++++++++++ elconfig.c | 2 ++ gamewin.c | 32 ++++++++++++++++++++++++++++++++ gamewin.h | 2 ++ 7 files changed, 132 insertions(+) diff --git a/actors.c b/actors.c index 1cd28f7bb..6edf4f89b 100644 --- a/actors.c +++ b/actors.c @@ -64,6 +64,41 @@ Uint32 have_actors_lock = 0; int cm_mouse_over_banner = 0; /* use to trigger banner context menu */ +int get_closest_actor(int tile_x, int tile_y, float max_distance) +{ + int i; + int found_actor = -1; + float x=tile_x / 2.0f; + float y=tile_y / 2.0f; + float distance; + float min_distance_found = 50; + + // check if too far + actor *me = get_our_actor(); + if (me) + { + distance = sqrt((me->x_pos - x) * (me->x_pos - x) + (me->y_pos - y) * (me->y_pos - y)); + if (distance > 6) + return -1; + } + + for (i=0; idead) + if (actors_list[i]->kind_of_actor != NPC && actors_list[i]->kind_of_actor != HUMAN && actors_list[i]->kind_of_actor != COMPUTER_CONTROLLED_HUMAN) + { + distance = sqrt((actors_list[i]->x_pos - x) * (actors_list[i]->x_pos - x) + (actors_list[i]->y_pos - y ) * (actors_list[i]->y_pos - y)); + if (distance < max_distance) + if (distance < min_distance_found) + { + found_actor = actors_list[i]->actor_id; + min_distance_found = distance; + } + } + + return found_actor; +} + //Threading support for actors_lists void init_actors_lists() { diff --git a/actors.h b/actors.h index 0036d3031..9dd38fa07 100644 --- a/actors.h +++ b/actors.h @@ -795,6 +795,20 @@ void end_actors_lists(void); int on_the_move (const actor *act); +/*! + * \ingroup display_actors + * \brief Return actor close clicked coords. + * + * \param tile_x the x coord of the clicked tile + * \param tile_y the y coord of the clicked tile + * \param max_distance the maximum distance between the clicked coord and the actor + * + * \callgraph + * \retval the actor id or -1 for no actor + * + */ +int get_closest_actor(int tile_x, int tile_y, float max_distance); + /*! * \ingroup display_actors * \brief Return a pointer to your own character, if available diff --git a/bags.c b/bags.c index a1dc7e157..9250c8c30 100644 --- a/bags.c +++ b/bags.c @@ -336,6 +336,39 @@ static int clear_groundlist(void) return 1; } +int find_and_open_closest_bag(int tile_x, int tile_y, float max_distance) +{ + int i; + int found_bag = -1; + float x = tile_x; + float y = tile_y; + + float distance; + float min_distance_found = 50; + + for(i=0; i= tile_map_size_x*6 || y >= tile_map_size_y*6) return 1; + + if (attack_close_clicked_creature) + { + int closest_actor = get_closest_actor(x, y, 0.8f); + if (closest_actor != -1) + { + actor *this_actor = NULL; + + if (you_sit && sit_lock && !flag_ctrl) + { + if(your_actor != NULL) + add_highlight(your_actor->x_tile_pos, your_actor->y_tile_pos, HIGHLIGHT_TYPE_LOCK); + return 1; + } + + this_actor = get_actor_ptr_from_id(closest_actor); + if (this_actor != NULL) + { + Uint8 str[10]; + add_highlight(this_actor->x_tile_pos, this_actor->y_tile_pos, HIGHLIGHT_TYPE_ATTACK_TARGET); + str[0] = ATTACK_SOMEONE; + *((int *)(str+1)) = SDL_SwapLE32((int)closest_actor); + my_tcp_send (my_socket, str, 5); + return 1; + } + } + } + + if (open_close_clicked_bag && find_and_open_closest_bag(x, y, 0.8f)) + return 1; add_highlight(x, y, HIGHLIGHT_TYPE_WALKING_DESTINATION); diff --git a/gamewin.h b/gamewin.h index c79870f91..e4cf409b5 100644 --- a/gamewin.h +++ b/gamewin.h @@ -31,6 +31,8 @@ extern int use_old_clicker; extern int include_use_cursor_on_animals; extern int cm_banner_disabled; extern int auto_disable_ranging_lock; +extern int attack_close_clicked_creature; +extern int open_close_clicked_bag; /*! @} */ /*!