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

Method canBeStacked

src/Battlescape/Inventory.cpp:927–950  ·  view source on GitHub ↗

* Checks if two items can be stacked on one another. * @param itemA First item. * @param itemB Second item. * @return True, if the items can be stacked on one another. */

Source from the content-addressed store, hash-verified

925 * @return True, if the items can be stacked on one another.
926 */
927bool Inventory::canBeStacked(BattleItem *itemA, BattleItem *itemB)
928{
929 //both items actually exist
930 return (itemA != 0 && itemB != 0 &&
931 //both items have the same ruleset
932 itemA->getRules() == itemB->getRules() &&
933 // either they both have no ammo
934 ((!itemA->getAmmoItem() && !itemB->getAmmoItem()) ||
935 // or they both have ammo
936 (itemA->getAmmoItem() && itemB->getAmmoItem() &&
937 // and the same ammo type
938 itemA->getAmmoItem()->getRules() == itemB->getAmmoItem()->getRules() &&
939 // and the same ammo quantity
940 itemA->getAmmoItem()->getAmmoQuantity() == itemB->getAmmoItem()->getAmmoQuantity())) &&
941 // and neither is set to explode
942 itemA->getFuseTimer() == -1 && itemB->getFuseTimer() == -1 &&
943 // and neither is a corpse or unconscious unit
944 itemA->getUnit() == 0 && itemB->getUnit() == 0 &&
945 // and if it's a medkit, it has the same number of charges
946 itemA->getPainKillerQuantity() == itemB->getPainKillerQuantity() &&
947 itemA->getHealQuantity() == itemB->getHealQuantity() &&
948 itemA->getStimulantQuantity() == itemB->getStimulantQuantity());
949
950}
951}

Callers

nothing calls this directly

Calls 8

getAmmoQuantityMethod · 0.80
getRulesMethod · 0.45
getAmmoItemMethod · 0.45
getFuseTimerMethod · 0.45
getUnitMethod · 0.45
getPainKillerQuantityMethod · 0.45
getHealQuantityMethod · 0.45
getStimulantQuantityMethod · 0.45

Tested by

no test coverage detected