MCPcopy Create free account
hub / github.com/diasurgical/DevilutionX / CheckInvPaste

Function CheckInvPaste

Source/inv.cpp:327–560  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

325}
326
327void CheckInvPaste(Player &player, Point cursorPosition)
328{
329 Size itemSize = GetInventorySize(player.HoldItem);
330
331 int slot = FindTargetSlotUnderItemCursor(cursorPosition, itemSize);
332 if (slot == NUM_XY_SLOTS)
333 return;
334
335 item_equip_type il = ILOC_UNEQUIPABLE;
336 if (slot == SLOTXY_HEAD)
337 il = ILOC_HELM;
338 if (slot == SLOTXY_RING_LEFT || slot == SLOTXY_RING_RIGHT)
339 il = ILOC_RING;
340 if (slot == SLOTXY_AMULET)
341 il = ILOC_AMULET;
342 if (slot == SLOTXY_HAND_LEFT || slot == SLOTXY_HAND_RIGHT)
343 il = ILOC_ONEHAND;
344 if (slot == SLOTXY_CHEST)
345 il = ILOC_ARMOR;
346 if (slot >= SLOTXY_BELT_FIRST && slot <= SLOTXY_BELT_LAST)
347 il = ILOC_BELT;
348
349 item_equip_type desiredIl = player.GetItemLocation(player.HoldItem);
350 if (il == ILOC_ONEHAND && desiredIl == ILOC_TWOHAND)
351 il = ILOC_TWOHAND;
352
353 int8_t it = 0;
354 if (il == ILOC_UNEQUIPABLE) {
355 int ii = slot - SLOTXY_INV_FIRST;
356 if (player.HoldItem._itype == ItemType::Gold) {
357 if (player.InvGrid[ii] != 0) {
358 int8_t iv = player.InvGrid[ii];
359 if (iv > 0) {
360 if (player.InvList[iv - 1]._itype != ItemType::Gold) {
361 it = iv;
362 }
363 } else {
364 it = -iv;
365 }
366 }
367 } else {
368 // check that the item we're pasting only overlaps one other item (or is going into empty space)
369 unsigned originCell = static_cast<unsigned>(slot - SLOTXY_INV_FIRST);
370 for (unsigned rowOffset = 0; rowOffset < static_cast<unsigned>(itemSize.height * InventorySizeInSlots.width); rowOffset += InventorySizeInSlots.width) {
371 for (unsigned columnOffset = 0; columnOffset < static_cast<unsigned>(itemSize.width); columnOffset++) {
372 unsigned testCell = originCell + rowOffset + columnOffset;
373 // FindTargetSlotUnderItemCursor returns the top left slot of the inventory region that fits the item, we can be confident this calculation is not going to read out of range.
374 assert(testCell < sizeof(player.InvGrid));
375 if (player.InvGrid[testCell] != 0) {
376 int8_t iv = abs(player.InvGrid[testCell]);
377 if (it != 0) {
378 if (it != iv) {
379 // Found two different items that would be displaced by the held item, can't paste the item here.
380 return;
381 }
382 } else {
383 it = iv;
384 }

Callers 1

CheckInvItemFunction · 0.85

Calls 15

GetInventorySizeFunction · 0.85
CanBePlacedOnBeltFunction · 0.85
IsNoneOfFunction · 0.85
app_fatalFunction · 0.85
ChangeEquipmentFunction · 0.85
RemoveEquipmentFunction · 0.85
AutoPlaceItemInInventoryFunction · 0.85
SetPlrHandGoldCursFunction · 0.85
NetSendCmdChInvItemFunction · 0.85
CalculateGoldFunction · 0.85
AddItemToInvGridFunction · 0.85
NetSendCmdChBeltItemFunction · 0.85

Tested by

no test coverage detected