Advertisement
WarPie90

Untitled

Jan 14th, 2015
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.63 KB | None | 0 0
  1. program new;
  2. {$I SRL/OSR.simba}
  3.  
  4. function FindColorsEx(const colors:TIntegerArray; B:TBox): TPointArray;
  5. var
  6.   TPA:TPointArray;
  7.   i:Int32;
  8. begin
  9.   for i:=0 to High(colors) do
  10.   begin
  11.     FindColors(TPA,colors[i], B.x1,B.y1,B.x2,B.y2);
  12.     Result := CombineTPA(TPA,Result);
  13.   end;
  14. end;
  15.  
  16. function __FixHPBars(var bars:T2DIntArray; TPA:TPointArray): TPointArray;
  17. var i:Int32;
  18. begin
  19.   FilterPointsBox(TPA,1,0,high(bars[0]),high(bars));
  20.   SortTPAByX(TPA,True);
  21.  
  22.   for i:=0 to High(TPA) do
  23.     if (Bars[TPA[i].y][TPA[i].x-1] <> 0) then
  24.       Bars[TPA[i].y][TPA[i].x] := 255;
  25. end;
  26.  
  27.  
  28. procedure __FindHPBars(var bars:T2DIntArray; var Result:TBoxArray);
  29. const
  30.   W = 29;
  31.   H = 4;
  32. var
  33.   wid,hei,y,x,yy:Int32;
  34.   bad:Boolean;
  35. begin
  36.   wid := Length(bars[0])-W-1;
  37.   hei := Length(bars)-5;
  38.   for y:=1 to hei do
  39.     for x:=1 to wid do
  40.       if (bars[y][x] <> 0) and (bars[y][x+w] <> 0) then
  41.         bars[y][x] := 254;
  42.  
  43.   for y:=1 to hei do
  44.     for x:=1 to wid do
  45.       if (bars[y][x] = 254) and ((bars[y][x-1] = 0) or (bars[y][x+1] = 255)) then
  46.       begin
  47.         bad := False;
  48.         for yy:=max(y-h,0) to y do
  49.           if bars[yy][x] = $00FF00 then
  50.           begin
  51.             bad := True;
  52.             break;
  53.           end;
  54.         if not bad then
  55.         begin
  56.           bars[y][x] := $00FF00;
  57.           Result += TBox([x,y,x+W,y+H]);
  58.         end;
  59.       end;
  60. end;
  61.  
  62.  
  63. function FindHPBars(area:TBox): TBoxArray;
  64. var
  65.   i,j:Int32;
  66.   TPA,splats:TPointArray;
  67.   mat:T2DIntArray;
  68.   B:TBox;
  69. begin
  70.   freeze();
  71.   TPA := FindColorsEx([$00FF00,$0000FF], area);
  72.   splats := FindColorsEx([16728128,11339523,5571843,
  73.                           192,197503,65889,
  74.                           $FFFFFF,0], area);
  75.   unfreeze();
  76.  
  77.   B := GetTPABounds(TPA);
  78.   OffsetTPA(splats, Point(-B.x1+1,-B.y1+1));
  79.   SetLength(mat, B.height()+2, B.width()+2);
  80.   for i:=0 to High(TPA) do
  81.     mat[(TPA[i].y-B.y1)+1][(TPA[i].x-B.x1)+1] := 255;
  82.  
  83.   __FixHPBars(mat, splats);
  84.   __FindHPBars(mat, result);
  85.   for i:=High(Result) downto 0 do
  86.   begin
  87.     if (mat[Result[i].y1,Result[i].x1] = 0) or
  88.        (mat[Result[i].y1,Result[i].x2] = 0) or
  89.        (mat[Result[i].y2,Result[i].x2] = 0) or
  90.        (mat[Result[i].y2,Result[i].x1] = 0) then
  91.       Result.Del(i)
  92.     else
  93.       Result[i].Offset([B.x1-1,B.y1-1]);
  94.   end;
  95. end;
  96.  
  97.  
  98. var
  99.   BMP:Integer;
  100.   TBA:TBoxArray;
  101.   i:Int32;
  102. begin
  103.   while True do
  104.   begin
  105.     TBA := FindHPBars(IntToBox(0,0,515,335));
  106.  
  107.     BMP := BitmapFromClient(IntToBox(0,0,515,335));
  108.     for i:=0 to High(TBA) do
  109.       DrawTPABitmap(BMP, EdgeFromBox(TBA[i]), $00FFFF);
  110.     ShowBitmap(bmp);
  111.     FreeBitmap(bmp);
  112.   end;
  113. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement