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

Function SyncPutItem

Source/inv.cpp:1815–1891  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1813}
1814
1815int SyncPutItem(int pnum, int x, int y, int idx, WORD icreateinfo, int iseed, int Id, int dur, int mdur, int ch, int mch, int ivalue, DWORD ibuff)
1816{
1817 BOOL done;
1818 int d, ii;
1819 int i, j, l;
1820 int xx, yy;
1821 int xp, yp;
1822
1823 if (numitems >= 127)
1824 return -1;
1825
1826 if (FindGetItem(idx, icreateinfo, iseed) != -1) {
1827 DrawInvMsg("A duplicate item has been detected from another player.");
1828 SyncGetItem(x, y, idx, icreateinfo, iseed);
1829 }
1830
1831 d = GetDirection(plr[pnum].WorldX, plr[pnum].WorldY, x, y);
1832 xx = x - plr[pnum].WorldX;
1833 yy = y - plr[pnum].WorldY;
1834 if (abs(xx) > 1 || abs(yy) > 1) {
1835 x = plr[pnum].WorldX + offset_x[d];
1836 y = plr[pnum].WorldY + offset_y[d];
1837 }
1838 if (!CanPut(x, y)) {
1839 d = (d - 1) & 7;
1840 x = plr[pnum].WorldX + offset_x[d];
1841 y = plr[pnum].WorldY + offset_y[d];
1842 if (!CanPut(x, y)) {
1843 d = (d + 2) & 7;
1844 x = plr[pnum].WorldX + offset_x[d];
1845 y = plr[pnum].WorldY + offset_y[d];
1846 if (!CanPut(x, y)) {
1847 done = FALSE;
1848 for (l = 1; l < 50 && !done; l++) {
1849 for (j = -l; j <= l && !done; j++) {
1850 yp = j + plr[pnum].WorldY;
1851 for (i = -l; i <= l && !done; i++) {
1852 xp = i + plr[pnum].WorldX;
1853 if (CanPut(xp, yp)) {
1854 done = TRUE;
1855 x = xp;
1856 y = yp;
1857 }
1858 }
1859 }
1860 }
1861 if (!done)
1862 return -1;
1863 }
1864 }
1865 }
1866
1867 CanPut(x, y);
1868
1869 ii = itemavail[0];
1870 dItem[x][y] = ii + 1;
1871 itemavail[0] = itemavail[MAXITEMS - (numitems + 1)];
1872 itemactive[numitems] = ii;

Callers 5

On_GETITEMFunction · 0.85
On_AGETITEMFunction · 0.85
On_PUTITEMFunction · 0.85
On_SYNCPUTITEMFunction · 0.85
On_RESPAWNITEMFunction · 0.85

Calls 8

FindGetItemFunction · 0.85
DrawInvMsgFunction · 0.85
SyncGetItemFunction · 0.85
GetDirectionFunction · 0.85
CanPutFunction · 0.85
RecreateEarFunction · 0.85
RecreateItemFunction · 0.85
RespawnItemFunction · 0.85

Tested by

no test coverage detected