Something I quickly threw together;
Simba Code:
function SecondClosestObj(IDs: TIntegerArray; objType, MaxDist: Integer): TRSObject;
var
i, j : Integer;
p, dest_tile : TTile;
dists : TIntegerArray;
t : TRSObjectArray;
obj_tiles : TPointArray;
begin
t := GetObjectsByIDEx(IDs, objType, MaxDist);
SetArrayLength(dists, GetArrayLength(t));
SetArrayLength(objs, GetArrayLength(t));
for i := 0 to High(t) do
obj_tiles[i] := t[i].Tile;
for i := 0 to High(obj_tiles) do
dists[i] := 500;
p := GetMyPos;
for i := 0 to High(obj_tiles) do
begin
if not TileOnMS(obj_tiles[i], 2) then
Continue;
dists[i] := Distance(p.x, p.y, obj_tiles[i].x, obj_tiles[i].y);
if i > 0 then
begin
if dists[i] < dists[i - 1] then
j := i;
end else
j := i;
end;
Result := t[j + 1];
end;
It'll sort the objects by distance, closest first, and then take the second closest (I hope :P). It's based off of my own function for finding the closest tree. Didn't test it yet.
For the non-interacting bit, you could save the tile of the rock you're currently mining as a global var and do something like...
Simba Code:
if (not TileOnMS(obj_tiles[i], 2)) and ((CurrentRockTile.x <> obj_tiles[i].x) and (CurrentRockTile.y <> obj_tiles[i].y)) then
Continue;