ZephyrsFury
07-25-2007, 05:25 AM
This function is designed to return the red colour of the doors on the minimap. It searches for a colour between 200 and 254 (the typical colours of the doors) then uses the fact that drop dots don't have the same colour in more than one pixel. It searches the area 1 pixel around the colour found to make sure its a door colour. Then it continues searching, storing any other door colours it comes across. After finishing with colour 254, it will check to see if the door colours its found occur in any other places. The colour that is found the most will be returned.
I scripted this function because I've found SRL's GetDoorColor to be unreliable - returning the colours of drop dots more than the actual doors. This function is simple yet reliable. I use this in my Rune Mysteries Runner and it works very well even in the presence of many door colours and drop dots (Wizard's Tower for example).
function FindDoorColour: integer;
var
x1, y1, x2, y2, x3, y3, x4, y4 : integer;
DoorBox1, DoorBox2 : TBox;
i, TempColour1, TempColour2 : integer;
begin
for i := 200 to 254 do
begin
if (FindColor(x1, y1, i, MMX1, MMY1, MMX2, MMY2)) then
begin
if (FindColor(x2, y2, i, x1 - 1, y1 - 1, x1 + 1, y1 - 1)) or
(FindColor(x2, y2, i, x1 - 1, y1 - 1, x1 - 1, y1 + 1)) or
(FindColor(x2, y2, i, x1 - 1, y1 + 1, x1 + 1, y1 + 1)) or
(FindColor(x2, y2, i, x1 + 1, y1 - 1, x1 + 1, y1 + 1)) then
begin
TempColour1 := i;
Break;
end;
end;
end;
if (TempColour1 = 0) then Exit;
for i := TempColour1 + 1 to 254 do
begin
if (FindColor(x3, y3, i, MMX1, MMY1, MMX2, MMY2)) then
begin
if (FindColor(x2, y2, i, x3 - 1, y3 - 1, x3 + 1, y3 - 1)) or
(FindColor(x2, y2, i, x3 - 1, y3 - 1, x3 - 1, y3 + 1)) or
(FindColor(x2, y2, i, x3 - 1, y3 + 1, x3 + 1, y3 + 1)) or
(FindColor(x2, y2, i, x3 + 1, y3 - 1, x3 + 1, y3 + 1)) then
begin
TempColour2 := i;
Break;
end;
end;
end;
DoorBox1.x1 := x1 - 5;
DoorBox1.y1 := y1 - 5;
DoorBox1.x2 := x1 + 5;
DoorBox1.y2 := y1 + 5;
DoorBox2.x1 := x3 - 5;
DoorBox2.y1 := y3 - 5;
DoorBox2.x2 := x3 + 5;
DoorBox2.y2 := y3 + 5;
if (TempColour2 = 0) then
Result := TempColour1
else
if (FindColorSkipBox(x4, y4, TempColour1, MMX1, MMY1, MMX2, MMY2, DoorBox1)) then
Result := TempColour1
else
if (FindColorSkipBox(x4, y4, TempColour2, MMX1, MMY1, MMX2, MMY2, DoorBox2)) then
Result := TempColour2
end;
I'll also attach it as a SCAR file.
If you use this function in any of your scripts, please give me credit. I only released it because I'm nice. :p
Zeph
I scripted this function because I've found SRL's GetDoorColor to be unreliable - returning the colours of drop dots more than the actual doors. This function is simple yet reliable. I use this in my Rune Mysteries Runner and it works very well even in the presence of many door colours and drop dots (Wizard's Tower for example).
function FindDoorColour: integer;
var
x1, y1, x2, y2, x3, y3, x4, y4 : integer;
DoorBox1, DoorBox2 : TBox;
i, TempColour1, TempColour2 : integer;
begin
for i := 200 to 254 do
begin
if (FindColor(x1, y1, i, MMX1, MMY1, MMX2, MMY2)) then
begin
if (FindColor(x2, y2, i, x1 - 1, y1 - 1, x1 + 1, y1 - 1)) or
(FindColor(x2, y2, i, x1 - 1, y1 - 1, x1 - 1, y1 + 1)) or
(FindColor(x2, y2, i, x1 - 1, y1 + 1, x1 + 1, y1 + 1)) or
(FindColor(x2, y2, i, x1 + 1, y1 - 1, x1 + 1, y1 + 1)) then
begin
TempColour1 := i;
Break;
end;
end;
end;
if (TempColour1 = 0) then Exit;
for i := TempColour1 + 1 to 254 do
begin
if (FindColor(x3, y3, i, MMX1, MMY1, MMX2, MMY2)) then
begin
if (FindColor(x2, y2, i, x3 - 1, y3 - 1, x3 + 1, y3 - 1)) or
(FindColor(x2, y2, i, x3 - 1, y3 - 1, x3 - 1, y3 + 1)) or
(FindColor(x2, y2, i, x3 - 1, y3 + 1, x3 + 1, y3 + 1)) or
(FindColor(x2, y2, i, x3 + 1, y3 - 1, x3 + 1, y3 + 1)) then
begin
TempColour2 := i;
Break;
end;
end;
end;
DoorBox1.x1 := x1 - 5;
DoorBox1.y1 := y1 - 5;
DoorBox1.x2 := x1 + 5;
DoorBox1.y2 := y1 + 5;
DoorBox2.x1 := x3 - 5;
DoorBox2.y1 := y3 - 5;
DoorBox2.x2 := x3 + 5;
DoorBox2.y2 := y3 + 5;
if (TempColour2 = 0) then
Result := TempColour1
else
if (FindColorSkipBox(x4, y4, TempColour1, MMX1, MMY1, MMX2, MMY2, DoorBox1)) then
Result := TempColour1
else
if (FindColorSkipBox(x4, y4, TempColour2, MMX1, MMY1, MMX2, MMY2, DoorBox2)) then
Result := TempColour2
end;
I'll also attach it as a SCAR file.
If you use this function in any of your scripts, please give me credit. I only released it because I'm nice. :p
Zeph