Advertisement
WarPie90

FindEdgeFurnace

Jan 22nd, 2018
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.36 KB | None | 0 0
  1. {$I srl/osr.simba}
  2. {$I srl/utils/slacktree.simba}
  3. type
  4.   TMSTile = record Bottom, Top: TRectangle; end;
  5.   TMSTiles = array of TMSTile;
  6.  
  7. var
  8.   BMP: TMufasaBitmap;
  9.  
  10. function DrawCuboid(m: TMufasaBitmap; Top, Btm: TRectangle; color: Int32): Boolean;
  11. begin
  12.   try m.DrawTPA(TRectangle([Top.Left, Top.Btm, Btm.Btm, Btm.Left]).ToTPA.Connect(), color); except end;
  13.   try m.DrawTPA(TRectangle([Top.Top, Top.Right, Btm.Right, Btm.Top]).ToTPA.Connect(), color); except end;
  14.   try m.DrawTPA(TRectangle([Top.Top, Btm.Top, Btm.Left, Top.Left]).ToTPA.Connect(), color); except end;
  15.   try m.DrawTPA(TRectangle([Top.Right, Btm.Right, Btm.Btm, Top.Btm]).ToTPA.Connect(), color); except end;
  16.   m.UpdateDebugImage();
  17. end;
  18.  
  19.  
  20. function MSToMM(MS: TPoint; Height: Int32): TPoint;
  21. var
  22.   x,y,i,c: Int32;
  23.   a: Double;
  24.   best, pt: TPoint;
  25.   arr: Vector3Array;
  26.   TPA: TPointArray;
  27. begin
  28.   a := Minimap.GetCompassAngle(False);
  29.  
  30.   for x:=MM2MS.MMCX-32 to MM2MS.MMCX+32 do
  31.     for y:=MM2MS.MMCY-32 to MM2MS.MMCY+32 do
  32.     begin
  33.       SetLength(arr, c+1);
  34.       arr[c] := Vector3([x,y,height]);
  35.       arr[c] := arr[c].RotateXY(-a, MM2MS.MMCX,MM2MS.MMCY);
  36.       Inc(c);
  37.     end;
  38.  
  39.   TPA := Minimap.ArrToMs(Copy(arr), a);
  40.   for i:=0 to High(TPA) do
  41.     if Distance(TPA[i], MS) < Distance(best, MS) then
  42.     begin
  43.       best := TPA[i];
  44.       Result := arr[i].ToVec2.ToPoint;
  45.     end;
  46. end;
  47.  
  48. function FindBestBrickMM(MM,MS: TPoint; Height: Int32): TPoint;
  49. var
  50.   x,y: Int32;
  51.   best,test: TPoint;
  52.   angle: Double;
  53. begin
  54.   angle := Minimap.GetCompassAngle(False);
  55.   for x:=MM.x-2 to MM.x+2 do
  56.     for y:=MM.y-2 to MM.y+2 do
  57.     begin
  58.       test := Minimap.VecToMsRect([x,y, height], angle).Partition(2,1)[0].Mean;
  59.       if Distance(test, MS) < Distance(best, MS) then
  60.       begin
  61.         best := test;
  62.         Result := [x,y];
  63.       end;
  64.     end;
  65. end;
  66.  
  67. function FindBrickOwen(out mm: TPoint): Boolean;
  68. var
  69.   B: TBox;
  70.   TPA,TPA1,TPA2,TPA3: TPointArray;
  71.   pipe: TPoint;
  72.   ATPA: T2DPointArray;
  73. begin
  74.   B := Mainscreen.GetBounds();
  75.   if (srl.FindColors(TPA1, CTS2(2438740, 10, 0.11, 0.26), B) > 15) and
  76.      (srl.FindColors(TPA2, CTS2(7895169, 15), B) > 5) and
  77.      (srl.FindColors(TPA3, CTS2(986899,  8),  B) > 2) then
  78.   begin
  79.     ATPA := TPA3.Cluster(4);
  80.     ATPA.FilterSize(10, __GT__);
  81.     TPA3 := ATPA.Merge();
  82.  
  83.     TPA := TPAOverlap(TPA2,TPA3,5);
  84.     if Length(TPA) < 5 then Exit();
  85.  
  86.     TPA := TPAOverlap(TPA,TPA1,4);
  87.     if Length(TPA) < 5 then Exit();
  88.  
  89.     ATPA := ClusterTPA(TPA, 6);
  90.     SortATPAFromSize(ATPA, 0, False);
  91.  
  92.     pipe := ATPA[0].Mean();
  93.     mm := FindBestBrickMM(MSToMM(pipe, 7), pipe, 7);
  94.     Result := True;
  95.   end;
  96. end;
  97.  
  98.  
  99. function GetFurnaceTile(out Tile: TMSTile): Boolean;
  100. var
  101.   mm: TPoint;
  102.   t: Double;
  103. begin
  104.   t := PerformanceTimer;
  105.   if FindBrickOwen(mm) then
  106.   begin
  107.     Tile.Bottom := Minimap.VecToMsRect([mm.x,mm.y,-1]);
  108.     Tile.Top    := Minimap.VecToMsRect([mm.x,mm.y, 7]);
  109.     Result := True;
  110.   end;
  111.   WriteLn(PerformanceTimer - t);
  112. end;
  113.  
  114. var
  115.   Tile: TMSTile;
  116.   top, btm: TRectangle;
  117. begin
  118.   while True do
  119.   begin
  120.     BMP := GetMufasaBitmap(BitmapFromClient(GetClientBounds()));
  121.  
  122.     if GetFurnaceTile(Tile) then
  123.     begin
  124.       top := Tile.Top.Partition(2,1)[0];
  125.       btm := Tile.Bottom.Partition(2,1)[0];
  126.  
  127.       DrawCuboid(BMP, top, btm, clLime);
  128.     end;
  129.  
  130.     ShowBitmap(BMP.GetIndex());
  131.     BMP.Free();
  132.   end;
  133. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement