nielsie95
2007-04-28 14:40:29
Hello all,
Sometimes when I use Radial(Road)Walk it doesn't click on the road.
It clicks at the edge of the Road.. And when there's a fence at the side of the road, it will click on the fence which results in clicking near the fence and not on the road.
Well, here's my solution: RadialRoadWalkMiddle!
FindMiddle: Needed in FindMiddleOfTheRoad.
The procedure :)
Adjusted RadialWalkEx, now it looks for the middle of the Road.
Adjusted RadialRoadWalk, it will click on the middle of the road.
If you want to try this at home: I attached a little script. Set StartRadial, EndRadial, Radius and watch it walk 3 times on the middle of the road. :)
Sometimes when I use Radial(Road)Walk it doesn't click on the road.
It clicks at the edge of the Road.. And when there's a fence at the side of the road, it will click on the fence which results in clicking near the fence and not on the road.
Well, here's my solution: RadialRoadWalkMiddle!
FindMiddle: Needed in FindMiddleOfTheRoad.
{*******************************************************************************
function FindMiddle(var x, y: integer; Color, x1, y1, x2, y2: integer): Boolean;
By: Nielsie95
Description: Finds the middle of a color in the given box.
*******************************************************************************}
function FindMiddle(var x, y: integer; Color, x1, y1, x2, y2: integer): Boolean;
var MiddlePoints: TPointArray; TotalLength: integer;
begin
FindColorsTolerance(MiddlePoints, color, x1, y1, x2, y2, 0);
TotalLength := GetArrayLength(MiddlePoints);
if TotalLength > 0 then
begin
x := round((MiddlePoints[0].x + MiddlePoints[(TotalLength -1)].x) div 2);
y := round((MiddlePoints[0].y + MiddlePoints[(TotalLength -1)].y) div 2);
Result := True;
end else Result := false;
end;
The procedure :)
{*******************************************************************************
function FindMiddleOfTheRoad(var x, y: Integer; Radial, cx, cy, TheColor, Tol: integer): Boolean;
By: Nielsie95
Description: Finds the middle the road.
*******************************************************************************}
function FindMiddleOfTheRoad(var x, y: Integer; Radial, cx, cy, TheColor, Tol: integer): Boolean;
var Temp, Temp1, Temp2, Temp3, Temp4, Temp5: integer;
x1, y1, x2, y2: integer;
Direction: String;
begin
Temp1 := 90 - Radial if Temp1 < 0 then Temp1 := Radial - 90;
Temp2 := 180 - Radial if Temp2 < 0 then Temp2 := Radial - 180;
Temp3 := 270 - Radial if Temp3 < 0 then Temp3 :=Radial - 270;
Temp4 := Radial;
Temp5 := 360 - Radial;
Temp := Min(Min(Min(Temp1, Temp2), Min(Temp3, Temp4)), Temp5);
case Temp of
Temp1 : Direction := 'East'
Temp2 : Direction := 'South'
Temp3 : Direction := 'West'
Temp4 : Direction := 'North'
Temp5 : Direction := 'North'
end;
case Direction of
'East' : begin x1 := cx -3; y1 := cy -8; x2 := cx; y2 := cy +8; end;
'West' : begin x1 := cx; y1 := cy -8; x2 := cx +3; y2 := cy +8; end;
'South' : begin x1 := cx -8; y1 := cy -3; x2 := cx +8; y2 := cy; end;
'North' : begin x1 := cx -8; y1 := cy; x2 := cx +8; y2 := cy +3; end;
end;
//WriteLn(Direction);
//WriteLn('x1 :'+IntToStr(x1)+' y1 :'+IntToStr(y1)+' x2 :'+IntToStr(x2)+' y2 :'+IntToStr(y2))
Result := FindMiddle(x, y, TheColor, x1, y1, x2, y2);
if not Result then
begin
x := (x1 + x2) div 2;
y := (y1 + y2) div 2;
Result := True;
end
end;Adjusted RadialWalkEx, now it looks for the middle of the Road.
{*******************************************************************************
function MyRadialWalkEx(var x, y: Integer; cx, cy, TheColor, Tol, StartRadial, EndRadial, Radius: Integer): Boolean;
By: WT-Fakawi & Wizzup? --> Adjusted by Nielsie95
Description: Same as RadialWalkEx, but returns Coords of the Middle of the Road.
*******************************************************************************}
function MyRadialWalkEx(var x, y: Integer; cx, cy, TheColor, Tol, StartRadial, EndRadial, Radius: Integer): Boolean;
var
i, X1, Y1, tx, ty: Integer;
begin
Result := False;
if (StartRadial < EndRadial) then
begin
repeat
for i := StartRadial to EndRadial do
begin
x1 := Round(Radius * Sine(i)) + cx;
y1 := Round(-Radius * Cose(i)) + cy;
if FindColorTolerance(tx, ty, TheColor, X1, Y1, X1 + 1, Y1 + 1, tol) then
begin
//WriteLn('Radius: '+IntToStr(i));
//WriteLn('tx: '+IntToStr(tx)+' ty: '+IntToStr(ty))
Result := FindMiddleOfTheRoad(x, y, i, tx, ty, TheColor, Tol);
//WriteLn('x: '+IntToStr(x)+' y: '+IntToStr(y))
//WriteLn('Adjusted x: '+IntToStr(tx - x)+' + y: '+IntToStr(ty - y));
Exit;
end;
end;
Radius := Radius - 4;
until Radius <= 1;
end;
if (StartRadial > EndRadial) then
begin
repeat
for i := StartRadial downto EndRadial do
begin
x1 := Round(Radius * Sine(i)) + cx;
y1 := Round(-Radius * Cose(i)) + cy;
if (FindColorTolerance(tx, ty, TheColor, X1, Y1, X1 + 1, Y1 + 1, tol)) then
begin
Result := FindMiddleOfTheRoad(x, y, i, tx, ty, TheColor, Tol);
Exit;
end;
end;
Radius := Radius - 4;
until Radius <= 1;
end;
end;Adjusted RadialRoadWalk, it will click on the middle of the road.
{*******************************************************************************
function RadialRoadWalkMiddle(TheColor, StartRadial, EndRadial, Radius, Xmod, Ymod, FlagDist: integer): Boolean;
By: WT-Fakawi & Wizzup? --> Adjusted by Nielsie95
Description: Same as RadialRoadWalk, but clicks on the Middle of the Road.
*******************************************************************************}
function RadialRoadWalkMiddle(TheColor, StartRadial, EndRadial, Radius, Xmod, Ymod, FlagDist: integer): Boolean;
var mx, my: integer;
begin
if (RoadColorChecker) then if (DebugRadialRoad) then WriteLn(' THROUGH RADIALROADWALK= ---> ' + IntToStr(RoadColor));
if (MyRadialWalkEx(mx, my, MMCX, MMCY, TheColor, 0, StartRadial, EndRadial, Radius)) then
begin
MouseFindNoFlag(mx, my, Xmod, Ymod);
Result := True;
FFlag(FlagDist);
end;
end;If you want to try this at home: I attached a little script. Set StartRadial, EndRadial, Radius and watch it walk 3 times on the middle of the road. :)