SRL Archive - Research & Development Lounge

finddoor


sherlockmeister

2007-08-28 18:42:02

heres a simple find door procedure, tell me if it works.

finddoor
function FindDoor(var X, Y: Integer): Boolean;
var
X1, Y1, X2, Y2, I, Dots, R, G, B: Integer;
SkipCoords: TPointArray;
TempBMP, TheColor: Integer;
begin
repeat
TempBMP := BitmapFromString(5, 5, '');
if FindColorSkipCoordsTolerance(X1, Y1, 255, 569, 8, 715, 160, 25, SkipCoords) then
begin
CopyClientToBitmap(TempBMP, X1 - 2, Y1 - 2, X1 + 2, Y1 + 2);
TheColor := FastGetPixel(TempBMP, 2, 2);
ColorToRGB(TheColor, R, G, B);
if (G > 1) or (B > 1) then
begin
SetArrayLength(SkipCoords, I + 1);
SkipCoords[I].X := X1;
SkipCoords[I].Y := Y1;
I := I + 1;
end else
begin
for X2 := 0 to 4 do
begin
for Y2 := 0 to 4 do
begin
if TheColor = FastGetPixel(TempBMP, X2, Y2) then
begin
Dots := Dots + 1;
end;
end;
end;
end;
if Dots > 2 then
begin
X := X1;
Y := Y1;
Result := true;
FreeBitmap(TempBMP);
Exit;
end else
begin
SetArrayLength(SkipCoords, I + 1);
SkipCoords[I].X := X1;
SkipCoords[I].Y := Y1;
I := I + 1;
Dots := 0;
end;
end else
begin
Break;
end;
until (false);
FreeBitmap(TempBMP);
end;

finddoormulti
function FindDoorMulti(var Coords: TPointArray; NumberOfDoors: Integer): Boolean;
var
X1, Y1, X2, Y2, I, Dots, R, G, B, N: Integer;
SkipCoords: TBoxArray;
TempBMP, TheColor: Integer;
begin
SetArrayLength(Coords, NumberOfDoors + 1);
TempBMP := BitmapFromString(5, 5, '');
repeat
if FindColorSkipBoxArrayTolerance(X1, Y1, 255, 569, 8, 715, 160, 25, SkipCoords) then
begin
CopyClientToBitmap(TempBMP, X1 - 2, Y1 - 2, X1 + 2, Y1 + 2);
TheColor := FastGetPixel(TempBMP, 2, 2);
ColorToRGB(TheColor, R, G, B);
if (G > 1) or (B > 1) then
begin
SetArrayLength(SkipCoords, I + 1);
SkipCoords[I].X1 := X1;
SkipCoords[I].Y1 := Y1;
SkipCoords[I].X2 := X1;
SkipCoords[I].Y2 := Y1;
I := I + 1;
end else
begin
for X2 := 0 to 4 do
begin
for Y2 := 0 to 4 do
begin
if TheColor = FastGetPixel(TempBMP, X2, Y2) then
begin
Dots := Dots + 1;
end;
end;
end;
end;
if Dots > 2 then
begin
Coords[N].X := X1;
Coords[N].Y := Y1;
N := N + 1;
SetArrayLength(SkipCoords, I + 1);
SkipCoords[I].X1 := X1 - 4;
SkipCoords[I].Y1 := Y1 - 4;
SkipCoords[I].X2 := X1 + 4;
SkipCoords[I].Y2 := Y1 + 4;
I := I + 1;
if N >= NumberOfDoors then
begin
Result := true;
FreeBitmap(TempBMP);
Exit;
end;
end else
begin
SetArrayLength(SkipCoords, I + 1);
SkipCoords[I].X1 := X1;
SkipCoords[I].Y1 := Y1;
SkipCoords[I].X2 := X1;
SkipCoords[I].Y2 := Y1;
I := I + 1;
Dots := 0;
end;
end else
begin
Break;
end;
until (false);
FreeBitmap(TempBMP);
end;

dvdcrayola

2007-08-28 23:49:51

wow, looks very nice.. only one thing…

never do until(false) just incase the script is in the wrong place.. do like until tries=10 or (not (loggedin;))

ShowerThoughts

2007-08-29 05:52:15

you gonnsa use this dvd?

dvdcrayola

2007-08-29 13:13:21

From: hermpie
you gonnsa use this dvd?


um, no… im making my own.. this one will work well if 1 door is on the minimap… but im dealing with 2

sherlockmeister

2007-08-29 20:42:01

From: dvdcrayola
wow, looks very nice.. only one thing…

never do until(false) just incase the script is in the wrong place.. do like until tries=10 or (not (loggedin;))


notice the

end else
begin
Break;
end;

in the last couple lines, the until (false) is there for reason. scar searches for the door color in the entire mini map skipping the coordinates which contain the door color but do not have enough of the same color in the area to be a door. when there is no more of the door color on the mini map (with the coordinates skipped appropriately) the "end else" is executed and it breaks out of the loop with the result of the function being false.

ShowerThoughts

2007-08-30 04:29:57

From: dvdcrayola
um, no… im making my own.. this one will work well if 1 door is on the minimap… but im dealing with 2


you dealing with 4;)

sherlockmeister

2007-08-30 18:04:24

i added multi door finding in a new function called finddoormulti, which was pretty simple, now maybe someone will test it?

WT-Fakawi

2007-08-30 19:10:27

Look in SRL/Core/DoorProfiles. Its all there. With on top
function GetDoors: array of DoorProfile;
It returns an array of all coords of doors in the minimap.

Wizzup?

2007-08-31 03:14:56

From: WT-Fakawi
Look in SRL/Core/DoorProfiles. Its all there. With on top
function GetDoors: array of DoorProfile;
It returns an array of all coords of doors in the minimap.


I think this is for mainscreen?

nielsie95

2007-08-31 04:45:32

Color 255 in an area of 569, 8, 715, 160.. I think this is the MM.

Wizzup?

2007-08-31 04:56:58

From: nielsie95
Color 255 in an area of 569, 8, 715, 160.. I think this is the MM.


Ah, alright, the Multi kinda cofused me.

sherlockmeister

2007-08-31 17:53:21

lol i thought doorprofile.scar was for main screen also, well looks like my efforts have been in vain

Boreas

2007-08-31 21:00:18

At least you learned something :)

rotflmfwao

2007-08-31 21:24:22

And thats all that matters.