EvilChicken!
2009-01-19 14:19:57
{.include SRL/SRL.scar}
function ScanForRoadColor(Direction: Char; SearchWidth, SearchDensity: Byte): Integer;
var
X, Y, tmpCol, arrLen, MX1, MY1, MX2, MY2, LowestToleranceColorPosition: Integer;
ColorArray, ColorTolerances, ColorToleranceArrayDuplicate: TIntegerArray;
Tolerance: Byte;
begin
Result := -1;
if not LoggedIn then exit;
MX1 := MMX1;
MY1 := MMY1;
MX2 := MMX2;
MY2 := MMY2;
case UpperCase(Direction) of
'N': MY2 := MMY1 + SearchWidth;
'W': MX2 := MMX1 + SearchWidth;
'S': MY1 := MMY2 - SearchWidth;
'E': MX1 := MMX2 - SearchWidth;
else
begin
srl_Warn('ScanWalk', '"' + Direction + '" is an invalid direction', -2);
Exit;
end;
end;
if SearchDensity < 1 then
SearchDensity := 1;
for X := MX1 to MX2 do
begin
for Y := MY1 to MY2 do
begin
tmpCol := GetColor(X, Y);
Inc(ArrLen);
SetArrayLength(ColorArray, ArrLen);
ColorArray[ArrLen - 1] := tmpCol;
IncEx(Y, SearchDensity);
end;
IncEx(X, SearchDensity);
end;
ClearSameIntegers(ColorArray);
Y := High(ColorArray);
SetLength(ColorTolerances, Y + 1);
SetLength(ColorToleranceArrayDuplicate, Y + 1);
for X := 0 to Y do
begin
Tolerance := 0;
while not SimilarColors(ColorArray[X], 7106421, Tolerance) do
Inc(Tolerance);
ColorTolerances[X] := Tolerance;
end;
ColorToleranceArrayDuplicate := ColorTolerances;
BubbleSort(ColorToleranceArrayDuplicate);
//InIntArrayEx(ColorArray, LowestToleranceColorPosition, ColorToleranceArrayDuplicate[0]);
InIntArrayEx(ColorTolerances, LowestToleranceColorPosition, ColorToleranceArrayDuplicate[0]);
Result := ColorArray[LowestToleranceColorPosition];
WriteLn(IntToStr(Result));
end;
procedure DebugTPA(TPA: TPointArray);
var
ClientBMP, Hi, I: Integer;
B: TBox;
Begin
B := GetTPABounds(TPA);
DisplayDebugImgWindow((B.x2 - B.x1) + 25, (B.y2 - B.y1) + 25);
ClientBMP := BitmapFromString(B.x2 - B.x1, B.y2 - B.y1, '');
CopyClientToBitmap(ClientBMP, B.x1, B.y1, b.x2, b.y2);
Hi := High(TPA);
for I := 0 to Hi do
FastSetPixel(ClientBMP, TPA[I].X - b.x1, TPA[I].Y - b.y1, 255);
SafeDrawBitmap(ClientBMP, GetDebugCanvas, 0, 0);
end;
procedure Main;
var
Col : Integer;
TPA: TPointArray;
begin
SetUpSRL;
ActivateClient;
Wait(500 + Random(500));
Col := ScanForRoadColor('w', 50, 5);
FindColorsTolerance(TPA, Col, MMX1, MMY1, MMX2, MMY2, 0);
DebugTPA(TPA);
GetApplication.BringToFront;
end;
begin
Main;
end.This kinda searches for the color the same way as my other walking function which I posted earlier. The point of this is to have a "general" road color (a mixture of 4 different road colors) and then scan for it, compare the gotten colors and result the one that is the most similar to the original color.
It finds the brown color which is around the minimap, no matter which color I compare colors against.
Sorry >__<"
Edit: What a nice 500th post? >___>""