SRL Archive - Test corner

Examine Minimap Tree Functions


Town

2007-09-05 22:00:24

Trees are a very common object to find in the game. Because of that, I thought they would be a useful tool in finding location, maybe walking, etc. So, here are my tree related functions.

function TreeColors(var GreTree, BroTree: Integer): Boolean;
var
Points: TPointArray;
i, a: Integer;
begin
FindColorsTolerance(Points, 1594672, MMX1, MMY1, MMX2, MMY2, 10);
for i := 0 to GetArrayLength(Points) - 1 do
begin
a := CountColor(GetColor(Points[i].x, Points[i].y), Points[i].x - 5, Points[i].y - 3, Points[i].x + 5, Points[i].y + 3)
if (a > 8) and (a < 13) then
begin
if (FindColorSpiralTolerance(x, y, KindOfTree, Points[i].x - 5, Points[i].y, Points[i].x + 5, Points[i].y + 8, 10)) then
begin
Result := True;
GreTree := GetColor(Points[i].x, Points[i].y);
BroTree := GetColor(x, y);
Exit;
end;
end;
end;
end;

Results green and brown minimap tree colors.

I left KindOfTree in there, the color that would be there varies depending on what kind of tree you're looking for. Once you pick the color the tolerance will pick it up even if it changes slightly. Colors I have used: 1916248, 733537, 1062210.

On this kind of tree, this is the color that you will want (By reading my code you should be able to understand why and how to pick it on a different tree):


function TreeCoords(GreTree, BroTree: Integer): TPoint;
var
Points: TPointArray;
i: Integer;
begin
FindColorsTolerance(Points, GreTree, MMX1, MMY1, MMX2, MMY2, 0);
for i := 0 to GetArrayLength(Points) do
if (GetColor(Points[i].x, Points[i].y + 1) = BroTree) and
(GetColor(Points[i].x - 1, Points[i].y) = GreTree) and
(GetColor(Points[i].x + 1, Points[i].y) = GreTree) then
begin
Result := Points[i]
Exit;
end;
end;

Results a coordinate of a tree on the minimap.

function TreeCoordsSkipBoxArray(GreTree, BroTree: Integer; var BoxArray: TBoxArray): TPoint;
begin
if (FindColorSkipBoxArray(x, y, GreTree, MMX1, MMY1, MMX2, MMY2, BoxArray)) then
begin
if (GetColor(x, y + 1) = BroTree) and
(GetColor(x - 1, y) = GreTree) and
(GetColor(x + 1, y) = GreTree) then
begin
Result.x := x;
Result.y := y;
Exit;
end else
begin
SetArrayLength(BoxArray, GetArrayLength(BoxArray) + 1);
BoxArray[GetArrayLength(BoxArray) - 1].x1 := x;
BoxArray[GetArrayLength(BoxArray) - 1].x2 := x;
BoxArray[GetArrayLength(BoxArray) - 1].y1 := y;
BoxArray[GetArrayLength(BoxArray) - 1].y2 := y;
Result.x := -1;
end;
end else Result.y := -1;
end;

Used in my next function.

function CountTrees(GreTree, BroTree: Integer): Integer;
var
BoxArray: TBoxArray;
Point: Tpoint;
begin
repeat
Point := TreeCoordsSkipBoxArray(GreTree, BroTree, BoxArray);
// WriteLN(IntToStr(Point.x) + ' ' + IntToStr(Point.y));
if (not (Point.x = -1)) and (not (Point.y = -1)) then
begin
// WriteLN(IntToStr(Point.x) + ' ' + IntToStr(Point.y));
SetArrayLength(BoxArray, GetArrayLength(BoxArray) + 1);
BoxArray[GetArrayLength(BoxArray) - 1].x1 := Point.x - 2;
BoxArray[GetArrayLength(BoxArray) - 1].x2 := Point.x + 8;
BoxArray[GetArrayLength(BoxArray) - 1].y1 := Point.y - 8;
BoxArray[GetArrayLength(BoxArray) - 1].y2 := Point.y + 2;
Result := Result + 1;
end;
until (Point.y = -1);
end;

Counts the number of trees on the minimap. Worked perfectly when I tried it, resulted 13, same as when I counted myself. Also tried a different type of tree, result 9, same as when I counted myself.

I'll take suggestions on anymore related functions if you guys can think of any.

Tim0suprem0

2007-09-05 22:52:50

You don't know how badly I've needed this. + Rep Thank you!

However when I tried this, I found that sometimes the tolerance couldn't handle it, but that was rare.

TOB

2007-09-06 08:44:11

Might be something Fakawi can use to auto-color that "stupid pixel". :)

Starblaster100

2007-09-06 08:58:52

This is very nice stuff! Nice one

Town

2007-09-06 16:32:03

From: tim0suprem0
You don't know how badly I've needed this. + Rep Thank you!

However when I tried this, I found that sometimes the tolerance couldn't handle it, but that was rare.


If that is the case then do For Tol := 10 to 20-25 do in the autocolor. Then replace the tolerance in the functions with Tol. That should work better. I'll see if I can test it.

From: TOB
Might be something Fakawi can use to auto-color that "stupid pixel". :)


I'm not sure which pixel you're talking about, but TreeCoords will always result the same pixel on the tree so it should be simple in just saying Result := TreeCoords.x + etc, TreeCoords.y + etc and it will get it each time.

Tim0suprem0

2007-09-06 21:14:28

From: Town
If that is the case then do For Tol := 10 to 20-25 do in the autocolor. Then replace the tolerance in the functions with Tol. That should work better. I'll see if I can test it.



I'm not sure which pixel you're talking about, but TreeCoords will always result the same pixel on the tree so it should be simple in just saying Result := TreeCoords.x + etc, TreeCoords.y + etc and it will get it each time.


The problem I had was the difference between the color 7462 (which is what it's around when the screen is REALLY dark) and one like 1594672, the tolerance between those two is about 62, so when I was Treefinding I had to do a case of different colors to use tolerance from because their was such a large range. In instances that the tolerance did help, there was often a shade of brown that was closer in tol somewhere else on the minmap so the array of points returned wasn't even trees :confused:

This was only on rare occasions, so it wasn't usually a problem though.