Add inventory.
This commit is contained in:
103
src/item/inventory.h
Normal file
103
src/item/inventory.h
Normal file
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "item.h"
|
||||
|
||||
#define ITEM_STACK_QUANTITY_MAX UINT8_MAX
|
||||
|
||||
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);
|
||||
Reference in New Issue
Block a user