putonajonny
2012-01-14 16:23:33
Returns The Areas that any path uses,
So something like:
Note this probably includes too many tiles and you may want to reduce the number.
function SPS_PathToAreas(Path : TPointArray) : TStringArray;
Var Xs, Ys, Xss, Yss, i, j : Integer; Areas : TPointArray; DoNot : Boolean;
begin
for i := 0 to high(Path) do
begin
Xs := Floor(Path[i].x/400);
Ys := Floor(Path[i].y/400);
if(GetArrayLength(Areas) = 0) then
begin
SetLength(Areas,GetArrayLength(Areas)+9)
Areas[0].x := Xs-1;
Areas[0].y := Ys-1;
Areas[1].x := Xs;
Areas[1].y := Ys-1;
Areas[2].x := Xs+1;
Areas[2].y := Ys-1;
Areas[3].x := Xs-1;
Areas[3].y := Ys;
Areas[4].x := Xs;
Areas[4].y := Ys;
Areas[5].x := Xs+1;
Areas[5].y := Ys;
Areas[6].x := Xs-1;
Areas[6].y := Ys+1;
Areas[7].x := Xs;
Areas[7].y := Ys+1;
Areas[8].x := Xs+1;
Areas[8].y := Ys+1;
end else
begin
for Yss := Ys-1 to Ys+1 do
begin
for Xss := Xs-1 to Xs+1 do
begin
for j := 0 to high(Areas) do
begin
if((Xss = Areas[j].x) and (Yss = Areas[j].y)) then
begin
DoNot := True;
end;
end;
if(not DoNot) then
begin
SetLength(Areas,GetArrayLength(Areas)+1)
Areas[High(Areas)].x := Xss;
Areas[High(Areas)].y := Yss;
end;
end;
end;
end;
Status(IntToStr(Floor(i*100/high(Path)))+'% Complete')
end;
SetLength(Result,GetArrayLength(Areas))
for i := 0 to high(Areas) do
Result[i] := IntToStr(Areas[i].x)+'_'+IntToStr(Areas[i].y);
end;So something like:
SPS_Areas := SPS_PathToAreas(myPath)can be called, fairly pointless function because I got frustrated with having to work out new areas every time I changed paths. Probably not the most efficient/best way of doing it but it does include nearby tiles.Note this probably includes too many tiles and you may want to reduce the number.