Advertisement
WarPie90

OSR - DoorIsOpen

Feb 7th, 2015
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.67 KB | None | 0 0
  1. {$DEFINE SMART}
  2. {$I SRL/OSR.simba}
  3.  
  4.  
  5. const
  6.   Color_Door: TColorEx = [2509163, 10, [2, [0.07, 0.40]]];
  7.  
  8. function GetColor(AColor: TColorEx; Area: TBox): TPointArray; overload;
  9. begin
  10.   with AColor do
  11.     FindColorsTolerance(Result, Color, Area, Tolerance, Settings);
  12. end;
  13.  
  14. function Modulo(X,Y:Double): Double;
  15. begin
  16.   Result := X - Floor(X / Y) * Y;
  17. end;
  18.  
  19. function DeltaAngle(DegA,DegB:Double; R:Double=360): Double;
  20. begin
  21.   Result := Modulo((DegA - DegB + R/2), R) - R/2;
  22. end;
  23.  
  24. function Door(): Boolean;
  25.  
  26.   function mbrAngle(mbr: TPointArray): Double;
  27.   begin
  28.     if Distance(mbr[0], mbr[3]) < Distance(mbr[0], mbr[1]) then
  29.       Result := Modulo(ArcTan2((mbr[0].Y-mbr[1].Y), (mbr[0].X-mbr[1].X)),PI*2)
  30.     else
  31.       Result := Modulo(ArcTan2((mbr[0].Y-mbr[3].Y), (mbr[0].X-mbr[3].X)),PI*2);
  32.     if Result > PI then
  33.       Result := Result-PI*2;
  34.   end;
  35. const
  36.   DOOR_WIDTH = 35;
  37.   DOOR_HEIGHT = 5;
  38. var
  39.   TPA: TPointArray;
  40.   ATPA: T2DPointArray;
  41.   i,W,H, compass,doorAngle:Int32;
  42. begin
  43.   ATPA := ClusterTPA(GetColor(Color_Door, MainScreen.GetBounds()), 1);
  44.   for i := 0 to High(ATPA) do
  45.   begin
  46.     TPA := MinAreaRectEx(FindTPAEdges(ATPA[i]), W, H);
  47.  
  48.     if InRange(W, DOOR_WIDTH - 8, DOOR_WIDTH + 8) and
  49.        InRange(H, DOOR_HEIGHT - 3, DOOR_HEIGHT + 3) then
  50.       begin
  51.         compass := Round(Modulo(Minimap.GetCompassAngle(),180));
  52.         doorAngle := 90+round(Degrees(mbrAngle(TPA)));
  53.         Result := not (Abs(DeltaAngle(compass, doorAngle,180)) < 30);
  54.         Exit;
  55.       end;
  56.   end;
  57.  
  58. end;
  59.  
  60. begin
  61.   Srl.DisableDebug := True;
  62.   Smart.EnableDrawing := True;
  63.   Smart.Init();
  64.   if Door() then WriteLn('Open') else WriteLn('Closed');
  65. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement