| 214 | |
| 215 | |
| 216 | int cItemGrid::HowManyCanFit(const cItem & a_ItemStack, bool a_AllowNewStacks) |
| 217 | { |
| 218 | char NumLeft = a_ItemStack.m_ItemCount; |
| 219 | int MaxStack = ItemHandler(a_ItemStack.m_ItemType)->GetMaxStackSize(); |
| 220 | for (int i = m_NumSlots - 1; i >= 0; i--) |
| 221 | { |
| 222 | if (m_Slots[i].IsEmpty()) |
| 223 | { |
| 224 | if (a_AllowNewStacks) |
| 225 | { |
| 226 | NumLeft -= MaxStack; |
| 227 | } |
| 228 | } |
| 229 | else if (m_Slots[i].IsEqual(a_ItemStack)) |
| 230 | { |
| 231 | NumLeft -= MaxStack - m_Slots[i].m_ItemCount; |
| 232 | } |
| 233 | if (NumLeft <= 0) |
| 234 | { |
| 235 | // All items fit |
| 236 | return a_ItemStack.m_ItemCount; |
| 237 | } |
| 238 | } // for i - m_Slots[] |
| 239 | return a_ItemStack.m_ItemCount - NumLeft; |
| 240 | } |
| 241 | |
| 242 | |
| 243 |
no test coverage detected