48 void GetSlotCoords(
int a_SlotNum,
int & a_X,
int & a_Y)
const;
62 void SetSlot(
int a_X,
int a_Y,
short a_ItemType,
char a_ItemCount,
short a_ItemDamage);
64 void SetSlot(
int a_SlotNum,
short a_ItemType,
char a_ItemCount,
short a_ItemDamage);
89 char AddItem(
cItem & a_ItemStack,
bool a_AllowNewStacks =
true,
int a_PrioritySlot = -1);
99 char AddItems(
cItems & a_ItemStackList,
bool a_AllowNewStacks =
true,
int a_PrioritySlot = -1);
158 bool DamageItem(
int a_SlotNum,
short a_Amount);
161 bool DamageItem(
int a_X,
int a_Y,
short a_Amount);
This class bridges a vector of cItem for safe access via Lua.
Used to store loot probability tables.
int GetFirstEmptySlot(void) const
Returns the index of the first empty slot; -1 if all full.
void GetSlotCoords(int a_SlotNum, int &a_X, int &a_Y) const
Converts slot number into XY coords; sets coords to -1 on invalid slot number.
char AddItems(cItems &a_ItemStackList, bool a_AllowNewStacks=true, int a_PrioritySlot=-1)
Same as AddItem, but works on an entire list of item stacks.
bool IsSlotEmpty(int a_SlotNum) const
Returns true if the specified slot is empty or the slot doesn't exist.
bool IsValidSlotCoords(int a_X, int a_Y) const
Returns true if slot coordinates lie within the grid.
void CopyFrom(const cItemGrid &a_Src)
Copies all items from a_Src to this grid.
char ChangeSlotCount(int a_SlotNum, char a_AddToCount)
Adds (or subtracts, if a_AddToCount is negative) to the count of items in the specified slot.
cItemGrid(int a_Width, int a_Height)
cCriticalSection m_CSListeners
CS that guards the m_Listeners against multi-thread access.
void TriggerListeners(int a_SlotNum)
Calls all m_Listeners for the specified slot number.
int GetLastEmptySlot(void) const
Returns the index of the last empty slot; -1 if all full.
void SetSlot(int a_X, int a_Y, const cItem &a_Item)
int GetFirstUsedSlot(void) const
Returns the index of the first non-empty slot; -1 if all empty.
std::vector< cListener * > cListeners
int GetLastUsedSlot(void) const
Returns the index of the last used slot; -1 if all empty.
char AddItemToSlot(const cItem &a_ItemStack, int a_Slot, int a_Num, int a_MaxStack)
Adds up to a_Num items out of a_ItemStack, as many as can fit, in specified slot Returns the number o...
cLazyArray< cItem > m_Slots
cItem * FindItem(const cItem &a_RecipeItem)
Finds an item based on ItemType and ItemDamage (<- defines the itemType, too)
const cItem & GetSlot(int a_X, int a_Y) const
int GetNextUsedSlot(int a_StartFrom) const
Returns the index of the first used slot following a_StartFrom (a_StartFrom is not checked)
void Clear(void)
Sets all items as empty.
void EmptySlot(int a_X, int a_Y)
bool HasItems(const cItem &a_ItemStack)
Returns true if there are at least as many items of type a_ItemStack as in a_ItemStack.
void GenerateRandomLootWithBooks(const cLootProbab *a_LootProbabs, size_t a_CountLootProbabs, int a_NumSlots, int a_Seed)
Generates random loot from the specified loot probability table, with a chance of enchanted books add...
int GetNumSlots(void) const
int GetNextEmptySlot(int a_StartFrom) const
Returns the index of the first empty slot following a_StartFrom (a_StartFrom is not checked)
bool IsValidSlotNum(int a_SlotNum) const
Returns true if slot number is within the grid.
bool m_IsInTriggerListeners
Set to true while TriggerListeners is running, to detect attempts to manipulate listener list while t...
cListeners m_Listeners
Listeners which should be notified on slot changes; the pointers are not owned by this object.
void AddListener(cListener &a_Listener)
Adds a callback that gets called whenever a slot changes.
int GetSlotNum(int a_X, int a_Y) const
Converts XY coords into slot number; returns -1 on invalid coords.
int HowManyItems(const cItem &a_Item)
Returns the number of items of type a_Item that are stored.
int HowManyCanFit(const cItem &a_ItemStack, bool a_AllowNewStacks=true)
Returns number of items out of a_ItemStack that can fit in the storage.
char RemoveItem(const cItem &a_ItemStack)
Removes the specified item from the grid, as many as possible, up to a_ItemStack.m_ItemCount.
void RemoveListener(cListener &a_Listener)
Removes a slot-change-callback.
bool DamageItem(int a_SlotNum, short a_Amount)
Adds the specified damage to the specified item; returns true if the item broke (but the item is left...
cItem RemoveOneItem(int a_SlotNum)
Removes one item from the stack in the specified slot, and returns it.
char AddItem(cItem &a_ItemStack, bool a_AllowNewStacks=true, int a_PrioritySlot=-1)
Adds as many items out of a_ItemStack as can fit.
void CopyToItems(cItems &a_Items) const
Copies the contents into a cItems object; preserves the original a_Items contents.
int GetHeight(void) const
This class is used as a callback for when a slot changes.
virtual void OnSlotChanged(cItemGrid *a_ItemGrid, int a_SlotNum)=0
Called whenever a slot changes.
size_type size() const noexcept