@@ -48,8 +48,8 @@ Main record used to interact with the {ref}`Minimap`.
4848 Polygon: TPolygon;
4949
5050 Compass: record
51- PreviousRadians: Single;
5251 Circle: TCircle;
52+ Accuracy: Double;
5353 end;
5454
5555 Mask: TPointArray;
@@ -224,22 +224,36 @@ begin
224224end;
225225
226226
227+ (*
228+ ## Minimap.Compass
229+ The minimap compass refers to the small compass on the top left corner of the
230+ minimap:
231+ ```{figure} ../../images/compass.png
232+ ```
233+ The following properties are used to read and set the compass angle as both
234+ radians and degrees as needed.
235+ *)
227236
228237(*
229- ## Minimap.CompassRadians
238+ ### Minimap.CompassRadians
230239```pascal
231240property TRSMinimap.CompassRadians: Single;
241+ property TRSMinimap.CompassRadians(radians: Single): Boolean;
242+ property TRSMinimap.CompassRadians(minRadians, maxRadians: Single): Boolean;
232243```
233- Returns the minimap compass angle as radians.
244+ Returns or sets the minimap compass angle as radians.
245+
246+ The accuracy can be controlled through the `Minimap.Compass.Accuracy` variable
247+ and it's value should be in radians. It's default is aproximately
248+ 5º (`0.03*PI`).
234249
235250Credits: [slacky](https://slacky.one/)
236251
237252Example:
238253```pascal
239254WriteLn Minimap.CompassRadians;
240- ```
241- If you are not sure what the compass refers to, it refers to this:
242- ```{figure} ../../images/compass.png
255+ WriteLn Minimap.CompassRadians := PI;
256+ WriteLn Minimap.CompassRadians;
243257```
244258*)
245259property TRSMinimap.CompassRadians: Single;
@@ -288,108 +302,103 @@ begin
288302 Result := Result + TAU;
289303end;
290304
291- (*
292- ## Minimap.CompassDegrees
293- ```pascal
294- property TRSMinimap.CompassDegrees: Single;
295- ```
296- Returns the minimap compass angle as radians.
297-
298- Credits: [slacky](https://slacky.one/)
299-
300- Example:
301- ```pascal
302- WriteLn Minimap.CompassDegrees;
303- ```
304- If you are not sure what the compass refers to, it refers to this:
305- ```{figure} ../../images/compass.png
306- ```
307- *)
308- property TRSMinimap.CompassDegrees: Single;
309- begin
310- Result := RadToDeg(Self.CompassRadians);
311- end;
312-
313-
314- (*
315- ## Minimap.SetCompassAngle
316- ```pascal
317- function TRSMinimap.SetCompassAngleEx(degrees, accuracy: Single): Boolean;
318- function TRSMinimap.SetCompassAngle(degrees: Single): Boolean;
319- function TRSMinimap.SetCompassAngle(minDegrees, maxDegrees: Single; accuracy: Single = 5): Boolean; overload;
320- ```
321- Sets the current compass angle.
322- If you specify a minimum and a maximum angle a gaussian distribution will be used.
323-
324- Example:
325- ```pascal
326- Minimap.SetCompassAngle(180);
327- ```
328- *)
329- function TRSMinimap.SetCompassAngleEx(degrees, accuracy: Single): Boolean;
305+ property TRSMinimap.CompassRadians(radians: Double): Boolean;
330306const
331- DEG_PER_PIXEL = 2.83 ;
307+ RAD_PER_PIXEL: Double = 162.2004206 ;
332308var
333309 available: TBox;
334- remaining: Integer ;
335- left2right : Boolean;
310+ remain, oneDeg: Double ;
311+ clockwise : Boolean;
336312 destination: TPoint;
337313 pixels: Integer;
338314 timeout: UInt64;
339315begin
340316 available := RSClient.Bounds.Expand(-10);
341- degrees := DegNormalize(degrees );
317+ radians := RadNormalize(radians );
342318 timeout := Time() + RandomMean(6000, 8000);
319+ oneDeg := DegToRad(1);
343320
344321 repeat
345- remaining := Round(DeltaAngle(Self.CompassDegrees, degrees));
346- if Abs(remaining) <= accuracy then Exit(True);
322+ remain := DeltaAngle(Self.CompassRadians, radians, TAU);
323+ if Abs(remain) <= Self.Compass.Accuracy then
324+ Exit(True);
347325
348- pixels := Round(Abs(DeltaAngle(Self.CompassDegrees, degrees)) * DEG_PER_PIXEL );
349- left2right := InRange(remaining, 1, 180 ) or (remaining < -180 );
326+ pixels := Round(Abs(remain) * RAD_PER_PIXEL );
327+ clockwise := InRange(remain, oneDeg, PI ) or (remain < -PI );
350328
351- if left2right then
329+ if clockwise then
352330 begin
353331 if (not available.Contains(Target.MouseXY)) or ((Target.MouseY + 200 > available.Y2) or (Target.MouseX + pixels > available.X2)) then
354- Target.MouseMove ([available.X1, available.Y1, available.X1 + 200, available.Y1 + 200]);
332+ Mouse.Move ([available.X1, available.Y1, available.X1 + 200, available.Y1 + 200]);
355333
356334 destination.X := Target.MouseX + pixels;
357335 end
358336 else
359337 begin
360338 if (not available.Contains(Target.MouseXY)) or ((Target.MouseY + 200 > available.Y2) or (Target.MouseX - pixels < available.X1)) then
361- Target.MouseMove ([available.X2 - 200, available.Y1, available.X2, available.Y1 + 200]);
339+ Mouse.Move ([available.X2 - 200, available.Y1, available.X2, available.Y1 + 200]);
362340
363- destination.X := Target.MouseX - Pixels ;
341+ destination.X := Target.MouseX - pixels ;
364342 end;
365343
366344 destination.Y := Random(Target.MouseY + 100, available.Y2);
367345
368- Target.MouseDown(EMouseButton.MIDDLE);
369- Target.MouseMove(destination);
370- Target.MouseUp(EMouseButton.MIDDLE);
371-
372- Sleep(100, 1000, ERandomDir.LEFT);
346+ Mouse.Drag(destination, EMouseButton.MIDDLE);
347+ Biometrics.Sleep(100, 1000, ERandomDir.LEFT);
373348 until Time() > timeout;
374349
375- WriteLn GetDebugLn('Minimap', 'SetCompassAngle timed out.', ELogLevel.WARN);
350+ WriteLn GetDebugLn('Minimap', 'Setting `CompassRadians` timed out.', ELogLevel.WARN);
351+
376352 if not RSClient.IsLoggedIn() then
377353 Login.DoLogin()
378354 else
379355 WriteLn GetDebugLn('Minimap', 'Make sure the setting "Middle mouse button controls the camera" is enabled in the game settings.', ELogLevel.WARN);
380356end;
381357
382- function TRSMinimap.SetCompassAngle(degrees: Single): Boolean;
358+ property TRSMinimap.CompassRadians(minRadians, maxRadians: Single): Boolean;
359+ var
360+ radians: Single;
383361begin
384- Result := Self.SetCompassAngleEx(degrees, 5);
362+ radians := RandomMean(RadNormalize(minRadians), RadNormalize(maxRadians));
363+ Result := Self.CompassRadians := radians;
385364end;
386365
387- function TRSMinimap.SetCompassAngle(minDegrees, maxDegrees: Single; accuracy: Single = 5): Boolean; overload;
388- var
389- degrees: Single;
366+
367+ (*
368+ ### Minimap.CompassDegrees
369+ ```pascal
370+ property TRSMinimap.CompassDegrees: Single;
371+ property TRSMinimap.CompassDegrees(degrees: Single): Boolean;
372+ property TRSMinimap.CompassDegrees(minDegrees, maxDegrees: Single): Boolean;
373+ ```
374+ Returns or sets the minimap compass angle as degrees.
375+
376+ The accuracy can be controlled through the `Minimap.Compass.Accuracy` variable
377+ and it's value should be in radians. It's default is aproximately
378+ 5º (`0.03*PI`).
379+
380+ Example:
381+ ```pascal
382+ WriteLn Minimap.CompassDegrees;
383+ WriteLn Minimap.CompassDegrees := 180;
384+ WriteLn Minimap.CompassDegrees;
385+ ```
386+ If you are not sure what the compass refers to, check the image at the end of
387+ {ref}`Minimap.CompassRadians`.
388+ *)
389+ property TRSMinimap.CompassDegrees: Single;
390+ begin
391+ Result := RadToDeg(Self.CompassRadians);
392+ end;
393+
394+ property TRSMinimap.CompassDegrees(degrees: Single): Boolean;
395+ begin
396+ Result := Self.CompassRadians := DegToRad(degrees);
397+ end;
398+
399+ property TRSMinimap.CompassDegrees(minDegrees, maxDegrees: Single): Boolean;
390400begin
391- degrees := RandomMean(DegNormalize(minDegrees), DegNormalize(maxDegrees));
392- Result := Self.SetCompassAngleEx(degrees, accuracy);
401+ Result := Self.CompassRadians[DegToRad(minDegrees), DegToRad(maxDegrees)];
393402end;
394403
395404
@@ -639,6 +648,66 @@ begin
639648end;
640649
641650
651+ (*
652+ ## Minimap.CountColor
653+ ```pascal
654+ function TRSMinimap.CountColor(color: TColor; tolerance: Single = 0): Integer;
655+ function TRSMinimap.CountColor(color: TColorTolerance): Integer; overload;
656+ ```
657+ Counts the specified `color` on the {ref}`Minimap`.
658+
659+ Example:
660+ ```pascal
661+ WriteLn Minimap.CountColor($FFFFFF);
662+ ```
663+ *)
664+ function TRSMinimap.CountColor(color: TColor; tolerance: Single = 0): Integer;
665+ var
666+ tpa: TPointArray;
667+ begin
668+ tpa := Target.FindColor(color, tolerance, Self.Bounds);
669+ Result := tpa.ExtractPolygon(Self.Polygon).Length;
670+ end;
671+
672+ function TRSMinimap.CountColor(color: TColorTolerance): Integer; overload;
673+ var
674+ tpa: TPointArray;
675+ begin
676+ tpa := Target.FindColor(color, Self.Bounds);
677+ Result := tpa.ExtractPolygon(Self.Polygon).Length;
678+ end;
679+
680+
681+ (*
682+ ## Minimap.ColorPercent
683+ ```pascal
684+ function TRSMinimap.ColorPercent(color: TColor; tolerance: Single = 0): Single;
685+ function TRSMinimap.ColorPercent(color: TColorTolerance): Single; overload;
686+ ```
687+ Counts the percentage of the specified `color` on the {ref}`Minimap`.
688+
689+ Example:
690+ ```pascal
691+ WriteLn Minimap.ColorPercent($FFFFFF);
692+ ```
693+ *)
694+ function TRSMinimap.ColorPercent(color: TColor; tolerance: Single = 0): Single;
695+ var
696+ count: Integer;
697+ begin
698+ count := Self.CountColor(color, tolerance);
699+ Result := count / Self.Polygon.Area;
700+ end;
701+
702+ function TRSMinimap.ColorPercent(color: TColorTolerance): Single; overload;
703+ var
704+ count: Integer;
705+ begin
706+ count := Self.CountColor(color);
707+ Result := count / Self.Polygon.Area;
708+ end;
709+
710+
642711(*
643712## Minimap.Normalize
644713```pascal
0 commit comments