In my perception MM compass angle has nothing to do with this or is at least unrelated to the problem. As you see from the Minimap picture above, the Rocks are my anchor. Now sometimes my Player becomes hyperactive and fweee… the Rocks just disappear out of the MM. So, now I need to click way back to the point I last registered the RockDTM, to get me back safely.
Today I finished a WillowBot Looter, that loots the Willow-dropping-bots left of the rats (there are two on the MM screen + drops) and neatly burns them. Just a couple of lines, fits wonderfully into my framework :)
EDIT: I am standing there. I have copa'd my procs into yours, but it doesn't work. Correct me pls.
program Leash;
{.include SRL\SRL.scar}
var
RockColor, RockDTM:Integer;
Procedure AssembleRockDTM;
var
DTMSubPoints: array[0..2] of TDTMPointDef;
DTMMainPoint: TDTMPointDef;
TempTDTM: TDTM;
begin
DTMMainPoint.x:=621;
DTMMainPoint.y:=88;
DTMMainPoint.areasize:=1;
DTMMainPoint.areashape:=0;
DTMMainPoint.color:=0;
DTMMainPoint.tolerance:=255;
DTMSubPoints[0].x:=637;
DTMSubPoints[0].y:=77;
DTMSubPoints[0].areasize:=1;
DTMSubPoints[0].areashape:=0;
DTMSubPoints[0].color:=RockColor;
DTMSubPoints[0].tolerance:=0;
DTMSubPoints[1].x:=645;
DTMSubPoints[1].y:=82;
DTMSubPoints[1].areasize:=1;
DTMSubPoints[1].areashape:=0;
DTMSubPoints[1].color:=RockColor;
DTMSubPoints[1].tolerance:=0;
DTMSubPoints[2].x:=636;
DTMSubPoints[2].y:=96;
DTMSubPoints[2].areasize:=1;
DTMSubPoints[2].areashape:=0;
DTMSubPoints[2].color:=RockColor;
DTMSubPoints[2].tolerance:=0;
TempTDTM.MainPoint := DTMMainPoint;
TempTDTM.SubPoints := DTMSubPoints;
RockDTM := AddDTM(TempTDTM);
end;
Function GetMyColorTPA(BaseColor, MinSize, MaxSize, x1, y1, x2, y2, tol:integer): Integer;
var
TPA: TPointArray;
begin
if FindColorsTolerance(TPA, BaseColor, x1, y1, x2, y2, tol) then
begin
If (High(TPA) > MinSize) and (High(TPA) < MaxSize) then
begin
Result := GetColor(TPA[0].x, TPA[0].y);
Writeln('TheColor = ' + IntToStr(Result));
end
end
else
begin
WriteLn('Color not found, Terminating Script');
TerminateScript;
end;
end;
Function GetAnchorPoint( TAnchorPoint:TPoint):TPoint;
var
WhichAngle: Extended;
begin
if FindDtmRotated(RockDTM, TAnchorPoint.x, TAnchorPoint.y, MMX1, MMY1, MMX2, MMY2, rs_GetCompassAngleRadians-pi/4, rs_GetCompassAngleRadians+pi/4, 0.05,
WhichAngle) then
begin
Result := TAnchorPoint;
Exit;
end
else
end;
Function AngleToNorth(X, Y, Z: Integer; Custom: Boolean): Integer;
var
N: Tpoint;
C, H: Integer;
Begin
X:=X - MMCX;
Y:=Y - MMCY;
H:=Round(Hypot(X, Y));
X:=76 * X / H;
Y:=76 * Y / H;
If Custom then C:=Z
else
C:=round(RS_GetCompassAngleDegrees);
N:=Inttopoint(Round(-1000 * Sin(Radians(C))),Round(-1000 * Cos(Radians(C))));
H:=Round(Hypot(N.x, N.y));
N:=Inttopoint(76 * N.x / H, 76 * N.y / H);
Result:=Round(Degrees(ArcCos((N.x * X + N.y * Y)/(Hypot(X, Y) * Hypot(N.x, N.y)))));
If Result > 0 then
Begin
If C < 180 then
Begin
If ((X < 0) and (Y < N.y)) or ((X > 0) and (Y < -1 * N.y)) then Result:=360 - Result;
End else
If ((X < 0) and (Y > -1 * N.y)) or ((X > 0) and (Y > N.y)) then Result:=360 - Result;
End;
End;
Procedure WalkAngle(Z, H: Integer; Back, Custom: Boolean);
var
P: Tpoint;
R, C: Integer;
Begin
If back then Z:=Z+180;
C:=round(RS_GetCompassAngleDegrees);
P.x:=Round(-100 * Sin(Radians(C + Z)));
P.y:=Round(-100 * Cos(Radians(C + Z)));
If Not Custom then H:=Round(Hypot(P.x, P.y));
R:=randomrange(20,70);
P.x:=MMCX + R * P.x / H;
P.y:=MMCY + R * P.y / H;
Mouse(P.x, P.y, 0, 0, true);
End;
Procedure PullTheLeash(X, Y: Integer);
var
Dist, Walked, Angle: Integer;
Begin
Dist:=Round(Hypot(X - MMCX, Y - MMCY));
Writeln('Distance is '+ IntToStr(Dist));
Angle:=AngleToNorth(x, y, 0, false);
Writeln('Angle is '+ IntToStr(Angle));
repeat
While Dist > 75 Do
Begin
Walked:=RandomRange( 1, 75);
WalkAngle( Angle, Walked, False, False);
Dist:= Dist - Walked;
Wait(5000);
While FlagPresent Do Wait(Random(100));
End;
While Dist < 75 Do
Begin
Walked:=Random(Dist);
Dist:= Dist - Walked;
WalkAngle( Angle, Dist - Walked, False, False);
Wait(5000);
While FlagPresent Do Wait(Random(100));
End;
until Dist < 10;
End;
var ThePoint:Tpoint;
begin
Setupsrl;
RockColor := GetMyColorTPA(5790555, 50, 100, 610, 70, 660, 128, 10);
AssembleRockDTM;
repeat
GetAnchorPoint(ThePoint);
PullTheLeash(ThePoint.x,ThePoint.y);
FFlag(0);
until false;
end.