ZephyrsFury
2007-10-15 09:44:36
Just before I leave I wanna post a couple of functions that people might like/find a use for. They are all already in SRL but my functions modify certain elements or improve on their SRL counterparts.
I made this because SRL's GetDoorColor function wasn't working too well for me (probably works now but anyway…). I've posted this somewhere but I've made some adjustments to it so here it is again. Basically it searches for all the possible door colours. If it finds it on the minimap, it searches in a box 1 pixel surrounding the point to determine if its a door or a drop dot (drop dots never have the same colour next to each other). After going through all of the points it compares the door colours its found and returns the colour that is found the most. As you can see it is designed for Wizard's Tower hence the if (TempColour1 <> 238) stuff at the bottom but will work anywhere.
Now this function returns the coordinates of each door with a certain door colour on the minimap. Its basically the same as SRL's GetDoors function but I made this because I wanted to understand TPoints and stuff better. This one has pretty much no use and is probably inferior to GetDoors. It basically works in three stages. 1. It gets the coords of all points with the DoorColour (including drop dots for now). 2. It uses the same method as FindDoorColour to sort out all the actually door points 3. It get one coordinate from each door and returns them in a TPointArray.
My version of FFlag. I made this because I kept having trouble with FFlag calculating the distance from the top of the flag instead of the place where the character is actually walking to (FFlag finds the colour 255 and uses the coord of that point which is usually the top part of the flag). This function also uses a different method of detecting when the character is within the correct distance. FFlag uses HumanCircleFlag whereas I use Distance.
{------------------------------------------------------------------------------]
[ function FindDoorColour: Integer; ]
[ by: ZephyrsFury ]
[ Description: Finds the most occuring door colour on the minimap. ]
{------------------------------------------------------------------------------}
function FindDoorColour: Integer;
var
x1, y1, x2, y2, x3, y3, x4, y4 : Integer;
DoorBox1, DoorBox2 : TBox;
i, TempColour1, TempColour2 : Integer;
begin
for i := 220 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, x1 - 1, y1)) or
(FindColor(x2, y2, i, x1 - 1, y1 + 1, x1 + 1, y1 + 1)) or
(FindColor(x2, y2, i, x1 + 1, y1, x1 + 1, y1)) 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 - 6;
DoorBox1.y1 := y1 - 6;
DoorBox1.x2 := x1 + 6;
DoorBox1.y2 := y1 + 6;
DoorBox2.x1 := x3 - 6;
DoorBox2.y1 := y3 - 6;
DoorBox2.x2 := x3 + 6;
DoorBox2.y2 := y3 + 6;
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
else
if (TempColour1 <> 238) then
Result := TempColour1
else
if (TempColour2 <> 238) then
Result := TempColour2;
end;
I made this because SRL's GetDoorColor function wasn't working too well for me (probably works now but anyway…). I've posted this somewhere but I've made some adjustments to it so here it is again. Basically it searches for all the possible door colours. If it finds it on the minimap, it searches in a box 1 pixel surrounding the point to determine if its a door or a drop dot (drop dots never have the same colour next to each other). After going through all of the points it compares the door colours its found and returns the colour that is found the most. As you can see it is designed for Wizard's Tower hence the if (TempColour1 <> 238) stuff at the bottom but will work anywhere.
{------------------------------------------------------------------------------]
[ function GetDoorCoords(var Points: TPointArray): Boolean; ] ]
[ by: ZephyrsFury ]
[ Description: Saves the coordinates of all the doors into a TPointArray. ] ]
{------------------------------------------------------------------------------}
function GetDoorCoords(var Points: TPointArray): Boolean;
var
i, j, k, m, Tempx, Tempy: Integer;
DoorColours1, DoorColours2: TPointArray;
begin
if (DoorColour = 0) then
DoorColour := FindDoorColour;
if (DoorColour = 0) then Exit;
FindColorsTolerance(DoorColours1, DoorColour, MMX1, MMY1, MMX2, MMY2, 0);
WriteDebug('Got ' + IntToStr(GetArrayLength(DoorColours1)) + ' DoorColour pixels');
i := 0;
for j := 0 to GetArrayLength(DoorColours1) - 1 do
begin
if (FindColor(Tempx, Tempy, DoorColour, DoorColours1[j].x - 1, DoorColours1[j].y - 1,
DoorColours1[j].x + 1, DoorColours1[j].y - 1)) or
(FindColor(Tempx, Tempy, DoorColour, DoorColours1[j].x - 1, DoorColours1[j].y,
DoorColours1[j].x - 1, DoorColours1[j].y)) or
(FindColor(Tempx, Tempy, DoorColour, DoorColours1[j].x - 1, DoorColours1[j].y + 1,
DoorColours1[j].x + 1, DoorColours1[j].y + 1)) or
(FindColor(Tempx, Tempy, DoorColour, DoorColours1[j].x + 1, DoorColours1[j].y,
DoorColours1[j].x + 1, DoorColours1[j].y)) then
begin
SetArrayLength(DoorColours2, i + 1);
DoorColours2[i].x := DoorColours1[j].x;
DoorColours2[i].y := DoorColours1[j].y;
i := i + 1;
end;
end;
WriteDebug('Got ' + IntToStr(GetArrayLength(DoorColours2)) + ' Door points');
i := 0;
m := 0;
repeat
for k := m to GetArrayLength(DoorColours2) - 2 do
begin
if (Distance(DoorColours2[k].x, DoorColours2[k].y, DoorColours2[k + 1].x,
DoorColours2[k + 1].y) > 8) or (k + 1 = GetArrayLength(DoorColours2) - 1) then
begin
SetArrayLength(Points, i + 1);
Points[i] := DoorColours2[k];
i := i + 1;
Break;
end;
end;
m := k + 1;
until(m >= GetArrayLength(DoorColours2) - 1);
WriteDebug('Got ' + IntToStr(GetArrayLength(Points)) + ' Doors');
if (GetArrayLength(Points) > 0) then
Result := True;
end;
Now this function returns the coordinates of each door with a certain door colour on the minimap. Its basically the same as SRL's GetDoors function but I made this because I wanted to understand TPoints and stuff better. This one has pretty much no use and is probably inferior to GetDoors. It basically works in three stages. 1. It gets the coords of all points with the DoorColour (including drop dots for now). 2. It uses the same method as FindDoorColour to sort out all the actually door points 3. It get one coordinate from each door and returns them in a TPointArray.
{------------------------------------------------------------------------------]
[ procedure ZephFlag(Distance: Integer); ]
[ by: ZephyrsFury ]
[ Description: My version of FFlag. ]
{------------------------------------------------------------------------------}
procedure ZephFlag(Dist: Integer);
var
Dx, Dy, m, T: Integer;
begin
MarkTime(T);
repeat
if (FindColor(Dx, Dy, 255, MMX1, MMY1, MMX2, MMY2)) then
begin
m := GetColor(317, 172);
if (Distance(Dx, Dy + 14, MMCX, MMCY) >= Dist) then
begin
Wait(100);
if (TimeFromMark(T) > 15000) then
begin
if (GetColor(317, 172) = m) then
begin
if (FindColor(Dx, Dy, 255, MMX1, MMY1, MMX2, MMY2)) then
Mouse(Dx, Dy + 14, 1, 1, True)
else
Mouse(MMCX, MMCY, 0, 0, True);
Break;
end;
end else
if (TimeFromMark(T) > 30000) then Break;
end else Break;
end;
until(not(FindColor(Dx, Dy, 255, MMX1, MMY1, MMX2, MMY2)));
end;
My version of FFlag. I made this because I kept having trouble with FFlag calculating the distance from the top of the flag instead of the place where the character is actually walking to (FFlag finds the colour 255 and uses the coord of that point which is usually the top part of the flag). This function also uses a different method of detecting when the character is within the correct distance. FFlag uses HumanCircleFlag whereas I use Distance.