Special Ed
2009-05-01 02:22:27
Yes, I've made one before but I always get fascinated with these. Don't judge me. :p
I'm looking for any suggestions or critiques you can offer. The point of this is to find the "Exact" area of fishing spots, useful for checking if your character is fishing, where you're character is on the mainscreen (because they'd be next to the fishing spot you're fishing at right?) ect.
Thanks if you actually took a look at it.
NOTE: Just run the script if you want to see the fishing areas in relation to the RS client, or else remove the code in the mainloop after the comment if you want to see how the code works through it.
Thanks again. This may be used in the MSI Karaproject, we haven't decided yet. If you want to use it feel free, just give credit and let me know.
I'm looking for any suggestions or critiques you can offer. The point of this is to find the "Exact" area of fishing spots, useful for checking if your character is fishing, where you're character is on the mainscreen (because they'd be next to the fishing spot you're fishing at right?) ect.
Thanks if you actually took a look at it.
NOTE: Just run the script if you want to see the fishing areas in relation to the RS client, or else remove the code in the mainloop after the comment if you want to see how the code works through it.
program New;
{.include SRL/SRL.scar}
function TBoxToTPA(Box: TBox): TPointArray;
begin
SetArrayLength(result, 4);
result[0]:= IntToPoint(Box.x1, Box.y1);
result[1]:= IntToPoint(Box.x2, Box.y1);
result[2]:= IntToPoint(Box.x1, Box.y2);
result[3]:= IntToPoint(Box.x2, Box.y2);
end;
function PointInBoxArray(Point: TPoint; BoxArray: TBoxArray): Boolean;
var
ArrMax, i: Integer;
begin
ArrMax:= High(BoxArray);
for i:= 0 to ArrMax do
if(PointInBox(Point, BoxArray[i]))then
begin
result:= True;
Exit;
end else result:= False;
end;
procedure DrawBox(BMP, Color: Integer; Box: TBox);
var
i: Byte;
WH: TPoint;
begin
WH.x:= Box.x2 - Box.x1;
WH.y:= Box.y2 - Box.y1;
for i:= 0 to WH.x do
begin
FastSetPixel(BMP, Box.x1 + i, Box.y1, Color);
FastSetPixel(BMP, Box.x1 + i, Box.y2, Color);
end;
for i:= 0 to WH.y do
begin
FastSetPixel(BMP, Box.x1, Box.y1 + i, Color);
FastSetPixel(BMP, Box.x2, Box.y1 + i, Color);
end;
end;
function FindFishingAreas(Passes: Byte; PassDelay: Integer): TBoxArray;
var
fTPA, fTPA_Extra, BoxArrTotal, tempTPA, BoxArr: TPointArray;
BoxArr_TPA: Array [0..3] of TPointArray;
fTPA_ArrMax, BMP, i: Integer;
BMP_Box: TBox;
BMP_Size: TPoint;
tempArr: TBoxArray;
a, f, c, GapSize: Byte;
begin
GapSize:= 10;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.10, 0.24);
FindColorsTolerance(fTPA, 11972264, MSx1, MSy1, MSx2, MSy2, 13);
while(i < Passes)do
begin
Wait(PassDelay);
FindColorsTolerance(fTPA_Extra, 11972264, MSx1, MSy1, MSx2, MSy2, 13);
fTPA:= CombineTPA(fTPA, fTPA_Extra);
Inc(i);
end;
{
for i:= 1 to Passes do
begin
Wait(PassDelay);
FindColorsTolerance(fTPA_Extra, 11972264, MSx1, MSy1, MSx2, MSy2, 13);
fTPA:= CombineTPA(fTPA, fTPA_Extra);
end;
}
fTPA_ArrMax:= High(fTPA);
Writeln('fTPA_ArrMax: ' + inttostr(fTPA_ArrMax));
BMP_Box:= GetTPABounds(fTPA);
Writeln('BMP_Box: (' + inttostr(BMP_Box.x1) + ', ' + inttostr(BMP_Box.y1) + ', ' + inttostr(BMP_Box.x2) + ', ' + inttostr(BMP_Box.y2) + ')');
BMP_Size.x:= BMP_Box.x2 - BMP_Box.x1;
Writeln('BMP_Size.x: ' + inttostr(BMP_Size.x));
BMP_Size.y:= BMP_Box.y2 - BMP_Box.y1;
Writeln('BMP_Size.y: ' + inttostr(BMP_Size.y));
BMP:= BitmapFromString(BMP_Size.x, BMP_Size.y, '');
for i:= 0 to fTPA_ArrMax do
fTPA[i]:= IntToPoint(fTPA[i].x - BMP_Box.x1, fTPA[i].y - BMP_Box.y1);
for i:= 0 to fTPA_ArrMax do
begin
Writeln('Pixel[' + inttostr(i) + ']: (' + inttostr(fTPA[i].x) + ', ' + inttostr(fTPA[i].y) + ')');
FastSetPixel(BMP, fTPA[i].x, fTPA[i].y, 255);
end;
DisplayDebugImgWindow(BMP_Size.x, BMP_Size.y);
CopyCanvas(GetBitmapCanvas(BMP), GetDebugCanvas, 0, 0, BMP_Size.x, BMP_Size.y, 0, 0, BMP_Size.x, BMP_Size.y);
RAaSTPA(fTPA, GapSize);
fTPA_ArrMax:= High(fTPA);
Writeln('fTPA_ArrMax (Check 2): ' + inttostr(fTPA_ArrMax));
SetTargetDc(GetBitmapDC(BMP));
Writeln('');
Writeln('** Starting Sort Loop **');
Writeln('');
for i:= 0 to fTPA_ArrMax do
begin
if not(PointInBoxArray(fTPA[i], tempArr))then
begin
Writeln('Point[' + inttostr(i) + '] is Valid: (' + inttostr(fTPA[i].x) + ', ' + inttostr(fTPA[i].y) + ')');
SetArrayLength(tempArr, f + 1);
Writeln('tempArr Length: ' + inttostr(GetArrayLength(tempArr)));
tempArr[f]:= IntToBox(fTPA[i].x - GapSize, fTPA[i].y - GapSize, fTPA[i].x + GapSize, fTPA[i].y + GapSize);
Writeln('tempArr[' + inttostr(f) + ']: (' + inttostr(tempArr[f].x1) + ', ' + inttostr(tempArr[f].y1) + ', ' + inttostr(tempArr[f].x2) + ', ' + inttostr(tempArr[f].y2) + ')');
repeat
FindColorsTolerance(tempTPA, 255, tempArr[f].x1, tempArr[f].y1, tempArr[f].x2, tempArr[f].y2, 0);
BoxArr:= TBoxtoTPA(GetTPABounds(tempTPA));
for a:= 0 to 3 do
begin
case a of
0 : FindColorsTolerance(BoxArr_TPA[a], 255, BoxArr[a].x - GapSize, BoxArr[a].y - GapSize, BoxArr[a].x + GapSize, BoxArr[a].y , 0);
1 : FindColorsTolerance(BoxArr_TPA[a], 255, BoxArr[a].x , BoxArr[a].y - GapSize, BoxArr[a].x + GapSize, BoxArr[a].y + GapSize, 0);
2 : FindColorsTolerance(BoxArr_TPA[a], 255, BoxArr[a].x - GapSize, BoxArr[a].y - GapSize, BoxArr[a].x , BoxArr[a].y + GapSize, 0);
3 : FindColorsTolerance(BoxArr_TPA[a], 255, BoxArr[a].x - GapSize, BoxArr[a].y , BoxArr[a].x + GapSize, BoxArr[a].y + GapSize, 0);
end;
BoxArrTotal:= CombineTPA(BoxArrTotal, BoxArr_TPA[a]);
Writeln('BoxArrTotal Length: ' + inttostr(GetArrayLength(BoxArrTotal)));
end;
tempArr[f]:= GetTPABounds(BoxArrTotal);
DrawBox(BMP, 16777215, tempArr[f]);
DisplayDebugImgWindow(BMP_Size.x, BMP_Size.y);
CopyCanvas(GetBitmapCanvas(BMP), GetDebugCanvas, 0, 0, BMP_Size.x, BMP_Size.y, 0, 0, BMP_Size.x, BMP_Size.y);
Inc(c);
Writeln('c: ' + inttostr(c));
until(c = 2);
SetArrayLength(BoxArrTotal, 0);
c:= 0;
Inc(f);
Writeln('f: ' + inttostr(f));
end;
end;
ResetDC;
SetArrayLength(result, f);
for i:= 0 to High(result) do
DrawBox(BMP, 8053399, tempArr[i]);
DisplayDebugImgWindow(BMP_Size.x, BMP_Size.y);
CopyCanvas(GetBitmapCanvas(BMP), GetDebugCanvas, 0, 0, BMP_Size.x, BMP_Size.y, 0, 0, BMP_Size.x, BMP_Size.y);
Writeln('result Length: ' + inttostr(GetArrayLength(result)));
if(GetArrayLength(Result) > 0)then
for i:= 0 to f - 1 do
result[i]:= IntToBox(tempArr[i].x1 + BMP_Box.x1, tempArr[i].y1 + BMP_Box.y1, tempArr[i].x2 + BMP_Box.x1, tempArr[i].y2 + BMP_Box.y1);
end;
var
fSpot: TBoxArray;
Client, w, h: Integer;
y: Byte;
begin
SetupSRL;
fSpot:= FindFishingAreas(4, 200);
//Comment out everything (except "end.") below here to see what the code "sees".
GetClientDimensions(w, h);
Client:= BitmapFromString(w, h, '');
CopyClientToBitmap(Client, 0, 0, w, h);
for y:= 0 to High(fSpot) do
begin
DrawBox(Client, 255, fSpot[y]);
DisplayDebugImgWindow(w, h);
CopyCanvas(GetBitmapCanvas(Client), GetDebugCanvas, 0, 0, w, h, 0, 0, w, h);
end;
end.
Thanks again. This may be used in the MSI Karaproject, we haven't decided yet. If you want to use it feel free, just give credit and let me know.