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 int AddItem(
cItem & a_ItemStack,
bool a_AllowNewStacks =
true,
int a_PrioritySlot = -1);
99 int AddItems(
cItems & a_ItemStackList,
bool a_AllowNewStacks =
true,
int a_PrioritySlot = -1);
155 bool DamageItem(
int a_SlotNum,
short a_Amount);
158 bool DamageItem(
int a_X,
int a_Y,
short a_Amount);
int GetSlotNum(int a_X, int a_Y) const
Converts XY coords into slot number; returns -1 on invalid coords.
std::vector< cListener * > cListeners
void TriggerListeners(int a_SlotNum)
Calls all m_Listeners for the specified slot number.
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 GetFirstUsedSlot(void) const
Returns the index of the first non-empty slot; -1 if all empty.
void EmptySlot(int a_X, int a_Y)
void CopyFrom(const cItemGrid &a_Src)
Copies all items from a_Src to this grid.
int HowManyItems(const cItem &a_Item)
Returns the number of items of type a_Item that are stored.
int RemoveItem(const cItem &a_ItemStack)
Removes the specified item from the grid, as many as possible, up to a_ItemStack.m_ItemCount.
cItemGrid(int a_Width, int a_Height)
int ChangeSlotCount(int a_SlotNum, int a_AddToCount)
Adds (or subtracts, if a_AddToCount is negative) to the count of items in the specified slot...
int GetFirstEmptySlot(void) const
Returns the index of the first empty slot; -1 if all full.
void CopyToItems(cItems &a_Items) const
Copies the contents into a cItems object; preserves the original a_Items contents.
cItem RemoveOneItem(int a_SlotNum)
Removes one item from the stack in the specified slot, and returns it.
void Clear(void)
Sets all items as empty.
This class is used as a callback for when a slot changes.
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.
bool IsSlotEmpty(int a_SlotNum) const
Returns true if the specified slot is empty or the slot doesn't exist.
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 RemoveListener(cListener &a_Listener)
Removes a slot-change-callback.
bool m_IsInTriggerListeners
Set to true while TriggerListeners is running, to detect attempts to manipulate listener list while t...
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.
int AddItem(cItem &a_ItemStack, bool a_AllowNewStacks=true, int a_PrioritySlot=-1)
Adds as many items out of a_ItemStack as can fit.
int GetLastEmptySlot(void) const
Returns the index of the last empty slot; -1 if all full.
size_type size() const NOEXCEPT
int GetLastUsedSlot(void) const
Returns the index of the last used slot; -1 if all empty.
int GetNextUsedSlot(int a_StartFrom) const
Returns the index of the first used slot following a_StartFrom (a_StartFrom is not checked) ...
int HowManyCanFit(const cItem &a_ItemStack, bool a_AllowNewStacks=true)
Returns number of items out of a_ItemStack that can fit in the storage.
cLazyArray< cItem > m_Slots
cCriticalSection m_CSListeners
CS that guards the m_Listeners against multi-thread access.
bool IsValidSlotNum(int a_SlotNum) const
Returns true if slot number is within the grid.
int GetHeight(void) const
Used to store loot probability tables.
bool IsValidSlotCoords(int a_X, int a_Y) const
Returns true if slot coordinates lie within the grid.
const cItem & GetSlot(int a_X, int a_Y) const
int GetNumSlots(void) const
virtual void OnSlotChanged(cItemGrid *a_ItemGrid, int a_SlotNum)=0
Called whenever a slot changes.
int 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...
int AddItems(cItems &a_ItemStackList, bool a_AllowNewStacks=true, int a_PrioritySlot=-1)
Same as AddItem, but works on an entire list of item stacks.
int GetNextEmptySlot(int a_StartFrom) const
Returns the index of the first empty slot following a_StartFrom (a_StartFrom is not checked) ...
This class bridges a vector of cItem for safe access via Lua.
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...
void SetSlot(int a_X, int a_Y, const cItem &a_Item)