SRL Archive - OSR Help

Help with TPA walking


3Garrett3

2010-08-22 12:46:10

Hey guys,

I'm trying to make a l33t TPA walker for my Karamja script, and I'm just trying to improve the one from my Baby Melter. Here is what it looks like:


Function WalkTPA(C1, XM, YM, XR, YR, Tol, SplitMethod, SortMethod, ColTolS : Integer;
SortPoint : TPoint; HueMod, SatMod : Extended; Dist : TIntegerArray) : Boolean;
Var
TPA: TPointArray;
TDPA: T2DPointArray;
I, CTS, H, X, Y: Integer;
Begin
If Not LoggedIn Then Exit;

cts := GetColorToleranceSpeed;
if ColTolS = 2 then
begin
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(HueMod, SatMod);
end else
ColorToleranceSpeed(ColTolS);

FindColorsSpiralTolerance(MMCX, MMCY, TPA, C1, MMX1, MMY1, MMX2, MMY2, Tol);

Debug('Found colour, length of array = ' + IntToStr(Length(TPA)));
If Length(TPA) = 0 Then
begin
Debug('Didn''t find the colour, quitting walktpa');
ColorToleranceSpeed(cts);
Exit;
end;

Case SplitMethod of
1:
TDPA := TPAToATPA(TPA, Dist[0]);
2:
TDPA := TPAToATPAEx(TPA, Dist[0], Dist[1]);
3:
TDPA := SplitTPA(TPA, Dist[0]);
4:
TDPA := SplitTPAEx(TPA, Dist[0], Dist[1]);
end;

Case SortMethod of
1:
SortATPAFrom(TDPA, SortPoint);
2:
SortATPASize(TDPA, True);
3:
SortATPASize(TDPA, False);
end;

//DebugTPA(TPA, '');
H := High(TDPA);
For i := 0 To H Do
Begin
MiddleTPAEx(TDPA[i], x, y);
If rs_OnMinimap(x,y) Then
Begin
MouseFlag(x + XM, y + YM, XR, YR, 0);
Result := True;
Wait(200 + Random(80));
ColorToleranceSpeed(cts);
Exit;
End;
End;

Result := False;
ColorToleranceSpeed(cts);
End;

It has sooo many parameters, yeah. But I want it to be the ultimate generic TPA walker, so that I don't have to do anything custom other than call one line of code every time I want to TPA walk (there are 6 steps to Stiles, so 12 steps altogether).

With this I simply have to call:

Result := WalkTPA(Color, 5, 5, 1, 1, 2, 4, 3, 1, Point(MMx1, MMCy), 0, 0, [20,30]);

Anything to add, remove, improve, etc would be greatly appreciated.

TRiLeZ

2010-08-22 13:56:27

Changing FindColorSpiralTolerance to FindColorTolerance would make it go faster.

What about using FilterPointsPie?

3Garrett3

2010-08-22 14:47:46

From: TRiLeZ
Changing FindColorSpiralTolerance to FindColorTolerance would make it go faster.

What about using FilterPointsPie?


I could add FilterPointsPie, it filters the TPA before it is split/sorted, right?

TRiLeZ

2010-08-22 15:01:42

From: 3Garrett3
I could add FilterPointsPie, it filters the TPA before it is split/sorted, right?


Correct.

Coh3n

2010-08-22 16:30:16

You should use constants for the Splitting/Sorting methods. If you can get this to work really well anywhere, I would love to incorporate this into MSI. :) May make making creating color walking a lot easier/faster. Also the first 5 parameters are kinda vague, maybe change them or include them in the function description.

3Garrett3

2010-08-22 17:00:34

From: Coh3n
You should use constants for the Splitting/Sorting methods. If you can get this to work really well anywhere, I would love to incorporate this into MSI. :) May make making creating color walking a lot easier/faster. Also the first 5 parameters are kinda vague, maybe change them or include them in the function description.


I removed them now anyway, too much confusion. It could be useful to have XMod and YMod though again, it is useful to autocolor a common object then click 15 pixels to the left, which is expected to be a road.

I can't get the SortMethod to work though, maybe the case is interfering with it.

Naum

2010-08-22 17:02:57

From: 3Garrett3

I can't get the SortMethod to work though, maybe the case is interfering with it.


Is it by Size or by Position? If by position try SortATPAFromFirstPoint :)

3Garrett3

2010-08-22 17:05:28

From: Naum
Is it by Size or by Position? If by position try SortATPAFromFirstPoint :)


By position. I'm using SortATPAFrom, it's giving this:

First point used to be (559, 72)
First point now is (569, 81)

When I debug it.

I'm using Sortpoint as MMCx, MMY2 which is 627, 161.

Edit:

I removed a couple Params. I'm using it with a colour chosen through autocolour, so I removed the Tol, HueMod, SatMod and ColTolS options. Those can be added back in if you want it to act as an autocolour of sorts as well.


Function WalkTPA(C1, XMod, YMod, SplitMethod, SortMethod : Integer; SortPoint : TPoint; Dist : TIntegerArray) : Boolean;
Var
TPA: TPointArray;
TDPA: T2DPointArray;
I, H, X, Y: Integer;
Begin
If Not LoggedIn Then Exit;

FindColorsTolerance(TPA, C1, MMX1, MMY1, MMX2, MMY2, 2);

Writeln('Found colour, length of array = ' + IntToStr(Length(TPA)));
If Length(TPA) = 0 Then
begin
Writeln('Didn''t find the colour, quitting walktpa');
Exit;
end;

Case SplitMethod of
1:
TDPA := TPAToATPA(TPA, Dist[0]);
2:
TDPA := TPAToATPAEx(TPA, Dist[0], Dist[1]);
3:
TDPA := SplitTPA(TPA, Dist[0]);
4:
TDPA := SplitTPAEx(TPA, Dist[0], Dist[1]);
end;

Case SortMethod of
1:
begin
SortATPAFromFirstPoint(TDPA, SortPoint);
end;
2:
SortATPASize(TDPA, True);
3:
SortATPASize(TDPA, False);
end;

Wait(10);
try
DebugATPABounds(TDPA);
except end;
H := High(TDPA);
For i := 0 To H Do
Begin
MiddleTPAEx(TDPA[i], x, y);
If rs_OnMinimap(x,y) Then
Begin
Mouse(x , y , 2, 2, True);
Wait(RandomRange(200,300));
FFlag(0);
Result := True;
Wait(200 + Random(80));
Exit;
End;
End;

Result := False;
End;

Coh3n

2010-08-23 13:02:24

Why don't you try marpis's FindMMLocation? I'm sure you could make it work for a lot of places.

{******************************************************************************}
{ function MSI_RelocateColor(...): Boolean; }
{ By: marpis }
{ Description: Finds a location in minimap. First tries to find DTM, then }
{ colors, and if still not found it will find it by symbol }
{******************************************************************************}
function MSI_RelocateColor(var P: TPoint; Location, Index: Integer): Boolean;
Var
SA, EA, tmp_Ang: Extended;
N, I, II, III, H, HH, X, Y, Score, Step: Integer;
ATPA: T2DPointArray;
tmp_TPA: TPointArray;
X1, Y1, X2, Y2: Integer;
Loc: TLocation;
begin
Result := False;
P := Point(-1, -1);

if (not LoggedIn) then
Exit;

if (Length(MSI_Locations[Location].RelocateAreas) <= 0) then
Exit;

Loc := MSI_ColorAreas[MSI_Locations[Location].RelocateAreas[Index]];
Step := (Loc.W * Loc.H) / 10;

{ DTM Search }
if (Loc.DTM > -1) then
while (N < 10) do
begin
if FindDTMRotated(Loc.DTM, X, Y, MMX1, MMY1, MMX2, MMY2, SA, EA, 0.02, tmp_Ang) then
begin
Result := True;
P := Point(X, Y);
MSI_SubDebug('Found relocation point via DTM: (' + IntToStr(P.X) + ', ' + IntToStr(P.Y) + ')');
Exit;
end;
Inc(N);
SA := SA - (N * 0.02);
EA := EA + (N * 0.02);
end;

{ Color search }
if (Length(Loc.Colors) > 0) then
begin
H := High(Loc.Colors);
SetLength(ATPA, H + 1);

for I := 0 to H do
begin
FindColorsSpiralTolerance(MMCX, MMCY, ATPA[I], Loc.Colors[I], MMX1, MMY1, MMX2, MMY2, Loc.Tolerances[I]);
FilterPointsPie(ATPA[I], 0.0, 360.0, 0.0, 76.0, MMCX, MMCY);
end;

{ Go through every TPA that contains one color. }
for I := 0 to H do
begin
HH := High(ATPA[I]);

{ Go through every 10th point in ATPA[I] to avoid lag. }
for II := 0 to HH do
begin
if ((II mod Step) <> 0) then
Continue;

Score := 0;

X1 := ATPA[I][II].X - (Loc.W / 2);
Y1 := ATPA[I][II].Y - (Loc.H / 2);
X2 := ATPA[I][II].X + (Loc.W / 2);
Y2 := ATPA[I][II].Y + (Loc.H / 2);

{ Go through every TPA again, calculating surrounding color counts. }
for III := 0 to H do
begin
tmp_TPA := MSI_ReturnPointsInBox(ATPA[III], IntToBox(X1, Y1, X2, Y2));
if (Length(tmp_TPA) >= Loc.Counts[III]) then
Inc(Score);
end;

{ If there are enough points of all colors, the location has been found. }
if (Score = H) then
begin
Result := True;
X := (X1 + X2) shr 1;
Y := (Y1 + Y2) shr 1;
P := Point(X, Y);
MSI_SubDebug('Found relocation point via color: (' + IntToStr(P.X) + ', ' + IntToStr(P.Y) + ')');
Exit;
end;

end;
end;
end;

{ Symbol Search }
if (Loc.Symbol <> '') then
if FindSymbol(X, Y, Loc.Symbol) then
begin
Result := True;
P := Point(X, Y);
MSI_SubDebug('Found relocation point via symbol: (' + IntToStr(P.X) + ', ' + IntToStr(P.Y) + ')');
Exit;
end;
end;

3Garrett3

2010-08-23 13:55:34

From: Coh3n
Why don't you try marpis's FindMMLocation? I'm sure you could make it work for a lot of places.

{******************************************************************************}
{ function MSI_RelocateColor(...): Boolean; }
{ By: marpis }
{ Description: Finds a location in minimap. First tries to find DTM, then }
{ colors, and if still not found it will find it by symbol }
{******************************************************************************}
function MSI_RelocateColor(var P: TPoint; Location, Index: Integer): Boolean;
Var
SA, EA, tmp_Ang: Extended;
N, I, II, III, H, HH, X, Y, Score, Step: Integer;
ATPA: T2DPointArray;
tmp_TPA: TPointArray;
X1, Y1, X2, Y2: Integer;
Loc: TLocation;
begin
Result := False;
P := Point(-1, -1);

if (not LoggedIn) then
Exit;

if (Length(MSI_Locations[Location].RelocateAreas) <= 0) then
Exit;

Loc := MSI_ColorAreas[MSI_Locations[Location].RelocateAreas[Index]];
Step := (Loc.W * Loc.H) / 10;

{ DTM Search }
if (Loc.DTM > -1) then
while (N < 10) do
begin
if FindDTMRotated(Loc.DTM, X, Y, MMX1, MMY1, MMX2, MMY2, SA, EA, 0.02, tmp_Ang) then
begin
Result := True;
P := Point(X, Y);
MSI_SubDebug('Found relocation point via DTM: (' + IntToStr(P.X) + ', ' + IntToStr(P.Y) + ')');
Exit;
end;
Inc(N);
SA := SA - (N * 0.02);
EA := EA + (N * 0.02);
end;

{ Color search }
if (Length(Loc.Colors) > 0) then
begin
H := High(Loc.Colors);
SetLength(ATPA, H + 1);

for I := 0 to H do
begin
FindColorsSpiralTolerance(MMCX, MMCY, ATPA[I], Loc.Colors[I], MMX1, MMY1, MMX2, MMY2, Loc.Tolerances[I]);
FilterPointsPie(ATPA[I], 0.0, 360.0, 0.0, 76.0, MMCX, MMCY);
end;

{ Go through every TPA that contains one color. }
for I := 0 to H do
begin
HH := High(ATPA[I]);

{ Go through every 10th point in ATPA[I] to avoid lag. }
for II := 0 to HH do
begin
if ((II mod Step) <> 0) then
Continue;

Score := 0;

X1 := ATPA[I][II].X - (Loc.W / 2);
Y1 := ATPA[I][II].Y - (Loc.H / 2);
X2 := ATPA[I][II].X + (Loc.W / 2);
Y2 := ATPA[I][II].Y + (Loc.H / 2);

{ Go through every TPA again, calculating surrounding color counts. }
for III := 0 to H do
begin
tmp_TPA := MSI_ReturnPointsInBox(ATPA[III], IntToBox(X1, Y1, X2, Y2));
if (Length(tmp_TPA) >= Loc.Counts[III]) then
Inc(Score);
end;

{ If there are enough points of all colors, the location has been found. }
if (Score = H) then
begin
Result := True;
X := (X1 + X2) shr 1;
Y := (Y1 + Y2) shr 1;
P := Point(X, Y);
MSI_SubDebug('Found relocation point via color: (' + IntToStr(P.X) + ', ' + IntToStr(P.Y) + ')');
Exit;
end;

end;
end;
end;

{ Symbol Search }
if (Loc.Symbol <> '') then
if FindSymbol(X, Y, Loc.Symbol) then
begin
Result := True;
P := Point(X, Y);
MSI_SubDebug('Found relocation point via symbol: (' + IntToStr(P.X) + ', ' + IntToStr(P.Y) + ')');
Exit;
end;
end;


Wait wha? :P

I don't understand what you mean by posting that in my TPA walk help

Coh3n

2010-08-23 14:08:51

There may be situations where that function would work better (i.e. a tree). You just make a record for each location and you're good to go. Was just pointing it out.

I've never tested it so it may or may not work better than yours, who knows.