SRL Archive - Reflection Development

ClickTile / ClickTileBox


Bad Boy JH

2010-12-03 07:15:04

I don't know HOW important these procedures might be, but they may prove useful in such things as FishingSpot clicking, and the carpet in the demon random.

function InRangeBetter(Value, Border1, Border2: Integer): Boolean;
begin
Result := InRange(Value, Border1, Border2) or InRange(Value, Border2, Border1);
end;

function XToY(X: Integer; Point1, Point2: TPoint): Integer;
var
M: Extended;
begin
M := 1.0 * (Point2.y - Point1.y) / (Point2.x - Point1.x);
Result := Round((X - Point1.x) * M) + Point1.y;
end;

function PointInTriangle(ThePoint: TPoint; TrianglePoint1, TrianglePoint2, TrianglePoint3: TPoint): Boolean;
var
Error: Boolean;
begin
if not InRange(ThePoint.x, Min(Min(TrianglePoint1.x, TrianglePoint2.x), TrianglePoint3.x), Max(Max(TrianglePoint1.x, TrianglePoint2.x), TrianglePoint3.x)) then
Exit;
if ((TrianglePoint1.x < ThePoint.x) and (TrianglePoint2.x < ThePoint.x)) or ((TrianglePoint1.x > ThePoint.x) and (TrianglePoint2.x > ThePoint.x)) then
Result := InRangeBetter(ThePoint.y, XToY(ThePoint.x, TrianglePoint1, TrianglePoint3), XToY(ThePoint.x, TrianglePoint2, TrianglePoint3)) else
if ((TrianglePoint1.x < ThePoint.x) and (TrianglePoint3.x < ThePoint.x)) or ((TrianglePoint1.x > ThePoint.x) and (TrianglePoint3.x > ThePoint.x)) then
Result := InRangeBetter(ThePoint.y, XToY(ThePoint.x, TrianglePoint1, TrianglePoint2), XToY(ThePoint.x, TrianglePoint2, TrianglePoint3)) else
if ((TrianglePoint2.x < ThePoint.x) and (TrianglePoint3.x < ThePoint.x)) or ((TrianglePoint2.x > ThePoint.x) and (TrianglePoint3.x > ThePoint.x)) then
Result := InRangeBetter(ThePoint.y, XToY(ThePoint.x, TrianglePoint1, TrianglePoint2), XToY(ThePoint.x, TrianglePoint1, TrianglePoint3)) else
if ThePoint.x = TrianglePoint1.x then
begin
if InRangeBetter(TrianglePoint1.x, TrianglePoint2.x, TrianglePoint3.x) then
Result := InRangeBetter(ThePoint.y, TrianglePoint1.y, XToY(ThePoint.x, TrianglePoint2, TrianglePoint3)) else
Result := ThePoint.y = TrianglePoint1.y;
end else
if ThePoint.x = TrianglePoint2.x then
begin
if InRangeBetter(TrianglePoint2.x, TrianglePoint1.x, TrianglePoint3.x) then
Result := InRangeBetter(ThePoint.y, TrianglePoint2.y, XToY(ThePoint.x, TrianglePoint1, TrianglePoint3)) else
Result := ThePoint.y = TrianglePoint1.y;
end else
if ThePoint.x = TrianglePoint3.x then
begin
if InRangeBetter(TrianglePoint3.x, TrianglePoint1.x, TrianglePoint2.x) then
Result := InRangeBetter(ThePoint.y, TrianglePoint3.y, XToY(ThePoint.x, TrianglePoint1, TrianglePoint2)) else
Result := ThePoint.y = TrianglePoint1.y;
end;
end;

function PointInAbstractBox(P1, P2, P3, P4, MainPoint: TPoint): Boolean;
begin
Result := PointInTriangle(MainPoint, P1, P2, P3) or
PointInTriangle(MainPoint, P1, P2, P4) or
PointInTriangle(MainPoint, P1, P3, P4) or
PointInTriangle(MainPoint, P2, P3, P4);
end;

procedure ClickTileBox(TileBox: TBox; ClickType: Integer);
var
P1, P2, P3, P4, ClickPoint: TPoint;

I, X, Y: Integer;
TPA: TPointArray;
begin
repeat
ClickPoint.x := RandomRange(Min(Min(Min(P1.x, P2.x), P3.x), P4.x), Max(Max(Max(P1.x, P2.x), P3.x), P4.x) + 1);
ClickPoint.y := RandomRange(Min(Min(Min(P1.y, P2.y), P3.y), P4.y), Max(Max(Max(P1.y, P2.y), P3.y), P4.y) + 1);
//Possibly needs a failsafe here, however odds of it not getting a point, are minimal
until PointInAbstractBox(P1, P2, P3, P4, ClickPoint);
case ClickType of
1 : Mouse(ClickPoint.x, ClickPoint.y, 0, 0, True);
2 : Mouse(ClickPoint.x, ClickPoint.y, 0, 0, False);
3 : Mouse(ClickPoint.x, ClickPoint.y, 0, 0);
else
Writeln('Unsupported Clicktype - ' + IntToStr(ClickType));
end;
end;

procedure ClickTile(TheTile: TTile; ClickType: Integer);
begin
ClickTileBox(TheTile.x, TheTile.y, TheTile.x, TheTile.y, ClickType);
end;

Cstrike

2010-12-03 07:17:40

I like the point in triangle :) I'll look into it and test it out once I get home.

Bad Boy JH

2010-12-03 07:22:30

it looked rather….complicated when I wrote it, but elegance isn't always the best way in scripting. Sometimes the ugly but foolproof method is the best way.

Naike

2010-12-03 07:23:10

Please type out what the functions do..

Bad Boy JH

2010-12-03 08:40:18

InRangeBetter, basically does the sameas InRange except that it will return true for
InRangeBetter(0, 1, -1) where as InRange wouldn't.

XtoY, whilst it may need a better name, takes an X coordinate and two points, and basically finds the y coordinate so that the point (X, Y) lies on the line connecting those two points. the sorta thing you did in mathematics at school.

PointInTriangle, basically does what it says, takes 4 points, a point to check, and the 3 vertices (corners) of the triangle and determines whether the point lies in the triangle.

PointInBox does exactly what it says using PointInTriangle, the only issue with it is if one of the points is INSIDE the triangle the other three would create, but that won't happen with tiles.

ClickTileBox clicks a random spot inside an Area of Tiles (TBox).
The repeat until generates the point, and the until checks if it is in the box of tiles. It then procedes to click the point, simmilar to how MouseBox does it.
1 - Left Click
2 - Right Click
3 - Don't Click

ClickTile just takes the one tile, and then clicks anywhere on that tile.