nw::Inventory

struct Inventory

Public Types

using Storage = std::bitset<total_slots_per_page>

Public Functions

explicit Inventory(ObjectBase *owner_, nw::MemoryResource *allocator = nw::kernel::global_allocator())
Inventory(int pages, int rows, int columns, nw::MemoryResource *allocator = nw::kernel::global_allocator())
Inventory(int pages, int rows, int columns, ObjectBase *owner_, nw::MemoryResource *allocator = nw::kernel::global_allocator())
Inventory(const Inventory&) = delete
Inventory(Inventory&&) = default
Inventory &operator=(const Inventory&) = delete
Inventory &operator=(Inventory&&) = default
~Inventory() = default
void destroy()
bool instantiate()
bool add_item(nw::Item *item)

Adds item to inventory.

bool add_page()

Adds a page to the inventory.

bool can_add_item(nw::Item *item) const

Determines if inventory can hold item.

bool check_available(int page, int row, int col, int width, int height) const noexcept

Checks if slots for item of width x height is availble at a particular page, row, and column.

bool clear_item(int page, int row, int col, int width, int height)

Clears an item from the inventory grid.

std::string debug() const

Gets a string representation of the occupied inventory slots.

InventorySlot find_slot(int width, int height) const noexcept

Finds first available slot for item of width x height.

bool has_item(nw::Item *item) const noexcept

Determines if inventory contains an item.

bool insert_item(int page, int row, int col, int width, int height)

Sets an item from the inventory grid.

inline int pages() const noexcept

Gets current number of pages.

bool remove_item(nw::Item *item)

Remove item from inventory.

void set_growable(bool value)

Sets the inventory to allow adding pages dynamically (for stores)

size_t size() const noexcept

Gets number of items in the inventory.

std::pair<uint16_t, uint16_t> slot_to_xy(InventorySlot slot) const noexcept

Converts coordinates from our page, row, col to bioware x,y cooardinates.

InventorySlot xy_to_slot(uint16_t x, uint16_t y) const noexcept

Converts bioware x,y cooardinates to our page, row, col coordinates.

bool from_json(const nlohmann::json &archive, SerializationProfile profile)
nlohmann::json to_json(SerializationProfile profile) const

Public Members

ObjectBase *owner
FixedVector<InventoryItem> items
std::vector<Storage> inventory_bitset
int pages_ = default_pages
int rows_ = max_rows
int columns_ = max_columns
bool growable_ = false

Public Static Attributes

static constexpr int default_pages = 6
static constexpr int max_columns = 10
static constexpr int max_rows = 10
static constexpr int total_slots_per_page = max_rows * max_columns