Mercurial > molko
comparison src/core/inventory.h @ 85:34e91215ec5a
core: implement basic parts of inventories, closes #2483
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 11 Mar 2020 19:53:19 +0100 |
parents | |
children | d3bc14c1e243 |
comparison
equal
deleted
inserted
replaced
84:a6c2067709ce | 85:34e91215ec5a |
---|---|
1 /* | |
2 * inventory.h -- inventory of items | |
3 * | |
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #ifndef MOLKO_INVENTORY_H | |
20 #define MOLKO_INVENTORY_H | |
21 | |
22 /** | |
23 * \file inventory.h | |
24 * \brief Inventory of items. | |
25 */ | |
26 | |
27 /** | |
28 * \brief Maximum number of rows. | |
29 */ | |
30 #define INVENTORY_ROWS_MAX 3 | |
31 | |
32 /** | |
33 * \brief Maximum number of columns. | |
34 */ | |
35 #define INVENTORY_COLS_MAX 10 | |
36 | |
37 struct item; | |
38 | |
39 /** | |
40 * \brief Inventory slot. | |
41 * | |
42 * This structure describe a 'cell' into the inventory. It references a item | |
43 * and has a given amount of it. | |
44 */ | |
45 struct inventory_slot { | |
46 struct item *item; /*!< (RO, ref) Pointer to the item. */ | |
47 unsigned int amount; /*!< (RO) Number of items in this slot. */ | |
48 }; | |
49 | |
50 /** | |
51 * \brief Inventory structure. | |
52 */ | |
53 struct inventory { | |
54 /** | |
55 * (RW) | |
56 * | |
57 * Grid of objects. | |
58 */ | |
59 struct inventory_slot items[INVENTORY_ROWS_MAX][INVENTORY_COLS_MAX]; | |
60 }; | |
61 | |
62 /** | |
63 * Try to push as much as possible the given item. | |
64 * | |
65 * \pre iv != NULL | |
66 * \pre item != NULL | |
67 * \param iv the inventory | |
68 * \param item the item to reference | |
69 * \param amount the desired amount | |
70 * \return 0 if all items were pushed or the number left otherwise | |
71 */ | |
72 unsigned int | |
73 inventory_push(struct inventory *iv, struct item *item, unsigned int amount); | |
74 | |
75 /** | |
76 * Clears the inventory. | |
77 * | |
78 * \pre iv != NULL | |
79 * \param iv the inventory | |
80 */ | |
81 void | |
82 inventory_clear(struct inventory *iv); | |
83 | |
84 #endif /* !MOLKO_INVENTORY_H */ |