Advertisement
WarPie90

Anchor correcting RSWalker for accuracy

May 1st, 2024
1,121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.80 KB | None | 0 0
  1. program new;
  2. {$DEFINE SRL_USE_REMOTEINPUt}
  3. {$I SRL/osr.simba}
  4.  
  5. function TRSWalker.GetMyPos_Barber(): TPoint;
  6. var
  7.   TPA: TPointArray;
  8.   err,me,anchor_mean,m: TPoint;
  9.   r: TRectangle;
  10.   anchor: TPoint = [3758, 2494];
  11.   b: TBox;
  12. begin
  13.   me := Self.GetMyPos();
  14.  
  15.  
  16.   // 1. covert `anchor` to minimap
  17.   m := Self.WorldToMM(me, anchor, minimap.GetCompassAngle(False));
  18.  
  19.   // 2. covert `anchor` to world location (and then some for finding)
  20.   r := Minimap.PointToMsRect(m, 1.5,1.5);  //scan larger than tile for object
  21.  
  22.   // limit to mainscreen exit if not in sight
  23.   b := r.Bounds();
  24.   b.LimitTo(MainScreen.Bounds);
  25.   if b.Area = 0 then Exit(p);
  26.  
  27.   // find the object - I use a red chair that is in which the mean is about 2 units high
  28.   srl.FindColors(TPA, CTS2(661620, 15, 0.16, 1.11), b);
  29.  
  30.   RSClient.Image.Clear();                             // can be removed
  31.  
  32.   // Mean of anchor, height of it (in my example 2)
  33.   // subtract it from whatever it was, call result err (error)
  34.   anchor_mean := TPA.Cluster(3).Biggest().Mean();
  35.   RSClient.Image.DrawCircle(anchor_mean, 5, $00FF00); // can be removed
  36.   RSClient.Image.DrawRect(r, 255);                    // can be removed
  37.  
  38.   // this is how much wrong RSW was in world pixels:
  39.   err := anchor-Self.MSToWorld(anchor_mean, 2);
  40.   WriteLn('RSW was: ', err, ' wrong');
  41.  
  42.   // add the error to RSW position `p` and return that shit
  43.   Result := me+err;
  44.  
  45.   // show corrected tile (can be removed):
  46.   m := Self.WorldToMM(Result, match, minimap.GetCompassAngle(False));
  47.   r := Minimap.PointToMsRect(m, 1,1);
  48.   RSClient.Image.DrawRect(r, $00FF00);
  49. end;
  50.  
  51. var
  52.   RSW: TRSWalker;
  53. begin
  54.   RSW.Setup();
  55.   MM2MS.ZoomLevel := 25;
  56.  
  57.   while True do
  58.   begin
  59.     WriteLn('Before: ', RSW.GetMyPos());
  60.     WriteLn('After : ', RSW.GetMyPos_barber());
  61.   end;
  62.  
  63. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement