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

Method takeItem

src/Battlescape/BattlescapeGame.cpp:1859–1932  ·  view source on GitHub ↗

* Tries to fit an item into the unit's inventory, return false if you can't. * @param item The item to attempt to take. * @param action A pointer to the action being performed. * @return Whether or not the item was successfully retrieved. */

Source from the content-addressed store, hash-verified

1857 * @return Whether or not the item was successfully retrieved.
1858 */
1859bool BattlescapeGame::takeItem(BattleItem* item, BattleAction *action)
1860{
1861 bool placed = false;
1862 Ruleset* rules = _parentState->getGame()->getRuleset();
1863 switch (item->getRules()->getBattleType())
1864 {
1865 case BT_AMMO:
1866 // find equipped weapons that can be loaded with this ammo
1867 if (action->actor->getItem("STR_RIGHT_HAND") && action->actor->getItem("STR_RIGHT_HAND")->getAmmoItem() == 0)
1868 {
1869 if (action->actor->getItem("STR_RIGHT_HAND")->setAmmoItem(item) == 0)
1870 {
1871 placed = true;
1872 }
1873 }
1874 else
1875 {
1876 for (int i = 0; i != 4; ++i)
1877 {
1878 if (!action->actor->getItem("STR_BELT", i))
1879 {
1880 item->moveToOwner(action->actor);
1881 item->setSlot(rules->getInventory("STR_BELT"));
1882 item->setSlotX(i);
1883 placed = true;
1884 break;
1885 }
1886 }
1887 }
1888 break;
1889 case BT_GRENADE:
1890 case BT_PROXIMITYGRENADE:
1891 for (int i = 0; i != 4; ++i)
1892 {
1893 if (!action->actor->getItem("STR_BELT", i))
1894 {
1895 item->moveToOwner(action->actor);
1896 item->setSlot(rules->getInventory("STR_BELT"));
1897 item->setSlotX(i);
1898 placed = true;
1899 break;
1900 }
1901 }
1902 break;
1903 case BT_FIREARM:
1904 case BT_MELEE:
1905 if (!action->actor->getItem("STR_RIGHT_HAND"))
1906 {
1907 item->moveToOwner(action->actor);
1908 item->setSlot(rules->getInventory("STR_RIGHT_HAND"));
1909 placed = true;
1910 }
1911 break;
1912 case BT_MEDIKIT:
1913 case BT_SCANNER:
1914 if (!action->actor->getItem("STR_BACK_PACK"))
1915 {
1916 item->moveToOwner(action->actor);

Callers

nothing calls this directly

Calls 11

getGameMethod · 0.80
getBattleTypeMethod · 0.80
setAmmoItemMethod · 0.80
moveToOwnerMethod · 0.80
setSlotMethod · 0.80
setSlotXMethod · 0.80
getRulesetMethod · 0.45
getRulesMethod · 0.45
getItemMethod · 0.45
getAmmoItemMethod · 0.45
getInventoryMethod · 0.45

Tested by

no test coverage detected