1 /*!
2  * \file
3  * \ingroup item
4  * \brief Item handling and storing
5  */
6 #ifndef __ITEMS_H__
7 #define __ITEMS_H__
8 
9 #include "platform.h"
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 /*!
16  * Any item in EL has assigned an item struct
17  */
18 typedef struct
19 {
20 	Uint16 id; /*!< server id of this item */
21 	int image_id; /*!< id of the image for this item */
22 	int pos;
23 	int quantity;
24 	int is_reagent; /*!< can be used for spells? */
25 	int is_resource; /*!< does it appear on the manufacturing menu? */
26 	int use_with_inventory;
27 	int is_stackable;
28 #ifdef NEW_SOUND
29 	int action;			/*!< action being done on this item, for playing sounds on server result */
30 	int action_time;	/*!< time this action has been active - times out after 2 seconds */
31 #endif // NEW_SOUND
32 	Uint32 cooldown_time; /*!< time when cooldown shall reach zero */
33 	Uint32 cooldown_rate; /*!< time that the item would need to cool down from full heat */
34 } item;
35 
36 /*!
37  * Extra features for items.
38  * We can't change the item struct as it used to read/write the manufacture pipeline file.
39  * Until that is changed, put other stuff here.
40  */
41 typedef struct
42 {
43 	Uint32 slot_busy_start;
44 } item_extra;
45 
46 /*!
47  * \name Item definition flags
48  */
49 /*! @{ */
50 typedef enum {
51 	ITEM_REAGENT           = 1, /*!< can be used in magic */
52 	ITEM_RESOURCE          = 2, /*!< can be used to manufacture */
53 	ITEM_STACKABLE         = 4, /*!< the item is stackable */
54 	ITEM_INVENTORY_USABLE  = 8, /*!< item can be used with inventory */
55 	ITEM_TILE_USABLE       = 16,
56 	ITEM_PLAYER_USABLE     = 32, /*!< item is usable by players */
57 	ITEM_OBJECT_USABLE     = 64,
58 	ITEM_ON_OFF            = 128,
59 } item_definition_flags;
60 /*! @} */
61 
62 /*!
63  * \name Item constants
64  */
65 /*! @{ */
66 #define	ITEM_WEAR_START	36
67 #define	ITEM_NUM_WEAR	8
68 #define	ITEM_NUM_ITEMS	(ITEM_WEAR_START+ITEM_NUM_WEAR)
69 #define ITEM_NO_ACTION -1
70 #define ITEM_EDIT_QUANT 6
71 /*! @} */
72 
73 /*!
74  * \name The quantities are located within this struct
75 */
76 struct quantities {
77 	int selected;
78 	struct tmp {
79 		int val;
80 		int len;
81 		char str[10];
82 	} quantity[ITEM_EDIT_QUANT+1];
83 };
84 
85 /*! \name item relates vars used globally */
86 /*! @{ */
87 extern struct quantities quantities; 		/*!< Quantities displayed in the items window*/
88 extern item item_list[ITEM_NUM_ITEMS]; 		/*!< global list of items */
89 extern item_extra item_list_extra[ITEM_NUM_ITEMS]; /*!< global list of items extra properties - use with care this is temporary */
90 extern int item_dragged;					/*!< the position of any currently dragged item, or -1 */
91 extern int item_quantity;					/*!< the number of items for and any currently dragged item */
92 extern int use_item;						/*!< the position of any current items used */
93 extern int item_uid_enabled;				/*!< true if item ids are enable */
94 extern const Uint16 unset_item_uid;			/*!< a value to compare with an itemd id to check if its set */
95 extern int independant_inventory_action_modes; /*!< use independant action modes for inventory window */
96 
97 /*! @} */
98 
99 /*! \name Text fields for items */
100 /*! @{ */
101 #define MAX_ITEMS_TEXTURES  32
102 extern int items_text[MAX_ITEMS_TEXTURES];
103 /*! @} */
104 
105 /*! \name Options flags for items, saved in config file */
106 /*! @{ */
107 extern int use_small_items_window;
108 extern int manual_size_items_window;
109 extern int items_mod_click_any_cursor;
110 extern int allow_equip_swap;
111 extern int items_buttons_on_left;
112 extern int items_equip_grid_on_left;
113 extern int items_mix_but_all;
114 extern int items_stoall_nofirstrow;
115 extern int items_stoall_nolastrow;
116 extern int items_dropall_nofirstrow;
117 extern int items_dropall_nolastrow;
118 extern int items_disable_text_block;
119 extern int items_list_on_left;
120 /*! @} */
121 
122 /*!
123  * \ingroup items_window
124  * \brief  Check for out of date item actions.
125  *
126  * \callgraph
127  */
128 #ifdef NEW_SOUND
129 void update_item_sound(int interval);
130 #endif // NEW_SOUND
131 
132 /*!
133  * \ingroup items_window
134  * \brief  Common function between QuickBar and Inventroy to move items.
135  *
136  * The funciton will try to us ethe suggest items slot but look for another
137  * if that is not free. It will also try to find a stack of items to use.
138  *
139  * \param item_pos_to_mov	the position of the item to move
140  * \param destination_pos	the desired destination
141  * \param avoid_pos			if > 0 then avoid this slot for the destinaiton
142  *
143  * \retval int      return true if the move command is sent to the server
144  *
145  * \callgraph
146  */
147 int move_item(int item_pos_to_mov, int destination_pos, int avoid_pos);
148 
149 /*!
150  * \ingroup items_window
151  * \brief  Common function to draw an item image in a grid.
152  *
153  * \callgraph
154  */
155 void draw_item(int id, int x_start, int y_start, int gridsize);
156 
157 /*!
158  * \ingroup items_window
159  * \brief  Common function grey out an item image in a grid.
160  *
161  * \callgraph
162  */
163 void gray_out(int x_start, int y_start, int gridsize);
164 
165 /*!
166  * \ingroup items_window
167  * \brief  The callback timer to impliment the use item counter.
168  *
169  * \callgraph
170  */
171 void used_item_counter_timer(void);
172 
173 /*!
174  * \ingroup items_window
175  * \brief  Common function between QuickBar and Inventroy to enable counting item use.
176  *
177  * \param item_pos   the position in the items array, to check
178  *
179  * \callgraph
180  */
181 void used_item_counter_action_use(int pos);
182 
183 /*!
184  * \ingroup items_window
185  * \brief  Common function between QuickBar and Inventroy to auto equip/swap items.
186  *
187  * \callgraph
188  */
189 void try_auto_equip(int from_item);
190 
191 /*!
192  * \ingroup items_window
193  * \brief  Common function between QuickBar and Inventroy to complete item swap.
194  *
195  * \callgraph
196  */
197 void check_for_swap_completion(void);
198 
199 /*!
200  * \ingroup items_window
201  * \brief  Common function between QuickBar and Inventroy to check if swapping so can hide moves.
202  *
203  * \param item_pos   the position in the items array, to check
204  *
205  * \retval int      return true if swap of this item is in progress
206   *
207 * \callgraph
208  */
209 int item_swap_in_progress(int item_pos);
210 
211 /*!
212  * \ingroup display_utils
213  * \brief   Renders the storage grid
214  *
215  *      Renders a storage grid with up to \a columns columns and \a rows rows. The parameters \a left and \a top indicate the starting position and \a width and \a height indicate the size of the grid window.
216  *
217  * \param columns   number of columns to use for the grid
218  * \param rows      number of rows to use for the grid
219  * \param left      x coordinate of the grid window
220  * \param top       y coordinate of the grid window
221  * \param width     width of the grid window
222  * \param height    height of the grid window
223  */
224 void rendergrid(int columns, int rows, int left, int top, int width, int height);
225 
226 /*!
227  * \ingroup display_utils
228  * \brief   Gets the mouse position within the storage grid window
229  *
230  *      Gets the mouse position within the storage grid window.
231  *
232  * \param mx        x coordinate of the mouse position
233  * \param my        y coordinate of the mouse position
234  * \param columns   number of columns of the grid window
235  * \param rows      number of rows of the grid window
236  * \param left      x coordinate of the grid window
237  * \param top       y coordinate of the grid window
238  * \param width     width of the grid window
239  * \param height    height of the grid window
240  * \retval int      the grid position of the mouse, i.e. the grid number where the mouse cursor currently is, or -1 if the mouse cursor is outside the grid window
241  */
242 int get_mouse_pos_in_grid(int mx, int my, int columns, int rows, int left, int top, int width, int height);
243 
244 /*!
245  * \ingroup item
246  * \brief Gets the textures associated with the item \a no.
247  *
248  *      Returns the texture id associated with the item given by \a no.
249  *
250  * \param no        id of the item
251  * \retval GLuint   the texture id associated with \a no.
252  */
get_items_texture(int no)253 static __inline__ GLuint get_items_texture(int no)
254 {
255 	return items_text[no];
256 }
257 
258 /*!
259  * \ingroup item
260  * \brief   Gets the items for \ref item_list from the parameter \a data.
261  *
262  *      Initializes the \ref item_list from the \a data given. Calls \ref build_manufacture_list after the initializing is done.
263  *
264  * \param data  the data for the \ref item_list
265  *
266  * \callgraph
267  */
268 void get_your_items (const Uint8 *data);
269 
270 /*!
271  * \ingroup item
272  * \brief   Drags the given \a item
273  *
274  *      Drags the given \a item. If \a mini is true, the dragged item will be drawn smaller.
275  *
276  * \param item  the index into array of the item being dragged
277  * \param storage specifies if it's taken from the storage or the inventory items array
278  * \param mini  boolean flag, indicating whether the dragged item will be drawn smaller
279  *
280  * \callgraph
281  */
282 void drag_item(int item, int storage, int mini);
283 
284 /*!
285  * \ingroup item
286  * \brief   Removes the item at the given inventory position \a pos from the items menu.
287  *
288  *      Removes the item at the given inventory position \a pos from the inventory. Calls \ref build_manufacture_list after the item was removed.
289  *
290  * \param pos   the position into the items menu
291  *
292  * \callgraph
293  *
294  */
295 void remove_item_from_inventory(int pos);
296 
297 /*!
298  * \ingroup item
299  * \brief   Gets a new item from the given \a data.
300  *
301  *      Gets a new inventory item from the given \a data. If we already have such an item, only the quantity will get updated. Calls \ref build_manufacture_list after the item has been updated or added.
302  *
303  * \param data  teh data for the new item
304  *
305  * \callgraph
306  *
307  * \note Assumes that \a data is valid and not NULL. This may be a possible bug.
308  * \bug Assumes that \a data is valid and not NULL and does not perform any sanity checks.
309  */
310 void get_new_inventory_item (const Uint8 *data);
311 
312 /*!
313  * \ingroup item
314  * \brief   Sets the cooldown values of inventory items from server data.
315  *
316  *      Sets the cooldown values of inventory items from server data.
317  *
318  * \param data the incoming data string from the server
319  * \param len  the length of the string in bytes
320  *
321  */
322 void get_items_cooldown (const Uint8 *data, int len);
323 
324 /*!
325  * \ingroup item
326  * \brief   Updates the cooldown value of inventory items.
327  *
328  *      Updates the cooldown value of inventory items.
329  *
330  */
331 void update_cooldown ();
332 
333 /*!
334  * \ingroup item
335  * \brief   Sets the displayed string for the items, manufacture and trade windows.
336  *
337  *      The items, manufacture and trade windows all display the same string,
338  * 		normally set in multiplayer.c.  This function can also set the string.
339  *		Each window independantly wraps the string to fit it's window.
340  *
341  * \param  colour_code the colour code for the string
342  * \param  the_text the null terminated string to display
343  */
344 void set_shown_string(char colour_code, const char *the_text);
345 
346 void get_item_uv(const Uint32 item, float* u_start, float* v_start,
347 	float* u_end, float* v_end);
348 
349 /*!
350  * \ingroup item
351  * \brief Set the action mode for the items window.
352  *
353  * \param new_mode  the new action mode, ignored if not one that can be used
354  *
355  */
356 void set_items_action_mode(int new_mode);
357 
358 #ifdef __cplusplus
359 } // extern "C"
360 #endif
361 
362 #endif
363