63 lines
1.6 KiB
C
63 lines
1.6 KiB
C
/**
|
|
* 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_SIZE_MAX UINT8_MAX
|
|
|
|
typedef struct {
|
|
itemstack_t items[INVENTORY_SIZE_MAX];
|
|
uint8_t itemCount;
|
|
uint8_t size;
|
|
} inventory_t;
|
|
|
|
/**
|
|
* Initializes an inventory with a specified size.
|
|
*
|
|
* @param inventory Pointer to the inventory to initialize.
|
|
* @param size The size of the inventory (maximum is INVENTORY_SIZE_MAX).
|
|
*/
|
|
void inventoryInit(inventory_t *inventory, const uint8_t size);
|
|
|
|
/**
|
|
* Finds the index of the item of a specified type in the inventory.
|
|
*
|
|
* @param inventory Pointer to the inventory to search.
|
|
* @param type The type of item to find.
|
|
* @return The index of the item, or INVENTORY_SIZE_MAX if not found.
|
|
*/
|
|
uint8_t inventoryItemIndexByType(
|
|
const inventory_t *inventory,
|
|
const itemtype_t type
|
|
);
|
|
|
|
/**
|
|
* Gets the count of items of a specified type in the inventory.
|
|
*
|
|
* @param inventory Pointer to the inventory to check.
|
|
* @param type The type of item to count.
|
|
* @return The count of items of the specified type.
|
|
*/
|
|
uint8_t inventoryItemCount(
|
|
const inventory_t *inventory,
|
|
const itemtype_t type
|
|
);
|
|
|
|
/**
|
|
* Sets the count of items of a specified type in the inventory.
|
|
* If the item does not exist, it will be added.
|
|
*
|
|
* @param inventory Pointer to the inventory to modify.
|
|
* @param type The type of item to set.
|
|
* @param count The count of items to set.
|
|
*/
|
|
void inventoryItemSet(
|
|
inventory_t *inventory,
|
|
const itemtype_t type,
|
|
const uint8_t count
|
|
); |