Skip to content

Commit

Permalink
Enable auto equip when using the item keys. This version avoids modif…
Browse files Browse the repository at this point in the history
…ying the items structure which is unfortunately used to save the manufacturing recipes as a binary file. We need to replace such binary formats as they are too fragile....
  • Loading branch information
pjbroad committed Mar 27, 2020
1 parent f32c057 commit ca943ea
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 15 deletions.
53 changes: 39 additions & 14 deletions hud_quickbar_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,10 @@ static int display_quickbar_handler(window_info *win)
glBegin(GL_QUADS);
draw_2d_thing(u_start,v_start,u_end,v_end,x_start,y_start,x_end,y_end);
glEnd();


if ((_cur_time - item_list_extra[i].slot_busy_start) < 250)
gray_out(x_start,y_start,item_quickbar_slot_size);

if (item_list[i].cooldown_time > _cur_time)
{
float cooldown = ((float)(item_list[i].cooldown_time - _cur_time)) / ((float)item_list[i].cooldown_rate);
Expand Down Expand Up @@ -666,24 +669,45 @@ void init_quickbar (void)
}


static void quick_use(int use_id)
// try to use or auto equip the item in the slot
static void quick_use(int use_id, size_t *timer)
{
Uint8 quick_use_str[3];
int i;

for(i=0; i<ITEM_NUM_ITEMS; i++){
if(item_list[i].pos==use_id &&
item_list[i].quantity &&
item_list[i].use_with_inventory){
quick_use_str[0]= USE_INVENTORY_ITEM;
quick_use_str[1]= use_id;
quick_use_str[2]= i;
my_tcp_send(my_socket,quick_use_str,2);
used_item_counter_action_use(i);
for(i=0; i<ITEM_NUM_ITEMS; i++)
{
if (item_list[i].pos==use_id)
{
if (item_list[i].quantity)
{
// its a usabale item so try to use it
if (item_list[i].use_with_inventory)
{
quick_use_str[0]= USE_INVENTORY_ITEM;
quick_use_str[1]= use_id;
quick_use_str[2]= i;
my_tcp_send(my_socket,quick_use_str,2);
used_item_counter_action_use(i);
#ifdef NEW_SOUND
item_list[i].action = USE_INVENTORY_ITEM;
item_list[i].action = USE_INVENTORY_ITEM;
#endif // NEW_SOUND
break;
}
// this else catches all other item types, but is not used if we have recenly use the slot
// if the item type is not equipable, the server will tell us like it normally does
else if (!item_swap_in_progress(i) && ((SDL_GetTicks() - *timer) > 500))
{
*timer = SDL_GetTicks();
try_auto_equip(i);
}
// the slot will shown as busy for sort while
else
{
item_list_extra[i].slot_busy_start = SDL_GetTicks();
do_alert1_sound();
}
}
return;
}
}
}
Expand All @@ -695,10 +719,11 @@ int action_item_keys(SDL_Keycode key_code, Uint16 key_mod)
size_t i;
el_key_def keys[] = {K_ITEM1, K_ITEM2, K_ITEM3, K_ITEM4, K_ITEM5, K_ITEM6,
K_ITEM7, K_ITEM8, K_ITEM9, K_ITEM10, K_ITEM11, K_ITEM12 };
static size_t timers[sizeof(keys)/sizeof(el_key_def)] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
for (i=0; i<sizeof(keys)/sizeof(el_key_def); i++)
if(KEY_DEF_CMP(keys[i], key_code, key_mod))
{
quick_use (i);
quick_use (i, &timers[i]);
return 1;
}
return 0;
Expand Down
5 changes: 4 additions & 1 deletion items.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "spells.h"

item item_list[ITEM_NUM_ITEMS];
item_extra item_list_extra[ITEM_NUM_ITEMS];

struct quantities quantities = {
0,
Expand Down Expand Up @@ -311,6 +312,7 @@ void get_your_items (const Uint8 *data)
//clear the items first
for(i=0;i<ITEM_NUM_ITEMS;i++){
item_list[i].quantity=0;
item_list_extra[i].slot_busy_start = 0;
}

for(i=0;i<total_items;i++){
Expand Down Expand Up @@ -649,7 +651,8 @@ static int display_items_handler(window_info *win)
y_end = y_start + items_grid.height - 1;
draw_item(item_list[i].image_id, x_start, y_start, items_grid.width - 1);
}

if ((_cur_time - item_list_extra[i].slot_busy_start) < 250)
gray_out(x_start, y_start, items_grid.width);

if (item_list[i].cooldown_time > _cur_time)
{
Expand Down
11 changes: 11 additions & 0 deletions items.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ typedef struct
Uint32 cooldown_rate; /*!< time that the item would need to cool down from full heat */
} item;

/*!
* Extra features for items.
* We can't change the item struct as it used to read/write the manufacture pipeline file.
* Until that is changed, put other stuff here.
*/
typedef struct
{
Uint32 slot_busy_start;
} item_extra;

/*!
* \name Item definition flags
*/
Expand Down Expand Up @@ -77,6 +87,7 @@ struct quantities {
/*! @{ */
extern struct quantities quantities; /*!< Quantities displayed in the items window*/
extern item item_list[ITEM_NUM_ITEMS]; /*!< global list of items */
extern item_extra item_list_extra[ITEM_NUM_ITEMS]; /*!< global list of items extra properties - use with care this is temporary */
extern int item_dragged; /*!< the position of any currently dragged item, or -1 */
extern int item_quantity; /*!< the number of items for and any currently dragged item */
extern int use_item; /*!< the position of any current items used */
Expand Down

0 comments on commit ca943ea

Please sign in to comment.