SRL Archive - Reflection Development

FurthestTile fix


Timer

2009-06-23 05:03:51

Result := Path[i]; should be Result := Path[index];

{*******************************************************************************
function FurthestTile(Path: TPointArray; MaxDist: integer): TPoint;
By: lordsaturn
Description: Gets the furthest tile in the array.
*******************************************************************************}
function FurthestTile(Path: TPointArray; MaxDist: integer): TPoint;
var
i, Hi, dist, mx, index: integer;
begin
Hi := High(Path);
if Hi < 0 then Exit;
index := -1;
for i := 0 to Hi do
begin
dist := DistanceFrom(Path[i]);
if (dist > mx) and (dist <= MaxDist) then
begin
mx := dist;
index := i;
end;
end;
if index > -1 then
Result := Path[index];
end;

mormonman

2009-06-23 06:06:29

That was the same thing that was wrong with the NearestTile… I guess I should have checked it too.