* 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. */
| 893 | * @return True, if the item was successfully placed in the inventory. |
| 894 | */ |
| 895 | bool 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. |
nothing calls this directly
no test coverage detected