Skip to content

Commit

Permalink
Added options from the Android client to attack a creature if you cli…
Browse files Browse the repository at this point in the history
…ck close to one, and to open a ground bag if you click close to one. Both options are enabled by default.
  • Loading branch information
pjbroad committed Dec 3, 2017
1 parent 2a392ef commit b6c0734
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 0 deletions.
35 changes: 35 additions & 0 deletions actors.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; i<max_actors; i++)
if (actors_list[i])
if (!actors_list[i]->dead)
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()
{
Expand Down
14 changes: 14 additions & 0 deletions actors.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions bags.c
Original file line number Diff line number Diff line change
Expand Up @@ -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<NUM_BAGS; i++)
if(bag_list[i].obj_3d_id != -1)
{
distance = sqrt(((float)bag_list[i].x - x) * ((float)bag_list[i].x - x) + ((float)bag_list[i].y - y) * ((float)bag_list[i].y - y));
if (distance < max_distance)
if (distance < min_distance_found)
{
found_bag = i;
min_distance_found = distance;
}
}

if (found_bag != -1)
{
Uint8 str[4];
str[0]= INSPECT_BAG;
str[1]= found_bag;
my_tcp_send(my_socket,str, 2);
return 1;
}

return 0;
}

void open_bag(int object_id)
{
Expand Down
14 changes: 14 additions & 0 deletions bags.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,20 @@ void items_get_bag(int x, int y);
*/
void strap_word(char * in, char * out);

/*!
* \ingroup item
* \brief Open close clicked bag .
*
* \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 bag
*
* \callgraph
* \retval int 0 for off, non-zero on
*
*/
int find_and_open_closest_bag(int tile_x, int tile_y, float max_distance);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
2 changes: 2 additions & 0 deletions elconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -1998,6 +1998,8 @@ static void init_ELC_vars(void)
// CONTROLS TAB
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,"attack_close_clicked_creature", "attackcloseclickedcreature", &attack_close_clicked_creature, change_var, 1, "Attack creature if you click close to it", "When enabled, if you click close to a creature that is in range, you will attack it.", 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,"use_floating_messages", "floating", &floatingmessages_enabled, change_var, 1, "Floating Messages", "Toggles the use of floating experience messages and other graphical enhancements", CONTROLS);
add_var(OPT_BOOL,"floating_session_counters", "floatingsessioncounters", &floating_session_counters, change_var, 0, "Floating Session Counters", "Toggles the display of floating session counters. Configure each type using the context menu of the counter category.", CONTROLS);
add_var(OPT_BOOL,"use_keypress_dialog_boxes", "keypressdialogues", &use_keypress_dialogue_boxes, change_var, 0, "Keypresses in dialogue boxes", "Toggles the ability to press a key to select a menu option in dialogue boxes (eg The Wraith)", CONTROLS);
Expand Down
32 changes: 32 additions & 0 deletions gamewin.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ int use_old_clicker=0;
int include_use_cursor_on_animals = 0;
int cm_banner_disabled = 0;
int auto_disable_ranging_lock = 1;
int attack_close_clicked_creature = 1;
int open_close_clicked_bag = 1;

#ifdef DEBUG
extern int e3d_count, e3d_total; // LRNR:stats testing only
Expand Down Expand Up @@ -942,6 +944,36 @@ static int click_game_handler(window_info *win, int mx, int my, Uint32 flags)
// check to see if the coordinates are OUTSIDE the map
if (y < 0 || x < 0 || x >= 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);

Expand Down
2 changes: 2 additions & 0 deletions gamewin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/*! @} */

/*!
Expand Down

0 comments on commit b6c0734

Please sign in to comment.