Inventory
This commit is contained in:
@ -7,4 +7,5 @@
|
|||||||
target_sources(${DUSK_TARGET_NAME}
|
target_sources(${DUSK_TARGET_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
itemtype.c
|
itemtype.c
|
||||||
|
inventory.c
|
||||||
)
|
)
|
16
src/rpg/item/inventory.c
Normal file
16
src/rpg/item/inventory.c
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2025 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "assert/assert.h"
|
||||||
|
#include "inventory.h"
|
||||||
|
#include "util/memory.h"
|
||||||
|
|
||||||
|
void inventoryInit(inventory_t *inventory) {
|
||||||
|
assertNotNull(inventory, "Inventory pointer cannot be NULL");
|
||||||
|
|
||||||
|
memoryZero(inventory, sizeof(inventory_t));
|
||||||
|
}
|
23
src/rpg/item/inventory.h
Normal file
23
src/rpg/item/inventory.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2025 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "itemstack.h"
|
||||||
|
|
||||||
|
#define INVENTORY_ITEM_COUNT 32
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
itemstack_t items[INVENTORY_ITEM_COUNT];
|
||||||
|
uint8_t itemCount;
|
||||||
|
} inventory_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the inventory.
|
||||||
|
*
|
||||||
|
* @param inventory Pointer to the inventory to initialize.
|
||||||
|
*/
|
||||||
|
void inventoryInit(inventory_t *inventory);
|
@ -6,4 +6,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "itemtype.h"
|
#include "itemtype.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
itemtype_t type;
|
||||||
|
uint8_t count;
|
||||||
|
} itemstack_t;
|
@ -5,6 +5,7 @@
|
|||||||
* https://opensource.org/licenses/MIT
|
* https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "assert/assert.h"
|
||||||
#include "itemtype.h"
|
#include "itemtype.h"
|
||||||
|
|
||||||
iteminfo_t ITEM_INFO[ITEM_TYPE_COUNT] = {
|
iteminfo_t ITEM_INFO[ITEM_TYPE_COUNT] = {
|
||||||
@ -19,4 +20,9 @@ iteminfo_t ITEM_INFO[ITEM_TYPE_COUNT] = {
|
|||||||
|
|
||||||
// Cooked Items
|
// Cooked Items
|
||||||
[ITEM_TYPE_BAKED_SWEET_POTATO] = { .stackable = true },
|
[ITEM_TYPE_BAKED_SWEET_POTATO] = { .stackable = true },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static inline bool_t itemTypeIsStackable(const itemtype_t type) {
|
||||||
|
assert(type < ITEM_TYPE_COUNT, "Invalid item type");
|
||||||
|
return ITEM_INFO[type].stackable;
|
||||||
|
}
|
@ -27,4 +27,12 @@ typedef enum {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
bool_t stackable;
|
bool_t stackable;
|
||||||
} iteminfo_t;
|
} iteminfo_t;
|
||||||
extern iteminfo_t ITEM_INFO[ITEM_TYPE_COUNT];
|
extern iteminfo_t ITEM_INFO[ITEM_TYPE_COUNT];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the item type is stackable.
|
||||||
|
*
|
||||||
|
* @param type The item type to check.
|
||||||
|
* @return true if the item type is stackable, false otherwise.
|
||||||
|
*/
|
||||||
|
static inline bool_t itemTypeIsStackable(const itemtype_t type);
|
Reference in New Issue
Block a user