SRL Archive - Help and Support

EC! needs halp with newb function ..


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? >___>""

Boreas

2009-01-19 14:25:37

InCircle?

    for Y := MY1 to MY2 do
begin
if InCircle(x,y,mmcx,mmcy,76) then
begin
tmpCol := GetColor(X, Y);
Inc(ArrLen);
SetArrayLength(ColorArray, ArrLen);
ColorArray[ArrLen - 1] := tmpCol;
IncEx(Y, SearchDensity);
end;
end;

EvilChicken!

2009-01-19 15:54:11

Long story short:
Sometimes it works, sometimes it doesn't.
It worked now, thank you.

^^

Boreas

2009-01-19 16:01:20

Np. Where is 7106421 from?

noidea

2009-01-19 16:03:04

From: Boreas
Np. Where is 7106421 from?


Isnt that Varrock road colour..?

EvilChicken!

2009-01-19 16:19:05

From: Boreas
Np. Where is 7106421 from?


>___<"
It's a mixture of Varrock, Lumbrdge, and Falador road color.
Really useless function, now that I think about it.

Well, at least this is the first thing I've ever made that uses sorting, so I guess I did learn something.
Though, it would be nice if I could find a way to modify this function into becoming useful.

Wizzup?

2009-01-19 19:45:50

I see a Bubblesort.
Bubblesort is slow. I suggest you use the Quicksort algorithm. (There are better ones, but I think QuickSort is in SCAR)

Bobarkinator

2009-01-19 21:47:10

From: Wizzup?
I see a Bubblesort.
Bubblesort is slow. I suggest you use the Quicksort algorithm. (There are better ones, but I think QuickSort is in SCAR)


Quicksort is also the fastest.

http://www.iti.fh-flensburg.de/lang/algorithmen/sortieren/sortcontest/sortcontest.htm

EvilChicken!

2009-01-20 00:11:31

From: Wizzup?
I see a Bubblesort.
Bubblesort is slow. I suggest you use the Quicksort algorithm. (There are better ones, but I think QuickSort is in SCAR)


Thanks! :)
I tried to use QuickSort, but for some reason it gave me runtime errors when BubbleSort didn't, but I think I fixed that error now.