This commit is contained in:
MihailRis
2025-02-06 20:26:06 +03:00
parent b1740bf7eb
commit 4306573320
7 changed files with 26 additions and 24 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ size_t Inventory::findSlotByItem(
}
void Inventory::move(
ItemStack& item, const ContentIndices* indices, size_t begin, size_t end
ItemStack& item, const ContentIndices& indices, size_t begin, size_t end
) {
end = std::min(slots.size(), end);
for (size_t i = begin; i < end && !item.isEmpty(); i++) {
+1 -1
View File
@@ -32,7 +32,7 @@ public:
void move(
ItemStack& item,
const ContentIndices* indices,
const ContentIndices& indices,
size_t begin = 0,
size_t end = -1
);
+3 -6
View File
@@ -3,9 +3,6 @@
#include "content/Content.hpp"
#include "ItemDef.hpp"
ItemStack::ItemStack() : item(ITEM_EMPTY), count(0) {
}
ItemStack::ItemStack(itemid_t item, itemcount_t count)
: item(item), count(count) {
}
@@ -28,9 +25,9 @@ bool ItemStack::accepts(const ItemStack& other) const {
return item == other.getItemId();
}
void ItemStack::move(ItemStack& item, const ContentIndices* indices) {
auto& def = indices->items.require(item.getItemId());
int count = std::min(item.count, def.stackSize - this->count);
void ItemStack::move(ItemStack& item, const ContentIndices& indices) {
auto& def = indices.items.require(item.getItemId());
itemcount_t count = std::min(item.count, def.stackSize - this->count);
if (isEmpty()) {
set(ItemStack(item.getItemId(), count));
} else {
+9 -4
View File
@@ -6,10 +6,10 @@
class ContentIndices;
class ItemStack {
itemid_t item;
itemcount_t count;
itemid_t item = ITEM_EMPTY;
itemcount_t count = 0;
public:
ItemStack();
ItemStack() = default;
ItemStack(itemid_t item, itemcount_t count);
@@ -17,7 +17,12 @@ public:
void setCount(itemcount_t count);
bool accepts(const ItemStack& item) const;
void move(ItemStack& item, const ContentIndices* indices);
/// @brief Move items from one stack to another.
/// If the target stack is completely filled, the source stack will be reduced.
/// @param item source stack
/// @param indices content indices
void move(ItemStack& item, const ContentIndices& indices);
inline void clear() {
set(ItemStack(0, 0));