WarPie90

FindBankSlots

Jan 29th, 2016
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.79 KB | None | 0 0
  1. program new;
  2. {$I SRL/OSR.simba}
  3.  
  4. function FindBankSlots(color:Int32=3424329; tol:Int32=45): TBoxArray;
  5. var
  6.   bmp,w,h,x,y,i,j:Int32;
  7.   arr:array of record top,btm:Int32; end;
  8.   temp:TIntegerArray;
  9.   rows:TBoxArray;
  10.   clear:Boolean;
  11.   B:TBox;
  12.   client:TBox = [73,81,456,293];
  13. begin
  14.   rows := client.Partition(1,8);
  15.   rows.ModifySide('x2',-15);
  16.  
  17.   bmp := BitmapFromClient(client.x1,client.y1, client.x2,client.y2);
  18.   GetBitmapSize(bmp, W,H);
  19.  
  20.   //find all lines where there are no obstacles
  21.   // -> The vertical separation between items
  22.   for y:=0 to H-1 do
  23.   begin
  24.     clear := True;
  25.     for x:=0 to W-1 do
  26.       if not SimilarColors(FastGetPixel(bmp,x,y),color,tol) then
  27.       begin
  28.         clear := False;
  29.         break;
  30.       end;
  31.     if clear then
  32.       temp.Append(y);
  33.   end;
  34.   FreeBitmap(bmp);
  35.  
  36.   //find the upper and the lower part of the vertical separation line
  37.   SetLength(arr, Length(temp));
  38.   for i:=0 to High(temp)-1 do
  39.   begin
  40.     y := temp[i];
  41.     while (temp[i] = temp[i+1]-1) and (i < High(temp)) do Inc(i);
  42.     arr[j].top := y;
  43.     arr[j].btm := temp[i];
  44.     Inc(j);
  45.   end;
  46.   arr[j].top := temp[high(temp)];
  47.   arr[j].btm := arr[j].top;
  48.  
  49.   //compute the resulting boxes
  50.   for i:=0 to j-1 do
  51.     for j:=0 to High(rows) do
  52.     begin
  53.       B    := rows[j];
  54.       B.y1 := client.y1 + arr[i+0].btm + 1;
  55.       B.y2 := client.y1 + arr[i+1].top;
  56.       if Abs(B.y1-B.y2) > 3 then
  57.         Result.Append(B);
  58.     end;
  59. end;
  60.  
  61.  
  62. var
  63.   arr:TBoxArray;
  64.   bmp,i:Int32;
  65. begin
  66.   while 1 do
  67.   begin
  68.     bmp := BitmapFromClient(0,0,764,502);
  69.  
  70.     arr := FindBankSlots();
  71.     for i:=0 to High(arr) do
  72.       if (arr[i].Width > 1) and (arr[i].Height() > 1) then
  73.         DrawTPABitmap(bmp, EdgeFromBox(arr[i]), 255);
  74.  
  75.     ShowBitmap(bmp);
  76.     FreeBitmap(bmp);
  77.   end;
  78. end.
Add Comment
Please, Sign In to add comment