123 lines
2.9 KiB
C
123 lines
2.9 KiB
C
/**
|
|
* Copyright (c) 2026 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#pragma once
|
|
#include "item/item.h"
|
|
|
|
#define ITEM_STACK_QUANTITY_MAX UINT8_MAX
|
|
|
|
typedef enum {
|
|
INVENTORY_SORT_BY_ID,
|
|
INVENTORY_SORT_BY_TYPE,
|
|
|
|
INVENTORY_SORT_COUNT
|
|
} inventorysort_t;
|
|
|
|
typedef struct {
|
|
itemid_t item;
|
|
uint8_t quantity;
|
|
} inventorystack_t;
|
|
|
|
typedef struct {
|
|
inventorystack_t *storage;
|
|
uint8_t storageSize;
|
|
} inventory_t;
|
|
|
|
/**
|
|
* Initializes an inventory.
|
|
*
|
|
* @param inventory The inventory to initialize.
|
|
* @param storage The storage array for the inventory.
|
|
* @param storageSize The size of the storage array.
|
|
*/
|
|
void inventoryInit(
|
|
inventory_t* inventory,
|
|
inventorystack_t* storage,
|
|
uint8_t storageSize
|
|
);
|
|
|
|
/**
|
|
* Checks if a specific item exists in the inventory (and has quantity > 0).
|
|
*
|
|
* @param inventory The inventory to check.
|
|
* @param item The item ID to check.
|
|
* @return true if the item exists, false otherwise.
|
|
*/
|
|
bool_t inventoryItemExists(const inventory_t *inventory, const itemid_t item);
|
|
|
|
/**
|
|
* Sets the quantity of a specific item in the inventory.
|
|
*
|
|
* @param inventory The inventory to modify.
|
|
* @param item The item ID to set.
|
|
* @param quantity The quantity to set.
|
|
*/
|
|
void inventorySet(
|
|
inventory_t *inventory,
|
|
const itemid_t item,
|
|
const uint8_t quantity
|
|
);
|
|
|
|
/**
|
|
* Adds a specific quantity of an item to the inventory.
|
|
*
|
|
* @param inventory The inventory to modify.
|
|
* @param item The item ID to add.
|
|
* @param quantity The quantity to add.
|
|
*/
|
|
void inventoryAdd(
|
|
inventory_t *inventory,
|
|
const itemid_t item,
|
|
const uint8_t quantity
|
|
);
|
|
|
|
/**
|
|
* Removes an item from the inventory.
|
|
*
|
|
* @param inventory The inventory to modify.
|
|
* @param item The item ID to remove.
|
|
*/
|
|
void inventoryRemove(inventory_t *inventory, const itemid_t item);
|
|
|
|
/**
|
|
* Gets the count of a specific item in the inventory.
|
|
*
|
|
* @param inventory The inventory to check.
|
|
* @param item The item ID to check.
|
|
* @return The count of the item in the inventory.
|
|
*/
|
|
uint8_t inventoryGetCount(const inventory_t *inventory, const itemid_t item);
|
|
|
|
/**
|
|
* Checks if the inventory is full.
|
|
*
|
|
* @param inventory The inventory to check.
|
|
* @return true if full, false otherwise.
|
|
*/
|
|
bool_t inventoryIsFull(const inventory_t *inventory);
|
|
|
|
/**
|
|
* Checks if a specific item stack is full in the inventory.
|
|
*
|
|
* @param inventory The inventory to check.
|
|
* @param item The item ID to check.
|
|
* @return true if the item stack is full, false otherwise.
|
|
*/
|
|
bool_t inventoryItemFull(const inventory_t *inventory, const itemid_t item);
|
|
|
|
/**
|
|
* Sorts the inventory based on the specified criteria.
|
|
*
|
|
* @param inventory The inventory to sort.
|
|
* @param sortBy The sorting criteria.
|
|
* @param reverse Whether to sort in reverse order.
|
|
*/
|
|
void inventorySort(
|
|
inventory_t *inventory,
|
|
const inventorysort_t sortBy,
|
|
const bool_t reverse
|
|
); |