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

Function FindItemOrObject

SourceX/controls/plrctrls.cpp:104–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102}
103
104void FindItemOrObject()
105{
106 int mx = plr[myplr]._px;
107 int my = plr[myplr]._py;
108 int rotations = 5;
109
110 // As the player can not stand on the edge fo the map this is safe from OOB
111 for (int xx = -1; xx < 2; xx++) {
112 for (int yy = -1; yy < 2; yy++) {
113 if (dItem[mx + xx][my + yy] <= 0)
114 continue;
115 int i = dItem[mx + xx][my + yy] - 1;
116 if (item[i]._itype == ITYPE_NONE
117 || item[i]._iSelFlag == 0)
118 continue;
119 int newRotations = GetRotaryDistance(mx + xx, my + yy);
120 if (rotations < newRotations)
121 continue;
122 if (xx != 0 && yy != 0 && GetDistance(mx + xx, my + yy, 1) == 0)
123 continue;
124 rotations = newRotations;
125 pcursitem = i;
126 cursmx = mx + xx;
127 cursmy = my + yy;
128 }
129 }
130
131 if (currlevel == DTYPE_TOWN || pcursitem != -1)
132 return; // Don't look for objects in town
133
134 for (int xx = -1; xx < 2; xx++) {
135 for (int yy = -1; yy < 2; yy++) {
136 if (dObject[mx + xx][my + yy] == 0)
137 continue;
138 int o = dObject[mx + xx][my + yy] > 0 ? dObject[mx + xx][my + yy] - 1 : -(dObject[mx + xx][my + yy] + 1);
139 if (object[o]._oSelFlag == 0)
140 continue;
141 if (xx == 0 && yy == 0 && object[o]._oDoorFlag)
142 continue; // Ignore doorway so we don't get stuck behind barrels
143 int newRotations = GetRotaryDistance(mx + xx, my + yy);
144 if (rotations < newRotations)
145 continue;
146 if (xx != 0 && yy != 0 && GetDistance(mx + xx, my + yy, 1) == 0)
147 continue;
148 rotations = newRotations;
149 pcursobj = o;
150 cursmx = mx + xx;
151 cursmy = my + yy;
152 }
153 }
154}
155
156void CheckTownersNearby()
157{

Callers 1

Calls 2

GetRotaryDistanceFunction · 0.85
GetDistanceFunction · 0.85

Tested by

no test coverage detected