MCPcopy Create free account
hub / github.com/diasurgical/devilution / AutoGetItem

Function AutoGetItem

Source/inv.cpp:1483–1613  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1481}
1482
1483void AutoGetItem(int pnum, int ii)
1484{
1485 int i, idx;
1486 int w, h;
1487 BOOL done;
1488
1489 if (dropGoldFlag) {
1490 dropGoldFlag = FALSE;
1491 dropGoldValue = 0;
1492 }
1493
1494 if (ii != MAXITEMS && !dItem[item[ii]._ix][item[ii]._iy]) {
1495 return;
1496 }
1497
1498 item[ii]._iCreateInfo &= 0x7FFF;
1499 plr[pnum].HoldItem = item[ii]; /// BUGFIX: overwrites cursor item, allowing for belt dupe bug
1500 CheckQuestItem(pnum);
1501 CheckBookLevel(pnum);
1502 CheckItemStats(pnum);
1503 SetICursor(plr[pnum].HoldItem._iCurs + CURSOR_FIRSTITEM);
1504 if (plr[pnum].HoldItem._itype == ITYPE_GOLD) {
1505 done = GoldAutoPlace(pnum);
1506 } else {
1507 done = FALSE;
1508 if (((plr[pnum]._pgfxnum & 0xF) == ANIM_ID_UNARMED || (plr[pnum]._pgfxnum & 0xF) == ANIM_ID_UNARMED_SHIELD) && plr[pnum]._pmode <= PM_WALK3) {
1509 if (plr[pnum].HoldItem._iStatFlag) {
1510 if (plr[pnum].HoldItem._iClass == ICLASS_WEAPON) {
1511 done = WeaponAutoPlace(pnum);
1512 if (done)
1513 CalcPlrInv(pnum, TRUE);
1514 }
1515 }
1516 }
1517 if (!done) {
1518 w = icursW28;
1519 h = icursH28;
1520 if (w == 1 && h == 1) {
1521 idx = plr[pnum].HoldItem.IDidx;
1522 if (plr[pnum].HoldItem._iStatFlag && AllItemsList[idx].iUsable) {
1523 for (i = 0; i < 8 && !done; i++) {
1524 if (plr[pnum].SpdList[i]._itype == ITYPE_NONE) {
1525 plr[pnum].SpdList[i] = plr[pnum].HoldItem;
1526 CalcPlrScrolls(pnum);
1527 drawsbarflag = TRUE;
1528 done = TRUE;
1529 }
1530 }
1531 }
1532 for (i = 30; i <= 39 && !done; i++) {
1533 done = AutoPlace(pnum, i, w, h, TRUE);
1534 }
1535 for (i = 20; i <= 29 && !done; i++) {
1536 done = AutoPlace(pnum, i, w, h, TRUE);
1537 }
1538 for (i = 10; i <= 19 && !done; i++) {
1539 done = AutoPlace(pnum, i, w, h, TRUE);
1540 }

Callers 3

On_REQUESTAGITEMFunction · 0.85
On_AGETITEMFunction · 0.85
On_WARPFunction · 0.85

Calls 14

CheckQuestItemFunction · 0.85
CheckBookLevelFunction · 0.85
CheckItemStatsFunction · 0.85
SetICursorFunction · 0.85
GoldAutoPlaceFunction · 0.85
WeaponAutoPlaceFunction · 0.85
CalcPlrInvFunction · 0.85
CalcPlrScrollsFunction · 0.85
AutoPlaceFunction · 0.85
DeleteItemFunction · 0.85
PlaySFXFunction · 0.85
random_Function · 0.85

Tested by

no test coverage detected