SRL Archive - Reflection Development

Some Walking Function


Phran6

2009-06-07 04:54:25

{*******************************************************}
{Description:will walk on main screen is tile apear on main screen else will walk on minimap}
{*******************************************************}


Function FH_WalkToTiles(x, y, Randomtile, FFlag : Integer) : Boolean;
var
N : TPoint;
begin
N:=point(x,y);
if TileOnMS(N, 0) then
Result := WalkToTileMs(N, Randomtile, FFlag)
else Result := WalkToTile(N, Randomtile, FFlag);
end;

{*******************************************************}
{Description:will make a square with the two point given and will result tpointarray in it of principal tpoint array in P.
Example you can do:

Gp:=GetMyPos;
TBT:=FH_TileBetween(Gp.x, Gp.y, xe, ye, P);

it will find all point in the tpointarray(P) between you and the other coord.
usefull for know witch tile is between you and the point you want reach.}
{*******************************************************}


Function FH_TileBetween(xs, ys, xe, ye:integer; P:Tpointarray): Array Of TPoint;
var
I:integer;
MaxX, MinX, MaxY, MinY:Integer;

begin
MaxX:=Max(xs,xe);
MinX:=Min(xs,xe);
MaxY:=Max(Ys,Ye);
MinY:=Min(Ys,Ye);

For I := 0 to High(P) do
begin
if InRange(p[I].x, minX, maxX) and InRange(p[I].y, minY,MinX ) then
begin
SetLength(result, Length(result) + 1);
result[High(result)] := p[I];
end;
end;

if length(result)=0 then writeln('No Tile Between');

end;

{*******************************************************}
{Description:it find the nearest tile in the tpointarray in Path from the point xe,ye}
{*******************************************************}

 
function FH_NearestTileFrom(Path: TPointArray; xe,ye: integer): TPoint;
var
i, Hi, dist, mn, index: integer;
begin
Hi := High(Path);
if Hi < 0 then Exit;
mn := Distance(path[0].x, path[0].y, xe, ye)
index := 0;
for i := 1 to Hi do
begin
dist := Distance(Path[I].x, Path[I].y, xe,ye);
if (dist < mn) then
begin
mn := dist;
index := i;
end;
end;
Result := Path[index];
end;

{*******************************************************}
{Description:It find the nearest tile on minimap from the point given in xe,ye in the tpointarray (P)}
{*******************************************************}

 
Function FH_FindBestTileToWalk(xe,ye:integer; P:Tpointarray): Tpoint;
var
Gp : tpoint;
Omm : Tpointarray;Function FH_FindBestTileToWalk(xe,ye:integer; P:Tpointarray): Tpoint;
var
Gp : tpoint;
Omm : Tpointarray;
I : Integer;
begin
Gp:=GetMyPos;
for I:=0 to High(P) do
begin
if TileOnMM(P[I]) then
begin
SetLength(Omm, Length(Omm) + 1);
Omm[High(Omm)] := P[I];
end;
end;
result:=NearestTileFrom(omm, xe,ye);
end;


I have not tested them but they should work :)

Leave comment plz