MCPcopy Create free account
hub / github.com/TurningWheel/Barony / getItemStackingBehaviorIntoChest

Function getItemStackingBehaviorIntoChest

src/items.cpp:4251–4374  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4249}
4250
4251ItemStackResult getItemStackingBehaviorIntoChest(const int player, Item* itemToCheck, Item* itemDestinationStack, int& newQtyForCheckedItem, int& newQtyForDestItem)
4252{
4253 ItemStackResult itemStackResult;
4254 itemStackResult.itemToStackInto = nullptr;
4255 if ( !itemToCheck )
4256 {
4257 itemStackResult.resultType = ITEM_STACKING_ERROR;
4258 return itemStackResult;
4259 }
4260
4261 list_t* chest_inventory = nullptr;
4262 if ( multiplayer == CLIENT )
4263 {
4264 chest_inventory = &chestInv[player];
4265 }
4266 else if ( openedChest[player] )
4267 {
4268 chest_inventory = openedChest[player]->getChestInventoryList();
4269 }
4270 if ( !chest_inventory )
4271 {
4272 // no chest inventory available
4273 itemStackResult.resultType = ITEM_STACKING_ERROR;
4274 return itemStackResult;
4275 }
4276
4277 if ( itemDestinationStack )
4278 {
4279 return getItemStackingBehaviorIndividualItemCheck(player, itemToCheck, itemDestinationStack, newQtyForCheckedItem, newQtyForDestItem);
4280 }
4281
4282 itemStackResult.resultType = ITEM_ADDED_WITHOUT_NEEDING_STACK;
4283 newQtyForCheckedItem = itemToCheck->count;
4284 newQtyForDestItem = 0;
4285
4286 for ( node_t* node = chest_inventory->first; node != nullptr; node = node->next )
4287 {
4288 Item* item2 = static_cast<Item*>(node->element);
4289 if ( item2 )
4290 {
4291 int tmpQtyCheckedItem = newQtyForCheckedItem;
4292 int tmpQtyDestItem = newQtyForDestItem;
4293 auto res = getItemStackingBehaviorIndividualItemCheck(player, itemToCheck, item2, tmpQtyCheckedItem, tmpQtyDestItem);
4294 bool skipResult = false;
4295 switch ( res.resultType )
4296 {
4297 case ITEM_DESTINATION_NOT_SAME_ITEM:
4298 case ITEM_STACKING_ERROR:
4299 case ITEM_DESTINATION_STACK_IS_FULL:
4300 skipResult = true;
4301 break;
4302 default:
4303 break;
4304 }
4305 if ( skipResult )
4306 {
4307 continue;
4308 }

Callers

nothing calls this directly

Tested by

no test coverage detected