OpenEnroth 52af553
|
#include <Inventory.h>
Classes | |
struct | InventoryRecord |
Public Member Functions | |
Inventory (Sizei gridSize, int capacity) | |
Inventory () | |
int | size () const |
int | capacity () const |
Sizei | gridSize () const |
Recti | gridRect () const |
auto | entries (this auto &&self) |
auto | items (this auto &&self) |
auto | items (this auto &&self, ItemId itemId) |
InventoryEntry | entry (Pointi position) |
InventoryConstEntry | entry (Pointi position) const |
InventoryEntry | entry (ItemSlot slot) |
InventoryConstEntry | entry (ItemSlot slot) const |
InventoryEntry | entry (int index) |
InventoryConstEntry | entry (int index) const |
bool | canAdd (Pointi position, Sizei size) const |
bool | canAdd (Pointi position, const Item &item) const |
bool | canAdd (Sizei size) const |
bool | canAdd (const Item &item) const |
InventoryEntry | add (Pointi position, const Item &item) |
InventoryEntry | add (const Item &item) |
InventoryEntry | tryAdd (Pointi position, const Item &item) |
InventoryEntry | tryAdd (const Item &item) |
bool | canEquip (ItemSlot slot) const |
InventoryEntry | equip (ItemSlot slot, const Item &item) |
InventoryEntry | tryEquip (ItemSlot slot, const Item &item) |
bool | canStash () const |
InventoryEntry | stash (const Item &item) |
InventoryEntry | tryStash (const Item &item) |
Item | take (InventoryEntry entry) |
std::optional< Pointi > | findSpace (Sizei size) const |
std::optional< Pointi > | findSpace (const Item &item) const |
InventoryEntry | find (ItemId itemId) |
InventoryConstEntry | find (ItemId itemId) const |
void | clear () |
Static Public Attributes | |
static constexpr std::size_t | MAX_ITEMS = 140 |
Private Member Functions | |
int | findFreeIndex () const |
bool | isGridFree (Pointi position, Sizei size) const |
InventoryEntry | addAt (Pointi position, const Item &item, int index) |
InventoryEntry | equipAt (ItemSlot slot, const Item &item, int index) |
InventoryEntry | stashAt (const Item &item, int index) |
void | checkInvariants () const |
auto | availableRecords (this auto &&self) |
Private Attributes | |
Sizei | _gridSize |
int | _size = 0 |
int | _capacity = 0 |
std::array< InventoryRecord, MAX_ITEMS > | _records |
std::array< int, MAX_ITEMS > | _grid = {{}} |
IndexedArray< int, ITEM_SLOT_FIRST_VALID, ITEM_SLOT_LAST_VALID > | _equipment = {{}} |
Friends | |
class | InventoryConstEntry |
void | snapshot (const ChestInventory &src, Chest_MM7 *dst) |
void | reconstruct (const Chest_MM7 &src, ChestInventory *dst, ContextTag< int > chestId) |
void | snapshot (const CharacterInventory &src, Character_MM7 *dst) |
void | reconstruct (const Character_MM7 &src, CharacterInventory *dst, ContextTag< int > characterIndex) |
Core container that stores items for both chests and characters.
Inventory
stores items inside an array, so all items have indices. These indices are exposed through InventoryConstEntry::index
and Inventory::entry(int)
. In practice there shouldn't be a lot of use cases where direct access to item indices is needed.
|
explicit |
|
inline |
Constructs a 1x1 inventory that can hold MAX_ITEMS
items.
InventoryEntry Inventory::add | ( | const Item & | item | ) |
InventoryEntry Inventory::add | ( | Pointi | position, |
const Item & | item | ||
) |
|
private |
|
inlineprivate |
|
inline |
bool Inventory::canAdd | ( | Sizei | size | ) | const |
bool Inventory::canEquip | ( | ItemSlot | slot | ) | const |
bool Inventory::canStash | ( | ) | const |
|
inline |
|
private |
void Inventory::clear | ( | ) |
|
inline |
self | *this . |
InventoryEntry
or InventoryConstEntry
objects for items in this inventory. Returned entries are never invalid. InventoryEntry Inventory::entry | ( | int | index | ) |
index | Entry index to look up an item. |
index
, or an invalid entry if index
is out of bounds or if there is no item at index
.
|
inline |
InventoryEntry Inventory::entry | ( | ItemSlot | slot | ) |
slot | Equipment slot to look up an item. |
slot
, or an invalid entry if that slot is empty.
|
inline |
InventoryEntry Inventory::entry | ( | Pointi | position | ) |
position | Grid position to look up an item. |
position
is out of bounds or if the grid at position
is empty.
|
inline |
InventoryEntry Inventory::equip | ( | ItemSlot | slot, |
const Item & | item | ||
) |
|
private |
InventoryEntry Inventory::find | ( | ItemId | itemId | ) |
|
inline |
|
private |
|
inline |
inventory.gridRect().contains(pos)
.
|
inline |
self | *this . |
Item
objects for items in this inventory. Returned items are never ITEM_NULL
.
|
inline |
|
inline |
InventoryEntry Inventory::stash | ( | const Item & | item | ) |
|
private |
Item Inventory::take | ( | InventoryEntry | entry | ) |
InventoryEntry Inventory::tryAdd | ( | const Item & | item | ) |
InventoryEntry Inventory::tryAdd | ( | Pointi | position, |
const Item & | item | ||
) |
InventoryEntry Inventory::tryEquip | ( | ItemSlot | slot, |
const Item & | item | ||
) |
InventoryEntry Inventory::tryStash | ( | const Item & | item | ) |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
private |
Max number of items that can be stuffed into this inventory.
|
private |
Equipment array. Positive number is an index into _records
plus one. Zero means empty.
|
private |
Backpack grid. 0 means empty cell. Positive number is an index into _records
plus one. Negative number is an index into the main slot in _grid
minus one.
|
private |
All items in inventory. ITEM_NULL
means the slot is empty.
|
private |
Number of items in this inventory.
|
staticconstexpr |