caused
2009-08-25 13:20:17
Heya =).
Sometimes you need to have the Compass aligned better than MakeCompass Does. Especially for map walking it may be crucial.
So this function aligns the compass with makecompass and than corrects it at any degree you want.
Usage:
Example:
CorrectCompass(15,'N');
Makes the Compass 'N' and corrects it till it finds an 15 px long outline. The higher the number, the more accurate it will be, but the longer it will take.
Help me improving this :'D.. I know it can be shortenend ALOT. And also improved alot. It may even be done before :3.. But i'd like to finish my function anyways =).
Sometimes you need to have the Compass aligned better than MakeCompass Does. Especially for map walking it may be crucial.
So this function aligns the compass with makecompass and than corrects it at any degree you want.
Usage:
Example:
CorrectCompass(15,'N');
Makes the Compass 'N' and corrects it till it finds an 15 px long outline. The higher the number, the more accurate it will be, but the longer it will take.
Help me improving this :'D.. I know it can be shortenend ALOT. And also improved alot. It may even be done before :3.. But i'd like to finish my function anyways =).
//Usage: First Argument is the accuracy, the higher the more accurate, but //the longer it will correct the compass, Second argument is the point of the //compass (n,s,w,e)...
function CorrectCompass(MinLine:Integer; Align:String):Boolean;
var
Cols : TpointArray;
TempColor, CLine,x,y,i,j,k,tempx, tempy,Timer,last : Integer;
wline : TautocolorInfo;
Nonono : Boolean;
FirstRun : Boolean;
TempCline : Array of Integer;
movedright, movedleft,lastmove : Boolean;
begin
FirstRun := TRUE;
MakeCompass(Align);
MarkTime(Timer);
ColorToleranceSPeed(2);
//AutoColor for them white lines
with wline do
begin
MinCount := 30;
Color := 15987692;
HueMod := 35.00;
SatMod := 21.69;
LumTol := 3;
MinR := 225; MaxR := 254;
MinG := 225; MaxG := 254;
MinB := 225; MaxB := 254;
MinX := 77.57; MaxX := 85.77;
MinY := 79.55; MaxY := 90.31;
MinZ := 86.42; MaxZ := 100.90;
end;
repeat
ColorToleranceSpeed(2);
// WriteLn('START');
TempColor := FindColorRecordEx(x, y, wline, MMX1, MMY1, MMX2, MMY2, TRUE);
// WriteLn('Found Line Color: '+IntTostr(Tempcolor));
ColorToleranceSpeed(0);
FindColorsTolerance(Cols, TempColor,MMX1, MMY1, MMX2, MMY2,11);
If TempColor = 0 then
begin
WriteLn('Couldnt Find White Outline');
exit;
end;
Case Align Of
'n':
begin
If (rs_GetCompassAngleDegrees > 20) or (rs_GetCompassAngleDegrees < 340) then
begin
MakeCompass(Align);
end;
end;
's':
begin
If (rs_GetCompassAngleDegrees > 200) or (rs_GetCompassAngleDegrees < 160) then
begin
MakeCompass(Align);
end;
end;
'w':
begin
If (rs_GetCompassAngleDegrees > 290) or (rs_GetCompassAngleDegrees < 240) then
begin
MakeCompass(Align);
end;
end;
'o':
begin
If (rs_GetCompassAngleDegrees > 110) or (rs_GetCompassAngleDegrees < 70) then
begin
MakeCompass(Align);
end;
end;
end;
repeat
//First Run
SetArrayLength(TempCline, high(Cols));
If SimilarColors(GetColor(Cols[i].x,Cols[i].y),TempColor,11) then
begin
// WriteLn('Checking Next Line');
repeat
inc(j);
If SimilarColors(GetColor(Cols[i].x+j,Cols[i].y),TempColor,11) then
begin
Inc(Cline);
end else
begin
Nonono := TRUE;
end;
until(CLine = MinLine) OR Nonono;
Nonono := FALSE;
j := 0;
TempCline[i] := Cline;
If Cline < MinLine then
Cline := 0
else
MoveMouse(Cols[i].x,Cols[i].y);
end;
inc(i);
Until(CLine >=MinLine) Or (i >= high(cols)-1);
If Cline >= MinLine then
begin
WriteLn('Correcting Took Seconds:'+ IntToStr(TimeFromMark(Timer)/1000));
WriteLn('STRAIGHT');
Result := TRUE;
exit;
end;
If TimeFromMark(Timer) >= 60000 then
begin
WriteLn('Correcting Failed after 60secs');
Result := FALSE;
MakeCompass(Align);
exit;
end;
//Find biggest temp number
try
BubbleSortB(TempCline);
except
end;
//Check if the movement was good
If (CLine < MinLine) AND not FirstRun then
begin
WriteLn('TempCline[i]: '+inttostr(TempCline[i]));
WriteLn('TempCline[0]: '+inttostr(TempCline[0]));
WriteLn('last: '+inttostr(last));
If last < TempCline[0] then
lastmove := false
else
lastmove := true;
end;
If (CLine < MinLine) AND not FirstRun then
begin
wait(100);
//MakeCompass(Align);
If lastmove then
begin
WriteLn('lastmove true');
if movedleft = true then
begin
movedleft:=false;
movedright := TRUE;
SendArrowWait(1,Random(175))
end else
begin
movedleft:= True;
movedright := false;
SendArrowWait(3,Random(175));
end
end else
begin
WriteLn('last move false');
if movedleft = false then
begin
movedleft:=true;
movedright := false;
SendArrowWait(3,Random(175))
end else
begin
movedleft:= false;
movedright := true;
SendArrowWait(1,Random(175));
end;
end;
end;
WriteLn('Compass angle');
WriteLn(rs_GetCompassAngleDegrees);
i:=0; //Reset i
If (CLine < MinLine) AND FirstRun then
begin
MakeCompass(Align);
Case Random(2) of
0 :
begin
movedleft:=false;
SendArrowWait(1,Random(200));
movedright := TRUE;
end;
1 :
begin
movedright:=false;
SendArrowWait(3,Random(200));
movedleft := TRUE;
end;
end;
end;
try last := TempCline[0]; except end;
WriteLn('LAST');
WRiteLn(last);
FirstRun := FALSE;
wait(200);
Until(CLine >=MinLine);
If CLine >=MinLine then
Result := TRUE
else
Result := FALSE;
end;