SRL Archive - SRL Archives

Function FindTreeColor: Integer;


noidea

2009-08-08 00:41:17

Function FindTreeColor: Integer;
var
TPA: TPointArray;
i, TestColor, GC, R, G, B, AL: Integer;
begin
GC := 1528609;
FindColorsSpiralTolerance(mmcx, mmcy, TPA, GC, mmx1, mmy1, mmx2, mmy2, 70);
If Length(TPA) < 1 then
begin
writeln('Couldn''t find tree color!');
Result := -1;
exit;
end;
FilterPointsPie(TPA, 0, 360, 0, 72, MMCX, MMCY);
AL := GetArrayLength(TPA);
For i := 0 to AL - 1 do
begin
If RS_OnMiniMap(TPA[i].x, TPA[i].y) then
begin
TestColor := GetColor(TPA[i].x, TPA[i].y);
ColorToRGB(TestColor, R, G, B);
if InRange(R - B, 4, 50) then
if InRange(R - G, -65, -30) then
if InRange(G - B, 50, 82) then
if GetColor(TPA[i].x - 1, TPA[i].y) = TestColor then
if GetColor(TPA[i].x, TPA[i].y + 1) = TestColor then
if GetColor(TPA[i].x, TPA[i].y - 1) = TestColor then
begin
writeln('Tree colour = '+ Inttostr(TestColor));
Result := TestColor;
exit;
end;
end;
end;
writeln('Couldn''t find tree color!');
Result := -1;
end;


Even in a place where the ground is very similar to the tree, it finds it :)

Craig`

2009-08-08 00:42:32

I had noidea you could do stuff like this, nice :)

I'm semi-working on a power cutter atm, I'll sure to be adding it to it :)

I'll tell you how it goes on the irc :)

~ Craig` :D

Awkwardsaw

2009-08-08 00:49:52

lol, i get some credit for sort of giving you the idea last night, right? ;)

and good job haha

noidea

2009-08-08 01:05:18

From: Awkwardsaw
lol, i get some credit for sort of giving you the idea last night, right? ;)

and good job haha


I wrote it a few days ago silly. I'm trying to re-write my old VWM :)
<3

ShowerThoughts

2009-08-08 01:39:44

Good job!

Smarter Child

2009-08-08 01:43:40

Add in AutoColor.scar nowz!!
Really helpful, since its good for location checks like.

RW
RW
if (not(findcolor(x, y, Findtreecolor, mmx1,mmy1,mmx2,mmy2))) or whatever the params lol
then exit;

ShowerThoughts

2009-08-08 01:55:06

From: Smarter Child
Add in AutoColor.scar nowz!!
Really helpful, since its good for location checks like.

RW
RW
if (not(findcolor(x, y, Findtreecolor, mmx1,mmy1,mmx2,mmy2))) or whatever the params lol
then exit;


That wouldn't be smart, because like whole Runescape's MM exists out of tree's when you are walking.

EvilChicken!

2009-08-08 05:33:09

This is especially useful for DDTMs.
Thanks, noidea - committed it.

Though, I took the liberty to edit it a tiny bit, hope you don't mind. :)

noidea

2009-08-08 08:24:19

From: EvilChicken!
This is especially useful for DDTMs.
Thanks, noidea - committed it.

Though, I took the liberty to edit it a tiny bit, hope you don't mind. :)


/me cheers
:D thanks EC! my first function added <3

I don't mind you editting it.

Edit: Lol, with the edits, its so short :p

Edit2: Oops. I hadnt realised I left in the DebugTPA(). It was the raw colour that the FindColorsSpiralTolerance gave out :p
To the the pic I used, I just made another tpa using the FindTreeColor.

noidea

2009-08-08 09:25:08

Sorry for the double post but this is urgant.

The one commited to SRL isn't find the tree colour.
ANd the one I posted Is.

Not putting you down EC :(

Edit: your function isnt working. The FindMMColor…
I changed it
function FindMMColorsSpiralTolerance(var Points: TPointArray; Color, Tol: Integer): Boolean;
begin
Result := False;
if (not LoggedIn) then exit;
FindColorsSpiralTolerance(MMCX, MMCY, Points, Color, MMX1, MMY1, MMX2, MMY2, Tol);
result := length(points) > 0;
if Result then
FilterPointsPie(Points, 0.0, 360.0, 0.0, 76.0, MMCX, MMCY);
end;
It works :D
And that bug is affecting ALL the other autocolors :<

noidea

2009-08-08 16:16:53

Sorry for the triple post but this is an epic updated one.

Function FindTreeColor: Integer;
var
TPA, TestTPA: TPointArray;
ATPA: T2DPointArray;
H, S, L: Extended;
i, TestColor, R, G, B, AL, BlackListCol: Integer;
begin
Result := -1;
BlackListCol := -1;
if FindMMColorsSpiralTolerance(TPA, 1528609, 70) then
begin
AL := high(TPA);
For i := 0 to AL do
begin
TestColor := GetColor(TPA[i].x, TPA[i].y);
if TestColor <> BlackListCol then
begin
ColorToRGB(TestColor, R, G, B);
ColorToHSL(TestColor, H, S, L);
if InRange(R - B, 4, 50) then
if InRange(R - G, -65, -30) then
if InRange(G - B, 50, 87) then
if L < 28 then
if GetColor(TPA[i].x - 1, TPA[i].y) = TestColor then
if GetColor(TPA[i].x, TPA[i].y + 1) = TestColor then
if GetColor(TPA[i].x, TPA[i].y - 1) = TestColor then
begin
FindColorsSpiralTolerance(mmcx, mmcy, TestTPA, TestColor, mmx1, mmy1, mmx2, mmy2, 0);
if Length(TestTPA) > 0 then
begin
ATPA := TPAtoATPAEx(TestTPA, 11, 10);
SortATPAFrom(ATPA, Point(mmcx, mmcy));
if not InRange(Length(ATPA[0]), 21, 28) then
if Length(ATPA[0]) < 30 then
begin
srl_Warn('FindTreeColor', 'TreeColor = ' + IntToStr(TestColor), warn_Debug);
Result := TestColor;
exit;
end else
begin
ColorToHSL(TestColor, H, S, L);
if L > 24 then
BlackListCol := TestColor;
end;
end;
end;
end;
end;
end;
srl_Warn('FindTreeColor', 'Could''t find TreeColor', warn_Debug);
Result := -1;
end;
- EvilChicken Style :p


Function FindTreeColor: Integer;
var
TPA, TestTPA: TPointArray;
ATPA: T2DPointArray;
H, S, L: Extended;
i, TestColor, GC, R, G, B, AL, BlackListCol: Integer;
begin
GC := 1528609;
BlackListCol := -1;
FindColorsSpiralTolerance(mmcx, mmcy, TPA, GC, mmx1, mmy1, mmx2, mmy2, 70);
If Length(TPA) < 1 then
begin
writeln('Couldn''t find tree color!');
Result := -1;
exit;
end;
FilterPointsPie(TPA, 0, 360, 0, 72, MMCX, MMCY);
//DebugTPA(TPA, '');
AL := GetArrayLength(TPA);
For i := 0 to AL - 1 do
begin
If RS_OnMiniMap(TPA[i].x, TPA[i].y) then
begin
TestColor := GetColor(TPA[i].x, TPA[i].y);
if TestColor <> BlackListCol then
begin
ColorToRGB(TestColor, R, G, B);
ColorToHSL(TestColor, H, S, L);
if InRange(R - B, 4, 50) then
if InRange(R - G, -65, -30) then
if InRange(G - B, 50, 87) then
if L < 28 then
if GetColor(TPA[i].x - 1, TPA[i].y) = TestColor then
if GetColor(TPA[i].x, TPA[i].y + 1) = TestColor then
if GetColor(TPA[i].x, TPA[i].y - 1) = TestColor then
begin
FindColorsSpiralTolerance(mmcx, mmcy, TestTPA, TestColor, mmx1, mmy1, mmx2, mmy2, 0);
if Length(TestTPA) > 0 then
begin
ATPA := TPAtoATPAEx(TestTPA, 11, 10);
SortATPAFrom(ATPA, Point(mmcx, mmcy));
if not InRange(Length(ATPA[0]), 21, 28) then
if Length(ATPA[0]) < 30 then
begin
writeln('Tree colour = '+ Inttostr(TestColor));
Result := TestColor;
exit;
end else
begin
ColorToHSL(TestColor, H, S, L);
if L > 24 then
BlackListCol := TestColor;
end;
end;
end;
end;
end;
end;
writeln('Couldn''t find tree color!');
Result := -1;
end;
- Original

The other one would often find the Bushes on the MM (I only found that after I posted). This one skips the bushes ect…

All in all this is about 100x better.

btw: I stayed up ALL night coding, and testing this - It better work. Wizzup can tell you that I was on the irc all night ranting and raging :p

EvilChicken!

2009-08-08 19:06:24

Ow, nice, looks a lot better.

First of all, it needs to be a global variable for the color to be permanently stored in there.
Second, don't you think that an array of colors would be better?
Third, I'll add it with the array if you can tell me with 100% certainty that it won't add useful colors in that blacklist array.

Naum

2009-08-08 21:22:32

You should replace GetArrayLength with High(). In a freak case that if nothing is found, then it won't do:

For I := 0 to -1 Do.

Good work though ;)

Edit: You may want to set Result := -1; at the beginning.

noidea

2009-08-08 21:39:54

From: EvilChicken!
Ow, nice, looks a lot better.

First of all, it needs to be a global variable for the color to be permanently stored in there.
Second, don't you think that an array of colors would be better?
Third, I'll add it with the array if you can tell me with 100% certainty that it won't add useful colors in that blacklist array.


So should I let it find that bush colour? (The tree that sort of looks like a palm tree on the MM)
Or just all the colour on the tree?

EvilChicken!

2009-08-08 21:47:20

Did some testing, seems to work really well. Nevermind the talk about making the blacklist array global, by the way.
Here's the version I committed.


function FindTreeColor: Integer;
var
TPA, TestTPA: TPointArray;
ATPA: T2DPointArray;
H, S, L: Extended;
Hi, i, TestColor, R, G, B: Integer;
TreeColorsBlackList: TIntegerArray;


begin
if FindMMColorsSpiralTolerance(TPA, 1528609, 70) then
begin
Hi := High(TPA);
For I := 0 to Hi do
begin
TestColor := GetColor(TPA[i].x, TPA[i].y);
if not InIntArray(TreeColorsBlackList, TestColor) then
begin
ColorToRGB(TestColor, R, G, B);
ColorToHSL(TestColor, H, S, L);
if InRange(R - B, 4, 50) then
if InRange(R - G, -65, -30) then
if InRange(G - B, 50, 87) then
if (L < 28) then
if (GetColor(TPA[i].x - 1, TPA[i].y) = TestColor) then
if (GetColor(TPA[i].x, TPA[i].y + 1) = TestColor) then
if (GetColor(TPA[i].x, TPA[i].y - 1) = TestColor) then
if FindMMColorsSpiralTolerance(testTPA, TestColor, 0) then
begin
ATPA := TPAtoATPAEx(TestTPA, 11, 10);
if (not InRange(Length(ATPA[0]), 21, 28)) then
if (Length(ATPA[0]) < 30) then
begin
srl_Warn('FindTreeColor', 'TreeColor = ' + IntToStr(TestColor), warn_Debug);
Result := TestColor;
Exit;
end else
if (L > 24) then
begin
Hi := High(TreeColorsBlackList);
SetLength(TreeColorsBlackList, Hi + 2);
TreeColorsBlackList[Hi + 1] := TestColor;
end;
end;
end;
end;
end;
srl_Warn('FindTreeColor', 'Could''t find TreeColor', warn_Debug);
Result := -1;
end;

noidea

2009-08-09 04:31:25

Function FindTreeColor: Integer;
var
TPA, TestTPA: TPointArray;
ATPA: T2DPointArray;
H, S, L: Extended;
i, TestColor, GC, R, G, B, AL: Integer;
BlackListCol: TIntegerArray;
begin
result := -1;
if FindMMColorsSpiralTolerance(TPA, 1528609, 70) then
begin
AL := high(TPA);
For i := 0 to AL do
begin
TestColor := GetColor(TPA[i].x, TPA[i].y);
if not InIntArray(BlackListCol, TestColor) then
begin
ColorToRGB(TestColor, R, G, B);
ColorToHSL(TestColor, H, S, L);
if InRange(R - B, -10, 50) then
if InRange(R - G, -75, -30) then
if InRange(G - B, 50, 88) then
if L < 31.5 then
if GetColor(TPA[i].x - 1, TPA[i].y) = TestColor then
if GetColor(TPA[i].x, TPA[i].y + 1) = TestColor then
if GetColor(TPA[i].x, TPA[i].y - 1) = TestColor then
begin
FindColorsSpiralTolerance(mmcx, mmcy, TestTPA, TestColor, mmx1, mmy1, mmx2, mmy2, 0);
if Length(TestTPA) > 0 then
begin
ATPA := TPAtoATPAEx(TestTPA, 11, 10);
SortATPAFrom(ATPA, Point(mmcx, mmcy));
if not InRange(Length(ATPA[0]), 21, 28) then
if Length(ATPA[0]) < 30 then
if not InRange(Length(ATPA[0]), 8, 10) then
begin
writeln('Tree colour = '+ Inttostr(TestColor));
Result := TestColor;
exit;
end else
begin
ColorToHSL(TestColor, H, S, L);
if L > 24 then
begin
SetArrayLength(BlackListCol, Length(BLackListCol) + 1);
BlackListCol[High(BlackListCol)] := TestColor;
end;
end;
end;
end;
end;
end;
end;
writeln('Couldn''t find tree color!');
Result := -1;
end;

Lol I just sent you this in PM and its like identical to yours :p
The one you upped needs to change some of the ranges though.

Edit: Lol I cant believe the similarity :p Its almost like word for word