Widget
2008-08-07 04:22:38
I've kept telling Wizzup and myself that I'd clean up all the useless/overly-specific functions in the reflection include, so now I'm finally doing it, but I'm at a loss for what people would actually use.
So basically, I'm making a poll, pick the parts that you think should be in the include, and [please :)] post why you think they should be kept and maybe good uses for them, or suggest new things to add/rewrite.
//------------------------------------------------------------------\\
//-- Scar Non-Standard Resource Library --||
//-- » Reflection Routines - Walking --||
//------------------------------------------------------------------//
// * Function DistanceFrom(TileX, TileY: Integer) : Integer; // * by Widget
// * Function ClickTile(TileX, TileY, Height : Integer; // * by ss23 and Widget
// Left : Boolean) : Boolean; // º
// * Function WalkToTile(TileX, TileY : Integer): Boolean; // * by ss23 and Widget
// * Function WalkToTileTol(TileX, TileY, Tol : Integer): Boolean; // * by ss23 and Widget and TheGuyWhoGotOn
// * Function AlmostThere: Boolean; // * by TheGuyWhoGotOn
// * function LongWalkEx(TileX, TileY, DisX, DisY, // * by TheGuyWhoGotOn
// * Tol : integer): boolean; // º
// * function LongWalk(TileX, TileY, Tol : integer): boolean; // * by TheGuyWhoGotOn
// * function PathWalk(Path : array of TPoint; Long : boolean; // * by TheGuyWhoGotOn
// * Tol : integer): Boolean; // º
// * Function GoToTile(XTile, YTile, FlagD: Integer): Boolean; // * by Timer
// * Function WalkPath(Path: TPointArray; StartTile, // * by Timer
// * FlagD: Integer): Boolean; // º
// * Function GetLowest(aVar: TIntegerArray): Integer; // * by Timer
// * Function GetHighest(aVar: TIntegerArray): Integer; // * by Timer
// * Function FindMeOnPath(Var aVar: Integer; Path: TPointArray; // * by Timer
// * LocateTo: Boolean): Boolean; // º
// * Function WalkThePath(Path: TPointArray): Boolean; // * by Timer
// * Function WalkToTileEx(TileX, TileY, XTRandom, YTRandom, // * by Nicbaz
// * FFlag : Integer): Boolean; // º
// * Function GerneratePath(StartTilePosX, StartTilePosY, TilePosX, // * by MasterKill
// * TilePosY: Integer): TPointArray; // * º
// * Function BlindWalkToTile(TilePosX, TilePosY): Boolean; // * by MasterKill
// * Procedure R_Flag; // * by Timer
// * procedure R_FFlag(Distance: Integer); // * ZephyrsFury
//------------------------------------------------------------------//
function GetFlag(var x, y: Integer): boolean; forward;
{*******************************************************************************
Function DistanceFrom(TileX, TileY: Integer) : Integer;
By: Widget
Description: Returns the distance between your player and the tile
*******************************************************************************}
Function DistanceFrom(TileX, TileY: Integer) : Integer;
Var
MyX,MyY : integer;
Begin
GetMyPos(MyX, MyY);
result := Distance(TileX, TileY, MyX, MyY);
end;
{*******************************************************************************
Function ClickTile(TileX, TileY, Height : Integer; Left : Boolean) : Boolean;
By: ss23 and Widget
Description: Clicks a tile. Height is the approximate heigh in pixels
Height doesnt matter if HighestAngle;
*******************************************************************************}
Function ClickTile(TileX, TileY, Height : Integer; Left : Boolean) : Boolean;
Var
x, y : Integer;
Begin
TileToMS(TileX, TileY, Height, x, y);
result := TileOnMs(x,y,height);
if not result then
Exit;
Mouse(x, y, 5, 5, False);
end;
{*******************************************************************************
procedure R_FFlag(Distance: Integer);
By: ZephyrsFury
Description: Similar to the original except it uses Reflection.
*******************************************************************************}
procedure R_FFlag(Dist: Integer);
var
Dx, Dy, Mx, My, Tx, Ty, m, d1, d2, w, h: Integer;
begin
while (GetFlag(Dx, Dy)) do
begin
GetMyPos(Mx, My);
w := (Dx - Mx) * 4;
h := (Dy - My) * 4;
d1 := Round(Sqrt(Sqr(w) + Sqr(h)));
if (d1 >= Dist) then
begin
Inc(m);
Wait(100);
if (Random(100) = 0) then IdleTime(500, 1000, 0.01);
if (m mod 100 = 0) then
if (d1 = d2) then
begin
if (FindColor(Tx, Ty, 255, MMX1, MMY1, MMX2, MMY2)) then
Mouse(Tx, Ty + 14, 0, 0, True)
else
Mouse(MMCX, MMCY, 0, 0, True);
end else d2 := d1;
end else Break;
end;
end;
{*******************************************************************************
Function - WalkToTile(TileX, TileY : Integer): Boolean;
By: ss23 and Widget
Description: Walks to the tile using minimap.
*******************************************************************************}
Function WalkToTile(TileX, TileY : Integer): Boolean;
Var
x, y : Integer;
Begin
TileToMinimap(Tilex, Tiley, x, y);
if not TileOnMM(TileX, TileY) then
begin
Writeln('Tile off minimap');
Result := False;
Exit;
end;
Mouse(x, y, 3, 3, True);
Result := True;
end;
{*******************************************************************************
Function - WalkToTileTol(TileX, TileY, Tol : Integer): Boolean;
By: ss23 and Widget and TheGuyWhoGotOn
Description: Walks to the tile using minimap and tolerance.
*******************************************************************************}
Function WalkToTileTol(TileX, TileY, Tol : Integer): Boolean;
Var
x, y : Integer;
Begin
TileToMinimap(Tilex, Tiley, x, y);
if not TileOnMM(TileX, TileY) then
begin
Writeln('Tile off minimap');
Result := False;
Exit;
end;
Mouse(x, y, Tol, Tol, True);
Result := True;
end;
{*******************************************************************************
Function - WalkToTileEx(TileX, TileY, XTRandom, YTRandom, FFlag : Integer): Boolean;
By: Nicbaz
Description: Walks to the tile using minimap and randomness + Flag
*******************************************************************************}
Function WalkToTileEx(TileX, TileY, XTRandom, YTRandom, FFlag : Integer): Boolean;
Var
x, y : Integer;
Begin
Walktotile(TileX+random(XTRandom),TileY+random(YTRandom));
R_FFlag(FFlag);
end;
{*******************************************************************************
Function - LongWalkEx(TileX, TileY, DisX, DisY, Tol : Integer): Boolean;
By: TheGuyWhoGotOn
Description: Walks to a far tile using the minimap and tolerance.
DisX/DisY is how many tiles it will move at a time.
*******************************************************************************}
function LongWalkEx(TileX, TileY, DisX, DisY, Tol : integer): boolean;
var TX, TY, DX, DY : integer;
begin
repeat
GetMyPos(TX, TY);
if ((DX) > (TileX - DisX)) and ((DX) < (TileX + DisX)) then else
if TileX > TX then DX := TX + DisX
else DX := TX - DisX;
if ((DY) > (-TileY - DisY)) and ((DY) < (TileY + DisY)) then else
if TileY > TY then DY := TY + DisY
else DY := TY - DisY;
WalkToTileTol(DX, DY, Tol);
repeat
Wait(1000 + Random(500));
until (Flag) or (not(CharacterMoving));
until (TileOnMM(TileX, TileY)) or (not(TileOnMM(DX, DY)));
Result := WalkToTileTol(TileX, TileY, Tol);
end;
{*******************************************************************************
Function - LongWalk(TileX, TileY, Tol : Integer): Boolean;
By: TheGuyWhoGotOn
Description: Walks to a far tile using the minimap and tolerance.
*******************************************************************************}
function LongWalk(TileX, TileY, Tol : integer): boolean;
begin
Result := LongWalkEx(TileX, TileY, 11, 11, Tol);
end;
{*******************************************************************************
Function - PathWalk(Path : array of TPoint; Long : boolean; Tol : integer): Boolean;
By: TheGuyWhoGotOn
Description: Walks a path for you with LongWalk options.
*******************************************************************************}
function PathWalk(Path : array of TPoint; Long : boolean; Tol : integer): Boolean;
var Count : integer;
begin
Count := 0;
repeat
if Long then Result := LongWalk(Path[Count].x, Path[Count].y, Tol)
else Result := WalkToTileTol(Path[Count].x, Path[Count].y, Tol);
repeat
Wait(1000 + Random(500));
until (Flag) or (not(CharacterMoving));
if not(Result) then
begin
WriteLn('Path walk failed');
Exit;
end;
Count := Count + 1;
until (not(Result)) or (Count = GetArrayLength(Path))
end;
{*******************************************************************************
Function GoToTile(XTile, YTile, FlagD: Integer): Boolean;
By: Timer
Description: If goes to the tile, results true, FFlags.
*******************************************************************************}
Function GoToTile(XTile, YTile, FlagD: Integer): Boolean;
Begin
Result := WalkToTile(XTile, YTile);
If (Not (Result)) Then
Exit;
FFlag(FlagD);
End;
{*******************************************************************************
Function WalkPath(Path: TPointArray; StartTile, FlagD: Integer): Boolean;
By: Timer
Description: Walks a path, if sucsess, results true.
*******************************************************************************}
Function WalkPath(Path: TPointArray; StartTile, FlagD: Integer): Boolean;
Var
H, I: Integer;
Begin
H := High(Path);
For I := StartTile To H Do
If (Not (GoToTile(Path[I].X, Path[I].Y, FlagD))) Then
Exit;
Result := True;
End;
{*******************************************************************************
Function GetLowest(aVar: TIntegerArray): Integer;
By: Timer
Description: Get the lowest integer.
*******************************************************************************}
Function GetLowest(aVar: TIntegerArray): Integer;
Var
H, I, T, Y: Integer;
Begin
H := High(aVar);
For I := 0 To H Do
If (aVar[I] > Y) Then
Begin
Y := aVar[I];
T := I;
End;
Result := T;
End;
{*******************************************************************************
Function GetHighest(aVar: TIntegerArray): Integer;
By: Timer
Description: Get the highest integer.
*******************************************************************************}
Function GetHighest(aVar: TIntegerArray): Integer;
Var
H, I, T, Y: Integer;
Begin
H := High(aVar);
For I := 0 To H Do
If (aVar[I] < Y) Then
Begin
Y := aVar[I];
T := I;
End;
Result := T;
End;
{*******************************************************************************
Function FindMeOnPath(Var aVar: Integer; Path: TPointArray; LocateTo: Boolean): Boolean;
By: Timer
Description: Finds your character on a specified path. Results True If Sucsess.
aVar is the tile.
*******************************************************************************}
Function FindMeOnPath(Var aVar: Integer; Path: TPointArray; LocateTo: Boolean): Boolean;
Var
I, H, X, Y: Integer;
D: TIntegerArray;
Begin
H := High(Path);
SetArrayLength(D, (H + 1));
GetMyPos(X, Y);
For I := 0 To H Do
D[I] := Distance(Path[I].X, Path[I].Y, X, Y);
H := GetLowest(D);
aVar := H;
If (LocateTo) Then
GoToTile(Path[H].X, Path[H].Y, 0);
Result := TileOnMM(Path[H].X, Path[H].Y);
End;
{*******************************************************************************
Function WalkThePath(Path: TPointArray): Boolean;
By: Timer
Description: Walks a path, start at beggining of the path..! :)
*******************************************************************************}
Function WalkThePath(Path: TPointArray): Boolean;
Var
I: Integer;
Begin
If (Not (WalkPath(Path, 0, 8))) Then
If (FindMeOnPath(I, Path, False)) Then
If (WalkPath(Path, I, 0)) Then
Result := True;
End;
{*******************************************************************************
Function GerneratePath(StartTilePosX, StartTilePosY, TilePosX,
TilePosY: Integer): TPointArray;
By: MasterKill
Description: Makes a path from star till end poss.
*******************************************************************************}
Function GerneratePath(StartTilePosX, StartTilePosY, TilePosX, TilePosY: Integer): TPointArray;
Var
I, XToWalk, YToWalk, RandX, RandY: Integer;
Begin
XToWalk := TilePosX - StartTilePosX;
YToWalk := TilePosY - StartTilePosY;
I := 0;
Repeat
RandX := Random(10);
RandY := Random(10);
If (XToWalk <> 0) Then
If (XToWalk > 0) Then
Begin
If (XToWalk > 65) Then
XToWalk := XToWalk - (55 + RandX)
Else
XToWalk := 0;
End Else
If (XToWalk > -65) Then
XToWalk := 0
Else
XToWalk := XToWalk + 55 + RandX;
If (YToWalk <> 0) Then
If (YToWalk > 0) Then
Begin
If (YToWalk > 65) Then
YToWalk := YToWalk - (55 + RandY)
Else
YToWalk := 0;
End Else
If (YToWalk < -65) Then
YToWalk := YToWalk + 55 + RandY
Else
YToWalk := 0;
SetArrayLength(Result, 1 + I);
Result[I] := IntToPoint(TilePosX - XToWalk, TilePosY - YToWalk);
If (XToWalk = 0) And (YToWalk = 0) Then Exit;
I := I + 1;
Until False
End;
{*******************************************************************************
Function BlindWalkToTile(TilePosX, TilePosY): Boolean;
By: MasterKill
Description: Makes a path from star till end poss.
*******************************************************************************}
Function BlindWalkToTile(TilePosX, TilePosY: Integer): Boolean;
Var
x, y: Integer;
WalkArray: TPointArray;
Begin
GetMyPos(X, Y);
WalkArray := GerneratePath(x, y, TilePosX, TilePosY);
Result := WalkThePath(WalkArray);
End;
{*******************************************************************************
Procedure R_Flag;
By: Timer
Description: Waits Till A COMPLETE Stop.
*******************************************************************************}
Procedure R_Flag;
Var
Ticker: Integer;
Begin
Ticker := (GetSystemTime + 30000);
While (CharacterMoving) Do
Begin
Wait(10 + Random(10));
If (GetSystemTime > Ticker) Then
Exit;
End;
Wait(500 + Random(50));
End;So basically, I'm making a poll, pick the parts that you think should be in the include, and [please :)] post why you think they should be kept and maybe good uses for them, or suggest new things to add/rewrite.