Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function FindRocks(RockType: Integer; var Return: TPointArray): Boolean;
- var
- x1, y1, x2, y2, W, H: Integer;
- BadRocks, CTS, ClientBitmap, I, L, Len, Len1: Integer;
- ClientMufasaBmp: TMufasaBitmap;
- BadBoxes: TIntegerArray;
- RockBoxes: TBoxArray;
- TPA: TPointArray;
- ATPA, RockLocations: T2DPointArray;
- ITarget, KMTarget: Integer;
- begin
- Result := False;
- CTS := GetColorToleranceSpeed;
- SetColorToleranceSpeed(2);
- ClientMufasaBmp := TMufasaBitmap.create();
- ClientMufasaBmp.CopyClientToBitmap(GetTClient().IOManager, True, 0, 0, MSX1, MSY1, MSX2, MSY2); // := BitmapFromClient(MSX1, MSY1, MSX2, MSY2);
- KMTarget := GetKeyMouseTarget;
- ITarget := GetImageTarget;
- SetTargetBitmap(ClientMufasaBmp.Index);
- GetClientDimensions(W, H);
- x1 := 0; y1 := 0; x2 := W - 1; y2 := H - 1;
- ClientMufasaBmp.Name := 'Client Mufasa Bitmap';
- ClientMufasaBmp.Posterize(ClientMufasaBmp, 2);
- ClientMufasaBmp.Posterize(ClientMufasaBmp, 3);
- Len := Length(Location[0]);
- SetLength(ATPA, Len);
- for I := 0 to (Len - 1) do
- begin
- SetColorToleranceSpeed(Location[0][i][4]);
- if (Location[0][i][4] = 2) then
- SetColorspeed2Modifiers(Location[0][i][2], Location[0][i][3]);
- FindColorsTolerance(ATPA[i], Location[0][i][0], x1, y1, x2, y2, Location[0][i][1]);
- end;
- MergeATPAWrap(ATPA, TPA);
- SplitTPAWrap(TPA, 4, ATPA);
- Len := Length(ATPA);
- SetLength(RockBoxes, Len);
- for L := 0 to (Len - 1) do
- RockBoxes[L] := GetTPABounds(ATPA[L]);
- Len1 := Length(Rocks[RockType]);
- for L := 0 to (Len - 1) do
- begin
- for I := 0 to (Len1 - 1) do
- begin
- SetColorToleranceSpeed(Rocks[RockType][i][4]);
- if (Rocks[RockType][i][4] = 2) then
- SetColorspeed2Modifiers(Rocks[RockType][i][2], Rocks[RockType][i][3]);
- FindColorsTolerance(TPA, Rocks[RockType][i][0], RockBoxes[L].x1,
- RockBoxes[L].y1, RockBoxes[L].x2, RockBoxes[L].y2, Rocks[RockType][i][1])
- if (Length(TPA) <= 6) then
- CombineIntArrayWrap([L], BadBoxes, BadBoxes);
- end;
- end;
- SetLength(RockLocations, Len);
- for L := 0 to (Len - 1) do
- begin
- if InIntArray(BadBoxes, L) then
- begin
- Inc(BadRocks);
- Continue;
- end;
- RockLocations[L] := TPAFromBox(RockBoxes[L]);
- Len1 := Length(Location[1]);
- for I := 0 to (Len1 - 1) do
- begin
- SetColorToleranceSpeed(Location[1][i][4]);
- if (Location[1][i][4] = 2) then
- SetColorspeed2Modifiers(Location[1][i][2], Location[1][i][3]);
- FindColorsTolerance(TPA, Location[1][i][0], RockBoxes[L].x1,
- RockBoxes[L].y1, RockBoxes[L].x2, RockBoxes[L].y2, Location[1][i][1]);
- ClearTPAFromTPAWrap(RockLocations[L], TPA, RockLocations[L]);
- end;
- end;
- {
- DisplayDebugImgWindow(W, H);
- for I := 0 to High(RockLocations) do
- for L := 0 to High(RockLocations[i]) do
- FastSetPixel(ClientMufasaBmp.Index, RockLocations[i][l].x, RockLocations[i][l].y, clFuchsia);
- DrawBitmapDebugImg(ClientMufasaBmp.Index);
- }
- //DebugATPA(RockLocations, '');
- FreeTarget(GetImageTarget);
- SetKeyMouseTarget(KMTarget);
- SetImageTarget(ITarget);
- SetColorToleranceSpeed(CTS);
- ClientMufasaBmp.Free;
- SortATPASize(RockLocations, True);
- SetLength(RockLocations, Len - BadRocks);
- OffsetATPA(RockLocations, IntToPoint(4, 4));
- SetLength(Return, Length(RockLocations));
- for I := 0 to High(RockLocations) do
- Return[i] := RockLocations[i][Random(High(RockLocations[i]))];
- if PAINT_DEBUG then
- begin
- try
- SMART_DrawTPAOutline(True, RockLocations[0], clWhite);
- for I := 1 to High(RockLocations) do
- SMART_DrawTPAOutline(False, RockLocations[i], clWhite);
- except
- end;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment