MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / tryPickUpItem

Method tryPickUpItem

game/ui/general/aequipscreen.cpp:1231–1277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1229}
1230
1231bool AEquipScreen::tryPickUpItem(sp<Agent> agent, Vec2<int> slotPos, bool alternative,
1232 bool *alienArtifact, bool forced)
1233{
1234 alternative = alternative && config().getBool("OpenApoc.NewFeature.AdvancedInventoryControls");
1235 auto equipment = std::dynamic_pointer_cast<AEquipment>(agent->getEquipmentAt(slotPos));
1236 if (!equipment)
1237 {
1238 return false;
1239 }
1240 if (!equipment->canBeUsed(*state) && (alternative || getMode() != Mode::Battle))
1241 {
1242 if (alienArtifact)
1243 {
1244 *alienArtifact = true;
1245 }
1246 return false;
1247 }
1248 draggedEquipmentOffset = {0, 0};
1249 draggedEquipmentOrigin = equipment->equippedPosition;
1250 draggedEquipmentAlternativePickup = false;
1251 if (alternative && equipment->payloadType)
1252 {
1253 draggedEquipmentAlternativePickup = true;
1254 draggedEquipment = equipment->unloadAmmo();
1255 }
1256 else
1257 {
1258 if (alternative && forced)
1259 {
1260 return false;
1261 }
1262 Vec2<float> slotPos = draggedEquipmentOrigin;
1263 for (auto &s : agent->type->equipment_layout->slots)
1264 {
1265 if (s.bounds.p0 != draggedEquipmentOrigin)
1266 {
1267 continue;
1268 }
1269 Vec2<float> offset = (s.bounds.p1 - s.bounds.p0) - equipment->type->equipscreen_size;
1270 slotPos += offset / 2.0f;
1271 break;
1272 }
1273 draggedEquipment = equipment;
1274 agent->removeEquipment(*state, equipment);
1275 }
1276 return true;
1277}
1278
1279bool AEquipScreen::tryPickUpItem(Vec2<int> inventoryPos, bool *alienArtifact)
1280{

Callers

nothing calls this directly

Calls 7

getBoolMethod · 0.80
unloadAmmoMethod · 0.80
withinMethod · 0.80
getPlayerMethod · 0.80
getEquipmentAtMethod · 0.45
canBeUsedMethod · 0.45
removeEquipmentMethod · 0.45

Tested by

no test coverage detected