MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / fitItem

Method fitItem

src/Battlescape/Inventory.cpp:895–919  ·  view source on GitHub ↗

* Attempts to place the item in the inventory slot. * @param newSlot Where to place the item. * @param item Item to be placed. * @param warning Warning message if item could not be placed. * @return True, if the item was successfully placed in the inventory. */

Source from the content-addressed store, hash-verified

893 * @return True, if the item was successfully placed in the inventory.
894 */
895bool Inventory::fitItem(RuleInventory *newSlot, BattleItem *item, std::string &warning)
896{
897 bool placed = false;
898 for (int y2 = 0; y2 <= newSlot->getY() / RuleInventory::SLOT_H && !placed; ++y2)
899 {
900 for (int x2 = 0; x2 <= newSlot->getX() / RuleInventory::SLOT_W && !placed; ++x2)
901 {
902 if (!overlapItems(_selUnit, item, newSlot, x2, y2) && newSlot->fitItemInSlot(item->getRules(), x2, y2))
903 {
904 if (!_tu || _selUnit->spendTimeUnits(item->getSlot()->getCost(newSlot)))
905 {
906 placed = true;
907 moveItem(item, newSlot, x2, y2);
908 _game->getResourcePack()->getSound("BATTLE.CAT", 38)->play();
909 drawItems();
910 }
911 else
912 {
913 warning = "STR_NOT_ENOUGH_TIME_UNITS";
914 }
915 }
916 }
917 }
918 return placed;
919}
920
921/**
922 * Checks if two items can be stacked on one another.

Callers

nothing calls this directly

Calls 10

fitItemInSlotMethod · 0.80
spendTimeUnitsMethod · 0.80
getYMethod · 0.45
getXMethod · 0.45
getRulesMethod · 0.45
getCostMethod · 0.45
getSlotMethod · 0.45
playMethod · 0.45
getSoundMethod · 0.45
getResourcePackMethod · 0.45

Tested by

no test coverage detected