euphemism

Untitled

Feb 16th, 2012
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.71 KB | None | 0 0
  1. function FindRocks(RockType: Integer; var Return: TPointArray): Boolean;
  2. var
  3.   x1, y1, x2, y2, W, H: Integer;
  4.   BadRocks, CTS, ClientBitmap, I, L, Len, Len1: Integer;
  5.   ClientMufasaBmp: TMufasaBitmap;
  6.   BadBoxes: TIntegerArray;
  7.   RockBoxes: TBoxArray;
  8.   TPA: TPointArray;
  9.   ATPA, RockLocations: T2DPointArray;
  10.   ITarget, KMTarget: Integer;
  11. begin
  12.  
  13.   Result := False;
  14.   CTS := GetColorToleranceSpeed;
  15.   SetColorToleranceSpeed(2);
  16.   ClientMufasaBmp := TMufasaBitmap.create();
  17.   ClientMufasaBmp.CopyClientToBitmap(GetTClient().IOManager, True, 0, 0, MSX1, MSY1, MSX2, MSY2); // := BitmapFromClient(MSX1, MSY1, MSX2, MSY2);
  18.  
  19.   KMTarget := GetKeyMouseTarget;
  20.   ITarget := GetImageTarget;
  21.   SetTargetBitmap(ClientMufasaBmp.Index);
  22.  
  23.   GetClientDimensions(W, H);
  24.  
  25.   x1 := 0; y1 := 0; x2 := W - 1; y2 := H - 1;
  26.  
  27.   ClientMufasaBmp.Name := 'Client Mufasa Bitmap';
  28.   ClientMufasaBmp.Posterize(ClientMufasaBmp, 2);
  29.   ClientMufasaBmp.Posterize(ClientMufasaBmp, 3);
  30.  
  31.   Len := Length(Location[0]);
  32.   SetLength(ATPA, Len);
  33.  
  34.   for I := 0 to (Len - 1) do
  35.   begin
  36.  
  37.     SetColorToleranceSpeed(Location[0][i][4]);
  38.     if (Location[0][i][4] = 2) then
  39.       SetColorspeed2Modifiers(Location[0][i][2], Location[0][i][3]);
  40.  
  41.     FindColorsTolerance(ATPA[i], Location[0][i][0], x1, y1, x2, y2, Location[0][i][1]);
  42.   end;
  43.  
  44.   MergeATPAWrap(ATPA, TPA);
  45.   SplitTPAWrap(TPA, 4, ATPA);
  46.  
  47.   Len := Length(ATPA);
  48.   SetLength(RockBoxes, Len);
  49.  
  50.   for L := 0 to (Len - 1) do
  51.     RockBoxes[L] := GetTPABounds(ATPA[L]);
  52.  
  53.   Len1 := Length(Rocks[RockType]);
  54.  
  55.   for L := 0 to (Len - 1) do
  56.   begin
  57.  
  58.     for I := 0 to (Len1 - 1) do
  59.     begin
  60.  
  61.       SetColorToleranceSpeed(Rocks[RockType][i][4]);
  62.       if (Rocks[RockType][i][4] = 2) then
  63.         SetColorspeed2Modifiers(Rocks[RockType][i][2], Rocks[RockType][i][3]);
  64.  
  65.       FindColorsTolerance(TPA, Rocks[RockType][i][0], RockBoxes[L].x1,
  66.        RockBoxes[L].y1, RockBoxes[L].x2, RockBoxes[L].y2, Rocks[RockType][i][1])
  67.  
  68.       if (Length(TPA) <= 6) then
  69.         CombineIntArrayWrap([L], BadBoxes, BadBoxes);
  70.     end;
  71.   end;
  72.  
  73.   SetLength(RockLocations, Len);
  74.   for L := 0 to (Len - 1) do
  75.   begin
  76.  
  77.     if InIntArray(BadBoxes, L) then
  78.     begin
  79.  
  80.       Inc(BadRocks);
  81.       Continue;
  82.     end;
  83.  
  84.     RockLocations[L] := TPAFromBox(RockBoxes[L]);
  85.     Len1 := Length(Location[1]);
  86.  
  87.     for I := 0 to (Len1 - 1) do
  88.     begin
  89.  
  90.       SetColorToleranceSpeed(Location[1][i][4]);
  91.       if (Location[1][i][4] = 2) then
  92.         SetColorspeed2Modifiers(Location[1][i][2], Location[1][i][3]);
  93.  
  94.       FindColorsTolerance(TPA, Location[1][i][0], RockBoxes[L].x1,
  95.        RockBoxes[L].y1, RockBoxes[L].x2, RockBoxes[L].y2, Location[1][i][1]);
  96.       ClearTPAFromTPAWrap(RockLocations[L], TPA, RockLocations[L]);
  97.     end;
  98.   end;
  99.   {
  100.   DisplayDebugImgWindow(W, H);
  101.   for I := 0 to High(RockLocations) do
  102.     for L := 0 to High(RockLocations[i]) do
  103.       FastSetPixel(ClientMufasaBmp.Index, RockLocations[i][l].x, RockLocations[i][l].y, clFuchsia);
  104.   DrawBitmapDebugImg(ClientMufasaBmp.Index);
  105.   }
  106.   //DebugATPA(RockLocations, '');
  107.  
  108.   FreeTarget(GetImageTarget);
  109.   SetKeyMouseTarget(KMTarget);
  110.   SetImageTarget(ITarget);
  111.  
  112.   SetColorToleranceSpeed(CTS);
  113.   ClientMufasaBmp.Free;
  114.  
  115.   SortATPASize(RockLocations, True);
  116.   SetLength(RockLocations, Len - BadRocks);
  117.  
  118.   OffsetATPA(RockLocations, IntToPoint(4, 4));
  119.  
  120.   SetLength(Return, Length(RockLocations));
  121.  
  122.   for I := 0 to High(RockLocations) do
  123.     Return[i] := RockLocations[i][Random(High(RockLocations[i]))];
  124.  
  125.   if PAINT_DEBUG then
  126.   begin
  127.     try
  128.     SMART_DrawTPAOutline(True, RockLocations[0], clWhite);
  129.  
  130.     for I := 1 to High(RockLocations) do
  131.       SMART_DrawTPAOutline(False, RockLocations[i], clWhite);
  132.     except
  133.     end;
  134.   end;
  135. end;
Advertisement
Add Comment
Please, Sign In to add comment