Copied from reflection 2_1:
(*
R_GetGroundItemsEx
~~~~~~~~~~~~~~~~~~
.. code-block:: pascal
function R_GetGroundItemsEx(IDs: TIntegerArray; MaxDist: Integer): TGroundItemArray;
Retrieves all of the ground items within a circle with a radius of MaxDist that
contain one of the IDs specified. Stores them in a TGroundItemArray.
.. note::
by Drags111
*)
function R_GetGroundItemsEx(IDs: TIntegerArray; MaxDist: Integer): TGroundItemArray;
var
Cache, Hash, Plane, Nodes, Size, Index, Tail, Cur, Next,
UID, List, TheID, Stack: Integer;
H, I, BX, BY, endx, endy: Integer;
Tiles: TTileArray;
begin
SetLength(Result, 0);
BX := SmartGetFieldInt(0, hook_static_BaseX);
BY := SmartGetFieldInt(0, hook_static_BaseY);
EndX := BX + 104;
EndY := BY + 104;
Cache := SmartGetFieldObject(0, hook_static_GroundItemCache);
Nodes := SmartGetFieldObject(cache, hook_nodecache_GetNodes);
SmartFreeObject(Cache);
Plane := SmartGetFieldInt(0, hook_static_LoadedPlane);
Size := SmartGetFieldArraySize(Nodes, '', 1);
Tiles := R_SortedCircleTPA(R_GetMyPos, MaxDist);
H := High(Tiles);
for I := 0 to H do
begin
List := 0;
Hash := Tiles[I].X or (Tiles[I].Y shl 14) or (Plane shl 28);
Index := Hash and (Size - 1);
Tail := SmartGetFieldArrayObject(Nodes, '', Index);
Cur := SmartGetFieldObject(Tail, hook_node_Next);
try
while (not (SmartIsEqual(Tail, Cur))) do
begin
UID := SmartGetFieldLongL(Cur, hook_node_GetID);
if (UID = Hash) then
begin
List := SmartGetFieldObject(Cur, hook_nodelistcache_GetNodeList);
Break;
end;
Next := SmartGetFieldObject(Cur, hook_node_Next);
SmartFreeObject(Cur);
Cur := Next;
end;
finally
SmartFreeObject(Cur);
SmartFreeObject(Tail);
end;
if(List = 0)then
Continue;
Tail := SmartGetFieldObject(list, hook_nodelist_Head);
List := 0;
Cur := SmartGetFieldObject(tail, hook_node_Next);
while (not (SmartIsEqual(tail, cur))) do
begin
TheID := SmartGetFieldInt(Cur, hook_item_GetID);
if InIntArray(IDs, TheID)then
begin
SetArrayLength(Result, GetArrayLength(Result) + 1);
with Result[High(Result)] do
begin
ID := TheID;
Stack := SmartGetFieldInt(Cur, hook_item_GetStack);
Tile.X := Tiles[I].X;
Tile.Y := Tiles[I].Y;
end;
end;
Next := SmartGetFieldObject(Cur, hook_node_Next);
SmartFreeObject(Cur);
Cur := Next;
end;
SmartFreeObject(Cur);
SmartFreeObject(Tail);
SmartFreeObject(List);
end;
SmartFreeObject(Nodes);
end;
This one is much faster, but you will need to adjust it for a square cage, I've made a set up for you. This hasn't been tested so it probally will still contains bugs.
function R_GetGroundItemsEx(IDs: TIntegerArray; SearchBox:Tbox): TGroundItemArray;
var
Cache, Hash, Plane, Nodes, Size, Index, Tail, Cur, Next,
UID, List, TheID, Stack: Integer;
cTileX, cTileY: Integer;
begin
SetLength(Result, 0);
Cache := SmartGetFieldObject(0, hook_static_GroundItemCache);
Nodes := SmartGetFieldObject(cache, hook_nodecache_GetNodes);
SmartFreeObject(Cache);
Plane := SmartGetFieldInt(0, hook_static_LoadedPlane);
Size := SmartGetFieldArraySize(Nodes, '', 1);
for cTileX := SearchBox.X1 to SearchBox.X2 do
for cTileY := SearchBox.Y1 to SearchBox.Y2 do
begin
List := 0;
Hash := cTileX or (cTileY shl 14) or (Plane shl 28);
Index := Hash and (Size - 1);
Tail := SmartGetFieldArrayObject(Nodes, '', Index);
Cur := SmartGetFieldObject(Tail, hook_node_Next);
try
while (not (SmartIsEqual(Tail, Cur))) do
begin
UID := SmartGetFieldLongL(Cur, hook_node_GetID);
if (UID = Hash) then
begin
List := SmartGetFieldObject(Cur, hook_nodelistcache_GetNodeList);
Break;
end;
Next := SmartGetFieldObject(Cur, hook_node_Next);
SmartFreeObject(Cur);
Cur := Next;
end;
finally
SmartFreeObject(Cur);
SmartFreeObject(Tail);
end;
if(List = 0)then
Continue;
Tail := SmartGetFieldObject(list, hook_nodelist_Head);
List := 0;
Cur := SmartGetFieldObject(tail, hook_node_Next);
while (not (SmartIsEqual(tail, cur))) do
begin
TheID := SmartGetFieldInt(Cur, hook_item_GetID);
if InIntArray(IDs, TheID)then
begin
SetArrayLength(Result, GetArrayLength(Result) + 1);
with Result[High(Result)] do
begin
ID := TheID;
Stack := SmartGetFieldInt(Cur, hook_item_GetStack);
Tile.X := cTileX;
Tile.Y := cTileY;
end;
end;
Next := SmartGetFieldObject(Cur, hook_node_Next);
SmartFreeObject(Cur);
Cur := Next;
end;
SmartFreeObject(Cur);
SmartFreeObject(Tail);
SmartFreeObject(List);
end;
SmartFreeObject(Nodes);
end;