SRL Archive - SRL Archives

DrawBMPFound


Sumilion

2006-08-23 17:00:04

Heya, this function (was helped by c0de) searches for a bitmap in a specified location and then draws it if wanted. It also writes down the coords, but it doesnt return them. It can be used to check the number of a specified item in your inventory, but i thought of it as a debug tool. Let's say you use findbitmap and mouse(), but the mouse clicks in a place you don't want it to go, you can check with this where it found all of the bitmaps. And PER HAPS someone can make it into a roadwalker, cause it can draw the entire road in the debug window. It's not needed, but possible. Don't forget that if you add a bitmap in your program with this script, that you name it BitmapFromString2, as i needed the width and height and i didnt knew what other way to get it… Here it is :
Program DrawMyBMPFound;
Var
BMPW, BMPH : integer;
Const
Tol = 10;

Function DrawBMPFound(bitmap : integer; BMPX1, BMPY1, BMPX2, BMPY2 : integer; tol : integer; DrawBMP : boolean) : integer;
var CX1, CY1, CX2, CY2, TX, TY, DrawBMPCount, Buffer, I, Repeater : integer;
AX1 : array[1..99999] of integer;
AY1 : array[1..99999] of integer;
AX2 : array[1..99999] of integer;
AY2 : array[1..99999] of integer;

Begin
If(BMPW > (BMPX2-BMPX1)) or (BMPH > (BMPY2-BMPY1))Then
Begin
Writeln('The BMP is bigger than the field criteria...');
Exit;
End;
Result := 0;
CY1 := BMPY1;
CY2 := BMPY1 + BMPH;
Repeat;
CX1 := BMPX1;
CX2 := BMPX1 + BMPW;
Repeat;
If(FindBitmapToleranceIn(bitmap, TX, TY, CX1, CY1, CX2, CY2, tol))Then
Begin
Result := Result + 1;
AX1[Result] := TX-BMPX1;
AY1[Result] := TY-BMPY1;
AX2[Result] := TX;
AY2[Result] := TY;
End;
CX1 := CX1 + 1;
CX2 := CX2 + 1;
Until(CX2 >= BMPX2)
CY1 := CY1 + 1;
CY2 := CY2 + 1;
Until(CY2 >= BMPY2);
If (Result >= 1) and DrawBMP Then
Begin
DisplayDebugImgWindow(100, 100);
Buffer := BitmapFromString(100, 100, '');
FastDrawClear(Buffer, ClBtnFace);
For I := 0 To 3000 Do
Begin
FastDrawTransparent(50, 50, bitmap, Buffer);
SafeDrawBitmap(Buffer, GetDebugCanvas, 0, 0);
End;
//This little piece above me is thanx to inferno.
DrawBMPCount := 0;
HideDebugImgWindow;
DisplayDebugImgWindow((BMPX2-BMPX1), (BMPY2-BMPY1));
Repeat
DrawBMPCount := DrawBMPCount + 1;
SafeDrawBitmap(bitmap, GetDebugCanvas, AX1[DrawBMPCount], AY1[DrawBMPCount]);
Until(DrawBMPCount >= Result);
End;
Writeln('------------------------>');
Writeln('Found: '+inttostr(Result));
Writeln('-------------------------');
If (Result >= 1) then
Begin
Repeat
Repeater := Repeater + 1;
Writeln(inttostr(Repeater) + '. (' + inttostr(AX2[Repeater]) + ', ' + inttostr(AY2[Repeater]) + ')');
Until(Repeater >= Result);
End;
Writeln('<------------------------');
End;

Function BitmapFromString2(Width, Height : integer; str : string) : integer;//Ok ok ok ok, this one is made by c0de ;)
begin
BMPW := Width;
BMPH := Height;
Result := BitmapFromString(Width, Height, str);
end;

Begin
End.

WhiteShadow

2006-08-23 17:44:20

Wow, intense stuff. I need to learn some of those commands. xP

I might find some use for it later.. Lawl.

I think GetDebugRoadColor(I forgot what it was called) it's compliant with RRW, basically works like this.

Sumilion

2006-08-23 18:27:03

hmm… im gonna give it a look then :D

Bebe

2006-08-24 17:26:59

You can make:
 AX1 : array[1..99999] of integer;
AY1 : array[1..99999] of integer;
AX2 : array[1..99999] of integer;
AY2 : array[1..99999] of integer;

Into:

AX1,AY1, AX2, AY2 : array[1..99999] of integer;

Looks good.

Sumilion

2006-08-24 18:34:25

ahh… looks better indeed, doesn't matter for the rest tho ;), but if anyone has a good idea of when this function can be usfull, please let me know :cool: