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.
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):

Results a coordinate of a tree on the minimap.
Used in my next function.
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.
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.