Naum
2009-11-30 17:00:49
….Hey…..
Since the new RadialWalkTolerance, by sexy c0hEn (:D), has been commited, by marpis, we can cut code. If we re-arrange stuff..
TO:
Whilst, we're at it - LinearWalkTolerance:
This also means we can shorten LinearWalk functions, considerably :):
TO:
The whole of MapWalk.Scar after that:
*fixed some labels
Voila, :
Oh yeah, and whilst we're at it:
http://www.villavu.com/forum/showthread.php?t=52626
http://www.villavu.com/forum/showthread.php?t=52185
^ Please take a look, it seems plausible :) ^
LOVE ALL OF YOU!
Since the new RadialWalkTolerance, by sexy c0hEn (:D), has been commited, by marpis, we can cut code. If we re-arrange stuff..
{*******************************************************************************
function RadialWalk(TheColor, StartRadial, EndRadial, Radius, Xmod, Ymod: Integer): Boolean;
By: Nielsie95
Description: Walks TheColor from StartRadial to EndRadial for Radius Distance
Valid Arguments:
TheColor: Any Color, but Road- or WaterColor will do fine :)
StartRadial/EndRadial: Any number between 0-720. 0=N,90=E,180=S,270=W.
Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
XMod, YMod: deviation from MouseFindFlag. -2 to 2.
*******************************************************************************}
function RadialWalk(TheColor, StartRadial, EndRadial, Radius, Xmod, Ymod: Integer): Boolean;
var
TPA: TPointArray;
I: Integer;
begin
Result := False;
if RadialWalkEx(tpa, MMCX, MMCY, TheColor, 0, StartRadial, EndRadial, Radius) then
for i := 0 to High(tpa) do
if MFNF(tpa[i].x, tpa[i].y, Xmod, Ymod) then
begin
FFlag(10);
Result := True;
Exit;
end;
end;
{*******************************************************************************
function RadialRoadWalk(TheColor, StartRadial, EndRadial, Radius, Xmod, Ymod: Integer): Boolean;
By: Nielsie95
Description: Walks TheColor from StartRadial to EndRadial for Radius Distance
Valid Arguments:
TheColor: RoadColor. RoadColor will be dynamically updated.
StartRadial/EndRadial: Any number between 0-720. 0=N,90=E,180=S,270=W.
Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
XMod, YMod: deviation from MouseFindFlag. -2 to 2.
*******************************************************************************}
function RadialRoadWalk(TheColor, StartRadial, EndRadial, Radius, Xmod, Ymod: Integer): Boolean;
var
tpa: TPointArray;
i: Integer;
begin
Result := False;
if (not LoggedIn) then exit;
if (RoadColorChecker) then
srl_Warn('RadialRoadWalk', 'Updated RoadColor through RoadColorChecker: ' +
IntToStr(RoadColor), warn_Debug);
if RadialWalkEx(tpa, MMCX, MMCY, TheColor, 0, StartRadial, EndRadial, Radius) then
for i := 0 to High(tpa) do
if MFNF(tpa[i].x, tpa[i].y, Xmod, Ymod) then
begin
FlagEx(10, True);
Result := True;
Break;
end;
If Result then
RoadColorChecker;
end;
TO:
{*******************************************************************************
function RadialWalkTolerance(Color, sRadial, eRadial, r, modX, modY, Tol: Integer): Boolean;
By: Coh3n
Description: Same as RadialWalk, but with a tolerance.
*******************************************************************************}
function RadialWalkTolerance(Color, sRadial, eRadial, r, modX, modY, Tol: Integer): Boolean;
var
TPA: TPointArray;
i, h: Integer;
begin
Result := False;
if RadialWalkEx(TPA, MMCX, MMCY, Color, Tol, sRadial, eRadial, r) then
begin
h := High(TPA);
for i := 0 to h do
if MFNF(TPA[i].x, TPA[i].y, modX, modY) then
begin
FFlag(10);
Result := True;
Exit;
end;
end;
end;
{*******************************************************************************
function RadialWalk(TheColor, StartRadial, EndRadial, Radius, Xmod, Ymod: Integer): Boolean;
By: Nielsie95
Description: Walks TheColor from StartRadial to EndRadial for Radius Distance
Valid Arguments:
TheColor: Any Color, but Road- or WaterColor will do fine :)
StartRadial/EndRadial: Any number between 0-720. 0=N,90=E,180=S,270=W.
Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
XMod, YMod: deviation from MouseFindFlag. -2 to 2.
*******************************************************************************}
Function RadialWalk(TheColor, StartRadial, EndRadial, Radius, Xmod, Ymod: Integer): Boolean;
Begin
Result := RadialWalkTolerance(TheColor, StartRadial, EndRadial, Radius, XMod, YMod, 0);
End;
{*******************************************************************************
function RadialRoadWalk(TheColor, StartRadial, EndRadial, Radius, Xmod, Ymod: Integer): Boolean;
By: Nielsie95
Description: Walks TheColor from StartRadial to EndRadial for Radius Distance
Valid Arguments:
TheColor: RoadColor. RoadColor will be dynamically updated.
StartRadial/EndRadial: Any number between 0-720. 0=N,90=E,180=S,270=W.
Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
XMod, YMod: deviation from MouseFindFlag. -2 to 2.
*******************************************************************************}
function RadialRoadWalk(TheColor, StartRadial, EndRadial, Radius, Xmod, Ymod: Integer): Boolean;
begin
Result := False;
if (not LoggedIn) then exit;
if (RoadColorChecker) then
srl_Warn('RadialRoadWalk', 'Updated RoadColor through RoadColorChecker: ' +
IntToStr(RoadColor), warn_Debug);
Result := RadialWalkTolerance(TheColor, StartRadial, EndRadial, Radius, XMod, YMod, 0);
If Result then
RoadColorChecker;
end;Whilst, we're at it - LinearWalkTolerance:
{*******************************************************************************
function LinearWalkTolerance(TheColor, Direction, Radius, Xmod, Ymod, Tol : Integer): Boolean;
By: Naum
Description: Same as LinearWalk, but with a tolerance.
*******************************************************************************}
function LinearWalkTolerance(TheColor, Direction, Radius, Xmod, Ymod, Tol : Integer): Boolean;
var
TPA: TPointArray;
i, h: Integer;
begin
Result := False;
if LinearWalkEx(TPA, MMCX, MMCY, TheColor, Tol, Direction, Radius) then
begin
h := High(TPA);
for i := 0 to h do
if MFNF(TPA[i].x, TPA[i].y, XMod, YMod) then
begin
FFlag(10);
Result := True;
Exit;
end;
end;
end;This also means we can shorten LinearWalk functions, considerably :):
{*******************************************************************************
function LinearWalk(TheColor, Direction, Radius, Xmod, Ymod: Integer): Boolean;
By: Nielsie95
Description: Walks TheColor from Direction MIDDLE OUT!by performing windscreenlike scanning movements for Radius Distance
Valid Arguments:
TheColor: Any Color, but Road- or WaterColor will do fine :)
Direction: Any number between 0-720. 0=N,90=E,180=S,270=W.
Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
XMod, YMod: deviation from MouseFindFlag. -2 to 2.
*******************************************************************************}
function LinearWalk(TheColor, Direction, Radius, Xmod, Ymod: Integer): Boolean;
var
TPA: TPointArray;
I: Integer;
begin
Result := False;
if LinearWalkEx(tpa, MMCX, MMCY, TheColor, 0, Direction, Radius) then
for i := 0 to High(tpa) do
if MFNF(tpa[i].x, tpa[i].y, Xmod, Ymod) then
begin
FFlag(10);
Result := True;
Break;
end;
end;
{*******************************************************************************
function LinearRoadWalk(TheColor: Integer; Direction: Integer; Radius: Integer; Xmod, Ymod: Integer): Boolean;
By: Nielsie95
Description: Walks TheColor from Direction MIDDLE OUT!by performing windscreenlike scanning movements for Radius Distance
Valid Arguments:
TheColor: Any Color, but Road- or WaterColor will do fine :)
Direction: Any number between 0-720. 0=N,90=E,180=S,270=W.
Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
XMod, YMod: deviation from MouseFindFlag. -2 to 2.
*******************************************************************************}
function LinearRoadWalk(TheColor: Integer; Direction: Integer; Radius: Integer; Xmod, Ymod: Integer): Boolean;
var
tpa: TPointArray;
i: Integer;
begin
Result := False;
if (not LoggedIn) then exit;
if (RoadColorChecker) then
srl_Warn('LinearRoadWalk', 'Updated RoadColor through RoadColorChecker: ' +
IntToStr(RoadColor), warn_Debug);
if LinearWalkEx(tpa, MMCX, MMCY, TheColor, 0, Direction, Radius) then
for i := 0 to High(tpa) do
if MFNF(tpa[i].x, tpa[i].y, Xmod, Ymod) then
begin
FlagEx(10, True);
Result := True;
Break;
end;
if (Result) then
RoadColorChecker;
end;
TO:
{*******************************************************************************
function LinearWalkTolerance(TheColor, Direction, Radius, Xmod, Ymod: Integer): Boolean;
By: Naum
Description: Same as LinearWalk, but with a tolerance.
*******************************************************************************}
function LinearWalkTolerance(TheColor, Direction, Radius, Xmod, Ymod: Integer; Tol : Integer): Boolean;
var
TPA: TPointArray;
i, h: Integer;
begin
Result := False;
if LinearWalkEx(TPA, MMCX, MMCY, TheColor, Tol, Direction, Radius) then
begin
h := High(TPA);
for i := 0 to h do
if MFNF(TPA[i].x, TPA[i].y, XMod, YMod) then
begin
FFlag(10);
Result := True;
Exit;
end;
end;
end;
{*******************************************************************************
function LinearWalk(TheColor, Direction, Radius, Xmod, Ymod: Integer): Boolean;
By: Nielsie95
Description: Walks TheColor from Direction MIDDLE OUT!by performing windscreenlike scanning movements for Radius Distance
Valid Arguments:
TheColor: Any Color, but Road- or WaterColor will do fine :)
Direction: Any number between 0-720. 0=N,90=E,180=S,270=W.
Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
XMod, YMod: deviation from MouseFindFlag. -2 to 2.
*******************************************************************************}
function LinearWalk(TheColor, Direction, Radius, Xmod, Ymod: Integer): Boolean;
begin
Result := LinearWalkTolerance(TheColor, Direction, Radius, XMod, YMod, 0);
end;
{*******************************************************************************
function LinearRoadWalk(TheColor: Integer; Direction: Integer; Radius: Integer; Xmod, Ymod: Integer): Boolean;
By: Nielsie95
Description: Walks TheColor from Direction MIDDLE OUT!by performing windscreenlike scanning movements for Radius Distance
Valid Arguments:
TheColor: Any Color, but Road- or WaterColor will do fine :)
Direction: Any number between 0-720. 0=N,90=E,180=S,270=W.
Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
XMod, YMod: deviation from MouseFindFlag. -2 to 2.
*******************************************************************************}
function LinearRoadWalk(TheColor: Integer; Direction: Integer; Radius: Integer; Xmod, Ymod: Integer): Boolean;
begin
Result := False;
if (not LoggedIn) then exit;
if (RoadColorChecker) then
srl_Warn('LinearRoadWalk', 'Updated RoadColor through RoadColorChecker: ' +
IntToStr(RoadColor), warn_Debug);
Result := LinearWalkTolerance(TheColor, Direction, Radius, XMod, YMod, 0);
if (Result) then
RoadColorChecker;
end;The whole of MapWalk.Scar after that:
*fixed some labels
//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- ยป MapWalking Routines --//
//-----------------------------------------------------------------//
// * function MakeCompass(Direction: string): Boolean; // * by nielsie95
// * procedure SetAngle(Highest : Boolean); // * by Raymond, edit by NaumanAkhlaQ
// * procedure ClickNorth(AngleHigh: boolean); // * by R1ch
// * function GetWallAngle(Ps: TPointArray): Extended; // * by Wizzup?
// * procedure RunAway(dir: string; RunFar: Boolean; Action, WaitTime: Integer); // * by nielsie95, modified by ZephyrsFury
// * procedure StoreToRoadColorArray; // * by Wizzup? / WT-Fakawi, rewritten by EvilChicken!
// * function GetOldRoadColors: Boolean; // * by Wizzup? / WT-Fakawi, edited by EvilChicken!
// * function GetNewRoadColor(xs, ys, xe, ye, tol: Integer): Boolean; // * by Wizzup? / WT-Fakawi, edited by Ron & EvilChicken!
// * function RoadColorChecker: Boolean; // * by Wizzup? / WT-Fakawi, edited by Ron & EvilChicken!
// * function LinearWalkEx(var TPA: TPointArray; cx, cy, TheColor, tol, Direction, Radius: Integer): Boolean; // * by nielsie95
// * function RadialWalkEx(var TPA: TPointArray; cx, cy, TheColor, tol, StartRadial, EndRadial, Radius: Integer): Boolean; // * by nielsie95
// * function RadialWalkTolerance(TheColor, StartRadial, EndRadial, Radius, Xmod, Ymod, Tol: Integer): Boolean // * by Coh3n
// * function LinearWalkTolerance(TheColor, Direction, Radius, Xmod, Ymod, Tol : Integer): Boolean; // * by Naum
// * function RadialWalk(TheColor, StartRadial, EndRadial, Radius, Xmod, Ymod: Integer): Boolean; // * by nielsie95
// * function LinearWalk(TheColor, Direction, Radius, Xmod, Ymod: Integer): Boolean; // * by nielsie95 re-written by Naum
// * function RadialRoadWalk(TheColor, StartRadial, EndRadial, Radius, Xmod, Ymod: Integer): Boolean; // * by nielsie95
// * function LinearRoadWalk(TheColor: Integer; Direction: Integer; Radius: Integer; Xmod, Ymod: Integer): Boolean; // * by nielsie95
// * function WaterWalk(StartRadial, EndRadial, Radius, FFlagBreakOut, Xoff, Yoff, Xmod, Ymod: Integer): Boolean; // * by nielsie95
// * function GetMiniMapDotsIn(WhatDot: String; x1, y1, x2, y2: Integer): TPointArray; // * by footballjds, NaumanAklaQ, Nava2 & Cazax
// * function GetMiniMapDots(WhatDot: String): TPointArray; // * by Nava2
// * function CountMiniMapDots(WhatDot: String): integer; // * by Nava2
// * procedure MouseMM(x, y, randX, randY: Integer); // * by mixster
//-----------------------------------------------------------------//
{*******************************************************************************
var RoadColors: TIntegerArray;
Description: Global record containing all roadcolors collected during runtime.
*******************************************************************************}
var
RoadColors: TIntegerArray;
{*******************************************************************************
function MakeCompass(Direction: Variant): Boolean;
By: Nielsie95 & Nava2
Description: Aligns RS to specified direction
direction: Enter a compass angle ('n', 's', 'e', 'w') or degree (23.3, 25, 205.2)
and it will move the compass to that angle. Also accepts 'random',
and 'rand' to make the compass a random direction.
*******************************************************************************}
function MakeCompass(Direction: Variant): Boolean;
var
StartAngle, Angle, DirectionDeg, i: Extended;
Left: Boolean;
Mark: Integer;
begin
Result := False;
StartAngle := (rs_GetCompassAngleDegrees);
if (StartAngle < 0) or (not LoggedIn) then Exit;
case VarType(Direction) of
3, 5: DirectionDeg := FixD(Direction + 0.0);
256: try
DirectionDeg := FixD(StrToFloat(Direction));
except
case LowerCase(Direction) of
'n': DirectionDeg := 0;
'w': DirectionDeg := 270;
's': DirectionDeg := 180;
'e': DirectionDeg := 90;
'random', 'rand': DirectionDeg := RandomRange(0, 360);
end;
end;
end;
if (MinE(Abs(StartAngle - DirectionDeg), MinE(Abs(StartAngle - (DirectionDeg + 360)), Abs((StartAngle + 360) - DirectionDeg)))) <= 8.0 then
begin
Result := True;
Exit;
end;
Left := (Round((360 - StartAngle) + DirectionDeg) mod 360 <= Round((StartAngle + 360) - DirectionDeg) mod 360);
KeyDown((Integer(not Left) * 2) + 37);
Wait(10);
MarkTime(Mark);
repeat
Wait(1);
Angle:= rs_GetCompassAngleDegrees;
if ((TimeFromMark(Mark) > 6000) and (i < 1.0)) or
((TimeFromMark(Mark) > 10000) and (i < 2.0)) or
((TimeFromMark(Mark) > 14000) and (i < 3.0)) then
begin
i := i + 1.0;
end;
until ((MinE(Abs(Angle - DirectionDeg), MinE(Abs(Angle - (DirectionDeg + 360)), Abs((Angle + 360) - DirectionDeg)))) <= (7.0 + i))
or (TimeFromMark(Mark) > 14000)
or (Angle < 0);
if Left then
KeyUp(VK_Left)
else
KeyUp(VK_Right);
Wait(10);
Result := ((MinE(Abs(Angle - DirectionDeg), MinE(Abs(Angle - (DirectionDeg + 360)), Abs((Angle + 360) - DirectionDeg)))) <= (7.0 + i));
end;
{*******************************************************************************
procedure SetAngle(Highest : Boolean);
By: Raymond, edit by NaumanAkhlaQ
Description: Sets the mainscreen at highest\lowest angle (Depends on the boolean)
*******************************************************************************}
procedure SetAngle(Highest : Boolean);
begin
if (not LoggedIn) then exit;
KeyDown((Integer(not Highest) * 2) + 38);
Sleep(1000 + Random(300));
KeyUp((Integer(not Highest) * 2) + 38);
Wait(500 + Random(100));
end;
{*******************************************************************************
procedure ClickNorth(AngleHigh : boolean);
By: R1ch
Description: Clicks the compass to make it perfect North. Will set angle at
highest depending on AngleHigh
*******************************************************************************}
procedure ClickNorth(AngleHigh: boolean);
begin
if Random(4) = 1 then
begin
Mouse(542, 24, 15, 15, False);
WaitOptionMulti(['ace', 'orth'], 1200);
end else
Mouse(542, 24, 15, 15, True);
SetAngle(AngleHigh);
end;
{$DEFINE WALL_ANGLELEFT}
{*******************************************************************************
Function GetWallAngle(Ps: TPointArray): Extended;
by: Wizzup?
Description: Get's the Minimap angle using Walls. Returns Angle in Radians.
Used in Maze.scar, but feel free to use for Perfect map aligning projects.
*******************************************************************************}
Function GetWallAngle(Ps: TPointArray): Extended;
Var
L, I, C: Integer;
ATPA, gATPA: T2DPointArray;
P, P2: TPoint;
B: TBox;
Begin
Result := -1.0;
If High(Ps) = -1 Then
Exit;
SortTPAFrom(Ps, Point((550 + 703) / 2, 0)); // Sort it from the center.
{$IFDEF WALL_ANGLELEFT}
ATPA := SplitTPAEx(Ps, 0, 1); // This turns a PointArray into
// vertical lines
{$ELSE}
ATPA := SplitTPAEx(Ps, 1, 0); //horizontal lines
{$ENDIF}
SortATPASize(ATPA, True); // longest 'line'.
L := High(aTPA);
If L = -1 Then
Exit;
SetLength(gATPA, L + 1);
C := 1;
gATPA[0] := aTPA[0];
P := MiddleTPA(aTPA[0]); // get middle of the line.
For I := 1 To L Do
Begin // this loops adds any points that are in a dist of 10 pixels.
// if vert, then x, hori then y (A wall isn't straight.)
If Length(aTPA[I]) < 4 Then
Continue;
P2 := MiddleTPA(aTPA[I]);
{$IFDEF WALL_ANGLELEFT} If Abs(P.X - P2.X) < 10 Then
{$ELSE} If Abs(P.Y - P2.Y) < 10 Then {$ENDIF}
Begin
gATPA[C] := aTPA[I];
C := C + 1;
End;
End;
SetLength(gATPA, C);
SetLength(Ps, 0);
Ps := MergeATPA(gATPA); //Combine all the points. within 10pix
B := GetTPABounds(Ps);
SortTPAFrom(Ps, Point((B.X1 + B.X2) / 2, 0)); // sort from center
SetLength(ATPA, 0);
ATPA := SplitTPA(Ps, 3); // split dist three, the left over walls
// were all in Ps, and now we split them again.
SetLength(Ps, 0);
SortATPASize(ATPA, True); // longest wall.
Ps := ATPA[0];
L := High(Ps); //angle getting
Result := ArcTan2(Ps[L].Y -Ps[0].Y, Ps[L].X - Ps[0].X) - (Pi * 0.5);
{$IFDEF WALL_ANGLELEFT} {$ELSE} Result := Result + 0.5 * Pi {$ENDIF}
End;
{*******************************************************************************
procedure RunAway(dir: string; RunFar: Boolean; Action, WaitTime: Integer);
By: nielsie95 modified by ZephyrsFury
Description: Runs away in minimap related direction, based on north.
Dir can be 'N', 'E', 'S', 'W' or an angle in degrees (145, 93, 180, etc).
RunFar will run further than normal.
Action can be either 1, 2 or 3.
1: RunAway + Wait(WaitTime) + RunBack
2: RunAway + Wait(WaitTime)
3: RunBack
Note: WaitTime is in milliseconds!
*******************************************************************************}
procedure RunAway(dir: string; RunFar: Boolean; Action, WaitTime: Integer);
var
Rad, Deg, T: Integer;
begin
if (not LoggedIn) then exit;
if RunFar then
Rad := 63
else Rad := 30;
case UpperCase(dir) of
'N': Deg := 0;
'E': Deg := 90;
'S': Deg := 180;
'W': Deg := 270;
else
Deg := StrToIntDef(Dir, -1);
end;
if (Deg = -1) then
begin
srl_Warn('RunAway', '' + Dir + ' is not a valid direction.', warn_AllVersions);
Exit;
end;
if (Action < 3) then
begin
SetRun(True);
MFNF(Trunc(Rad * Sin(Radians(FixD(Rs_GetCompassAngleDegrees + Deg))) + MMCX + Random(5)),
Trunc(-Rad * Cos(Radians(FixD(Rs_GetCompassAngleDegrees + Deg))) + MMCY + Random(5)), 1, 1);
FFlag(0);
Wait(500 + Random(1500));
t := GetSystemTime;
while ((GetSystemTime - t) < WaitTime) and (LoggedIn) do
if (Random(5) = 0) then
IdleTime(2000, 500, 1.0)
else
Wait((WaitTime - (GetSystemTime - t)) / 5);
end;
if (Action = 1) or (Action = 3) then
begin
MFNF(Trunc(Rad * Sin(Radians(FixD(Rs_GetCompassAngleDegrees + (Deg + 180)))) + MMCX - Random(5)),
Trunc(-Rad * Cos(Radians(FixD(Rs_GetCompassAngleDegrees + (Deg + 180)))) + MMCY - Random(5)), 1, 1);
FFlag(0);
Wait(500 + Random(1500));
end;
SetRun(False);
end;
{*******************************************************************************
procedure StoreToRoadColorArray;
By: Wizzup? / WT-Fakawi, rewritten by EvilChicken!
Description: Stores RoadColor to an array. Debugging and logging purposes.
*******************************************************************************}
procedure StoreToRoadColorArray;
var
Hi: Integer;
begin
if (InIntArray(RoadColors, RoadColor)) then exit;
Hi := High(RoadColors);
SetLength(RoadColors, Hi + 2)
RoadColors[Hi + 1] := RoadColor;
end;
{*******************************************************************************
function GetOldRoadColors: Boolean;
By: Wizzup? / WT-Fakawi, edited by EvilChicken!
Description: Checks if RoadColor matches with any color stored in RoadColors
array. If successful, it sets the roadcolor.
*******************************************************************************}
function GetOldRoadColors: Boolean;
var
I, X, Y, Hi: Integer;
begin
Result := False;
Hi := High(RoadColors);
for I := 0 to Hi do
if FindColorTolerance(X, Y, RoadColors[I], MMX1, MMY1, MMX2, MMY2, 10) then
begin
RoadColor := GetColor(X, Y);
if (not InIntArray(RoadColors, RoadColor)) then
begin
SetLength(RoadColors, Hi + 2);
RoadColors[Hi + 1] := RoadColor;
end;
srl_Warn('GetOldRoadColors', 'Set RoadColor through RoadColors array.', warn_Debug);
Result := True;
Exit;
end;
end;
{*******************************************************************************
function GetNewRoadColor(xs, ys, xe, ye, tol: Integer): Boolean;
By: Wizzup?/WT-Fakawi, edited by Ron & EvilChicken!
Description: Searches for new RoadColor in box xs, ys, xe, ye by comparing
all the colors found within box against current RoadColor.
*******************************************************************************}
function GetNewRoadColor(xs, ys, xe, ye, Tol: Integer): Boolean;
var
X, Y, W, H, Bmp: Integer;
TC: TColor;
begin
if (not LoggedIn) then exit;
if (XS > XE) then
begin
srl_Warn('GetNewRoadColor', 'Seachbox coordinates error - XS:' + IntToStr(XS) +
', XE: ' + IntToStr(XE), warn_Warning);
Exit;
end;
if (YS > YE) then
begin
srl_Warn('GetNewRoadColor', 'Seachbox coordinates error - YS:' + IntToStr(YS) +
', YE: ' + IntToStr(YE), warn_Warning);
Exit;
end;
w := xe - xs;
h := ye - ys;
try
Bmp := BitmapFromString(w, h, '');
SafeCopyCanvas(GetClientCanvas, GetBitmapCanvas(Bmp), xs, ys, xe, ye, 0, 0, w, h)
except
GetClientDimensions(w, h);
srl_Warn('RadialRoadWalk', 'An error occured. ' + 'xs: ' + IntToStr(xs) +
', ys: ' + IntToStr(ys) + ', xe: ' + IntToStr(xe) + ', ye: ' + IntToStr(ye), warn_AllVersions);
srl_Warn('RadialRoadWalk', 'Client area is 0, 0, ' + IntToStr(w) + ', ' +
IntToStr(h), warn_AllVersions);
FreeBitmap(Bmp);
Exit;
end;
for Y := 1 to H do
for X := 1 to W do
begin
TC := FastGetPixel(Bmp, X, Y);
if SimilarColors(TC, RoadColor, Tol) then
begin
RoadColor := TC;
StoreToRoadColorArray;
Result := True;
FreeBitmap(Bmp);
Exit;
end
end;
FreeBitmap(Bmp);
end;
{*******************************************************************************
function RoadColorChecker: Boolean;
By: Wizzup?/WT-Fakawi, edited by Ron & EvilChicken!
Description: Checks for presence of RoadColor. If none is found, it will try
various methods to find it. If successful, it sets RoadColor to the new color.
*******************************************************************************}
function RoadColorChecker: Boolean;
var
I, X, Y: Integer;
begin
Result := False;
if (not LoggedIn) or (FindColor(X, Y, RoadColor, MMX1 + 20, MMY1 + 20, MMX2 - 20, MMY2 - 20)) then exit;
for I := 0 to 2 do
begin
case I of
0: if (FindColor(X, Y, 3026478, MMX1, MMY1, MMX2, MMY2)) then
Result := GetNewRoadColor(X - 14, Y - 14, X + 14, Y + 14, 10);
1: Result := (GetNewRoadColor(MMCX - 20, MMCY - 20, MMCX + 20, MMCY + 20, 10));
2: Result := GetOldRoadColors;
end;
if (Result) then
begin
case I of
0: srl_Warn('RoadColorChecker', 'Found RoadColor through flag: ' + IntToStr(RoadColor), warn_Debug);
1: srl_Warn('RoadColorChecker', 'Found RoadColor through minimap: ' + IntToStr(RoadColor), warn_Debug);
2: srl_Warn('RoadColorChecker', 'Found RoadColor through GetOldRoadColors: ' + IntToStr(RoadColor), warn_Debug);
end;
Exit;
end else
if (I = 2) then
srl_Warn('RoadColorChecker', 'Couln''t find RoadColor', warn_Warning);
end;
end;
{*******************************************************************************
function LinearWalkEx(var TPA: TPointArray; cx, cy, TheColor, tol, Direction, Radius: Integer): Boolean;
By: Nielsie95
Description: Finds TheColor from Radial (scanning outwards) for Radius Distance.
Valid Arguments:
tpa: Result points.
Direction: Any number between 0-720. 0=N,90=E,180=S,270=W.
Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
*******************************************************************************}
function LinearWalkEx(var TPA: TPointArray; cx, cy, TheColor, tol, Direction, Radius: Integer): Boolean;
var
i, SD, ED: Integer;
begin
Result := False;
if (not LoggedIn) then Exit;
i := GetSystemTime;
Direction := Direction mod 360;
if (Direction < 50) then
SD := ((Direction + 360) - 50)
else
SD := (Direction - 50);
ED := (Direction + 50);
SD := Trunc(FixD(SD + 0.0));
ED := Trunc(FixD(ED + 0.0));
try
FindColorsTolerance(tpa, TheColor, MMX1, MMY1, MMX2, MMY2, tol);
FilterPointsPie(tpa, SD, ED, 10, Radius, cx, cy);
LinearSort(tpa, cx, cy, Direction, False);
Result := (Length(tpa) > 0);
except
srl_Warn('LinearWalkEx', 'LWex error!', warn_AllVersions);
Exit;
end;
srl_Warn('LinearWalkEx', 'Took ' + IntToStr(GetSystemTime - i) + ' ms, found ' +
IntToStr(Length(TPA)) + 'points.', warn_Debug);
end;
{*******************************************************************************
function RadialWalkEx(var TPA: TPointArray; cx, cy, TheColor, tol, StartRadial, EndRadial, Radius: Integer): Boolean;
By: Nielsie95
Description: Finds TheColor from StartRadial to EndRadial for Radius Distance.
Valid Arguments:
tpa: Result points.
StartRadial/EndRadial: Any number between 0-720. 0=N,90=E,180=S,270=W.
Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
*******************************************************************************}
function RadialWalkEx(var TPA: TPointArray; cx, cy, TheColor, tol, StartRadial, EndRadial, Radius: Integer): Boolean;
var
i, SD, ED: Integer;
begin
Result := False;
SD := StartRadial;
ED := EndRadial;
if (SD = ED) then
begin
srl_Warn('RadialWalkEx', 'StartRadial = EndRadial, using LinearWalkEx.', warn_Warning);
Result := LinearWalkEx(tpa, cx, cy, TheColor, tol, StartRadial, Radius);
end;
if (SD > ED) then
Swap(SD, ED);
SD := Trunc(FixD(SD + 0.0));
ED := Trunc(FixD(ED + 0.0));
if (not LoggedIn) then Exit;
i := GetSystemTime;
try
FindColorsTolerance(tpa, TheColor, MMX1, MMY1, MMX2, MMY2, tol);
FilterPointsPie(tpa, SD, ED, 10, Radius, cx, cy);
SortCircleWise(tpa, cx, cy, StartRadial, False, StartRadial > EndRadial);
Result := (Length(tpa) > 0);
except
srl_Warn('RadialWalkEx', 'An exception has occured', warn_AllVersions); Exit;
end;
srl_Warn('RadialWalkEx', 'Took ' + IntToStr(GetSystemTime - i) +
' ms, found' + IntToStr(Length(TPA)) + ' points', warn_Debug);
end;
{*******************************************************************************
function RadialWalkTolerance(Color, sRadial, eRadial, r, modX, modY, Tol: Integer): Boolean;
By: Coh3n
Description: Same as RadialWalk, but with a tolerance.
*******************************************************************************}
function RadialWalkTolerance(Color, sRadial, eRadial, r, modX, modY, Tol: Integer): Boolean;
var
TPA: TPointArray;
i, h: Integer;
begin
Result := False;
if RadialWalkEx(TPA, MMCX, MMCY, Color, Tol, sRadial, eRadial, r) then
begin
h := High(TPA);
for i := 0 to h do
if MFNF(TPA[i].x, TPA[i].y, modX, modY) then
begin
FFlag(10);
Result := True;
Exit;
end;
end;
end;
{*******************************************************************************
function LinearWalkTolerance(TheColor, Direction, Radius, Xmod, Ymod, Tol: Integer): Boolean;
By: Naum
Description: Same as LinearWalk, but with a tolerance.
*******************************************************************************}
function LinearWalkTolerance(TheColor, Direction, Radius, Xmod, Ymod, Tol: Integer): Boolean;
var
TPA: TPointArray;
i, h: Integer;
begin
Result := False;
if LinearWalkEx(TPA, MMCX, MMCY, TheColor, Tol, Direction, Radius) then
begin
h := High(TPA);
for i := 0 to h do
if MFNF(TPA[i].x, TPA[i].y, XMod, YMod) then
begin
FFlag(10);
Result := True;
Exit;
end;
end;
end;
{*******************************************************************************
function RadialWalk(TheColor, StartRadial, EndRadial, Radius, Xmod, Ymod: Integer): Boolean;
By: Nielsie95
Description: Walks TheColor from StartRadial to EndRadial for Radius Distance
Valid Arguments:
TheColor: Any Color, but Road- or WaterColor will do fine :)
StartRadial/EndRadial: Any number between 0-720. 0=N,90=E,180=S,270=W.
Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
XMod, YMod: deviation from MouseFindFlag. -2 to 2.
*******************************************************************************}
Function RadialWalk(TheColor, StartRadial, EndRadial, Radius, Xmod, Ymod: Integer): Boolean;
Begin
Result := RadialWalkTolerance(TheColor, StartRadial, EndRadial, Radius, XMod, YMod, 0);
End;
{*******************************************************************************
function LinearWalk(TheColor, Direction, Radius, Xmod, Ymod: Integer): Boolean;
By: Nielsie95
Description: Walks TheColor from Direction MIDDLE OUT!by performing windscreenlike scanning movements for Radius Distance
Valid Arguments:
TheColor: Any Color, but Road- or WaterColor will do fine :)
Direction: Any number between 0-720. 0=N,90=E,180=S,270=W.
Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
XMod, YMod: deviation from MouseFindFlag. -2 to 2.
*******************************************************************************}
function LinearWalk(TheColor, Direction, Radius, Xmod, Ymod: Integer): Boolean;
begin
Result := LinearWalkTolerance(TheColor, Direction, Radius, XMod, YMod, 0);
end;
{*******************************************************************************
function RadialRoadWalk(TheColor, StartRadial, EndRadial, Radius, Xmod, Ymod: Integer): Boolean;
By: Nielsie95
Description: Walks TheColor from StartRadial to EndRadial for Radius Distance
Valid Arguments:
TheColor: RoadColor. RoadColor will be dynamically updated.
StartRadial/EndRadial: Any number between 0-720. 0=N,90=E,180=S,270=W.
Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
XMod, YMod: deviation from MouseFindFlag. -2 to 2.
*******************************************************************************}
function RadialRoadWalk(TheColor, StartRadial, EndRadial, Radius, Xmod, Ymod: Integer): Boolean;
begin
Result := False;
if (not LoggedIn) then exit;
if (RoadColorChecker) then
srl_Warn('RadialRoadWalk', 'Updated RoadColor through RoadColorChecker: ' +
IntToStr(RoadColor), warn_Debug);
Result := RadialWalkTolerance(TheColor, StartRadial, EndRadial, Radius, XMod, YMod, 0);
If Result then
RoadColorChecker;
end;
{*******************************************************************************
function LinearRoadWalk(TheColor: Integer; Direction: Integer; Radius: Integer; Xmod, Ymod: Integer): Boolean;
By: Nielsie95
Description: Walks TheColor from Direction MIDDLE OUT!by performing windscreenlike scanning movements for Radius Distance
Valid Arguments:
TheColor: Any Color, but Road- or WaterColor will do fine :)
Direction: Any number between 0-720. 0=N,90=E,180=S,270=W.
Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
XMod, YMod: deviation from MouseFindFlag. -2 to 2.
*******************************************************************************}
function LinearRoadWalk(TheColor: Integer; Direction: Integer; Radius: Integer; Xmod, Ymod: Integer): Boolean;
begin
Result := False;
if (not LoggedIn) then exit;
if (RoadColorChecker) then
srl_Warn('LinearRoadWalk', 'Updated RoadColor through RoadColorChecker: ' +
IntToStr(RoadColor), warn_Debug);
Result := LinearWalkTolerance(TheColor, Direction, Radius, XMod, YMod, 0);
if (Result) then
RoadColorChecker;
end;
{*******************************************************************************
function WaterWalk(StartRadial, EndRadial, Radius, FFlagBreakOut, Xoff, Yoff, Xmod, Ymod: Integer): Boolean;
By: Nielsie95
Description: Walks alongside Water.
StartRadial/EndRadial := Any number between 0-720. 0=N,90=E,180=S,270=W.
Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
FFlagBreakOut: Distance to flag where it will break out. 15 - 10 is good.
Xoff, Yoff: Added to found point.
XMod, YMod: deviation from MouseFindFlag. -2 to 2.
*******************************************************************************}
function WaterWalk(StartRadial, EndRadial, Radius, FFlagBreakOut, Xoff, Yoff, Xmod, Ymod: Integer): Boolean;
var
tpa: TPointArray;
i: Integer;
begin
Result := False;
if RadialWalkEx(tpa, MMCX, MMCY, WaterColor, 0, StartRadial, EndRadial, Radius) then
for i := 0 to High(tpa) do
if MFNF(tpa[i].x + Xoff, tpa[i].y + Yoff, Xmod, Ymod) then
begin
FFLag(FFlagBreakOut);
Result := True;
Break;
end;
end;
{*******************************************************************************
function GetMiniMapDotsIn(WhatDot: String; x1, y1, x2, y2: Integer): TPointArray;
By: footballjds, NaumanAkhlaQ, Nava2 & Cazax
Description: Results the dots specified by WhatDot in x1, y1, x2, y2.
Usage : 'npc', 'yellow' : Yellow Dot;
'cape', 'blue' : Blue Dot;
'item', 'red' : Red Dot;
'player', 'white' : White Dot;
'friend', 'green' : Green Dot;
*******************************************************************************}
function GetMiniMapDotsIn(WhatDot: string; x1, y1, x2, y2: Integer): TPointArray;
var
Color: Integer;
begin
WhatDot := LowerCase(WhatDot);
case WhatDot Of
'npc', 'yellow': Color := 60909;
'cape', 'blue': Color := 12742980;
'item', 'red': Color := 789758;
'player', 'white': Color := 16711422;
'friend', 'green': Color := 61440;
else
srl_Warn('GetMiniMapDotsIn', '"' + WhatDot + '" is not a valid dot type', warn_AllVersions);
end;
FindColorsSpiralTolerance(MMCX, MMCY, Result, Color, x1, y1, x2, y2, 0);
RAaSTPA(Result, 4);
if (Length(Result) < 1) then Exit;
if (WhatDot = 'player') or (WhatDot = 'white') then
begin
InvertTPA(Result);
SetLength(Result, Length(Result) - 1);
InvertTPA(Result);
end;
end;
{*******************************************************************************
function GetMiniMapDots(WhatDot: String): TPointArray;
By: Nava2
Description: Results the dots specified by WhatDot on the Minimap. See GetMiniMapDots
in for more information.
*******************************************************************************}
function GetMiniMapDots(WhatDot: String): TPointArray;
begin
Result := GetMinimapDotsIn(WhatDot, MMX1, MMY1, MMX2, MMY2);
end;
{*******************************************************************************
function CountDots(WhatDot: String): integer;
By: Nava2
Description: Counts the occurance of WhatDot on the MiniMap. See GetMiniMapDots
in for more information.
*******************************************************************************}
function CountDots(WhatDot: String): integer;
begin
Result := Length(GetMinimapDots(WhatDot));
end;
{*******************************************************************************
procedure MouseMM(x, y, randX, randY: Integer);
By: mixster
Description: Clicks (x, y) on the MM, taking Map Angle into Account.
Be sure to choose the coords when Map Angle = 0 !
*******************************************************************************}
procedure MouseMM(x, y, randX, randY: Integer);
var
p: TPoint;
begin
if not rs_OnMinimap(x, y) then
exit;
p := RotatePoint(Point(x, y), rs_GetCompassAngleRadians, MMCX, MMCY);
Mouse(p.x, p.y, randX, randY, True);
end;Voila, :
Successfully compiled (4896 ms)Oh yeah, and whilst we're at it:
http://www.villavu.com/forum/showthread.php?t=52626
http://www.villavu.com/forum/showthread.php?t=52185
^ Please take a look, it seems plausible :) ^
LOVE ALL OF YOU!