| 243 | |
| 244 | |
| 245 | void cSlotArea::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_Apply, bool a_KeepEmptySlots) |
| 246 | { |
| 247 | for (int i = 0; i < m_NumSlots; i++) |
| 248 | { |
| 249 | const cItem * Slot = GetSlot(i, a_Player); |
| 250 | if (!Slot->IsEqual(a_ItemStack) && (!Slot->IsEmpty() || a_KeepEmptySlots)) |
| 251 | { |
| 252 | // Different items |
| 253 | continue; |
| 254 | } |
| 255 | int NumFit = ItemHandler(Slot->m_ItemType)->GetMaxStackSize() - Slot->m_ItemCount; |
| 256 | if (NumFit <= 0) |
| 257 | { |
| 258 | // Full stack already |
| 259 | continue; |
| 260 | } |
| 261 | if (NumFit > a_ItemStack.m_ItemCount) |
| 262 | { |
| 263 | NumFit = a_ItemStack.m_ItemCount; |
| 264 | } |
| 265 | if (a_Apply) |
| 266 | { |
| 267 | cItem NewSlot(a_ItemStack); |
| 268 | NewSlot.m_ItemCount = Slot->m_ItemCount + NumFit; |
| 269 | SetSlot(i, a_Player, NewSlot); |
| 270 | } |
| 271 | a_ItemStack.m_ItemCount -= NumFit; |
| 272 | if (a_ItemStack.IsEmpty()) |
| 273 | { |
| 274 | return; |
| 275 | } |
| 276 | } // for i - Slots |
| 277 | } |
| 278 | |
| 279 | |
| 280 |
no test coverage detected