kanah
2011-10-29 23:20:29
So I was looking for a nice procedures to discover doors and stumbled upon the old outdated methods in "doorprofiles.scar". I tried using GetDoorPoints which failed to discern drop dots from the door itself.
Below are some procedures I wrote that accurately find doors and item drops. The method of finding them is based off the fact that item drops usually have a higher luminance then the similiar door red.
Below are some procedures I wrote that accurately find doors and item drops. The method of finding them is based off the fact that item drops usually have a higher luminance then the similiar door red.
Procedure IdentifyDoors(var Doors: TpointArray);
//This function locates possible doors on the minimap
var
RedColor: integer;
TempDoors: TPointArray;
Len,i,q: integer;
H,S,L: Extended;
MaxLum,MinLum: Extended;
begin
RedColor := 327916;
//Find all the red on the mini map
FindColorsTolerance(Doors,RedColor,MMX1,MMY1,MMX2,MMY2,35);
//Group those points to basic door size
RAaSTPA(Doors,8);
//Now we are going to analyze the points
Len := length(Doors);
SetLength(TempDoors,Len);
MinLum := 100;
MaxLum := 0;
//The general HSL profile is made in this loop, max and min
for i:= 0 to(Len-1) do
begin
ColorToHSL(GetColor(Doors[i].x,Doors[i].y),h,s,l);
//writeln('H ='+tostr(h)+' S ='+tostr(s)+' L ='+tostr(l));
if (l<MinLum) then
MinLum := l;
if (l>MaxLum) then
MaxLum := l;
end;
//With the knowledge of the HSL of the points we can now determine which are doors
for i:=0 to(Len-1) do
begin
ColorToHSL(GetColor(Doors[i].x,Doors[i].y),h,s,l);
//writeln('H ='+tostr(h)+' S ='+tostr(s)+' L ='+tostr(l));
//Doors always have a lower luminance then item dots
if (l>=MinLum)and(l<(MinLum+1)) then
begin
TempDoors[q] := Doors[i];
Inc(q);
end;
end;
//writeln('there are '+tostr(q)+' points that meet the criteria');
Doors := CopyTPA(TempDoors);
SetLength(Doors,q);
end;
Procedure FindItemDrops(var points: TPointArray);
//This function locates possible drops on the minimap
var
RedColor: integer;
TempPoints: TPointArray;
Len,i,q: integer;
H,S,L: Extended;
MaxLum,MinLum: Extended;
begin
RedColor := 327916;
//Find all the general red on minimap
FindColorsTolerance(points,RedColor,MMX1,MMY1,MMX2,MMY2,35);
//Group them small enough to detect touching dots
RAaSTPA(points,4);
Len := length(points);
SetLength(TempPoints,Len);
MinLum := 100;
MaxLum := 0;
//Grab the HSL profile
for i:= 0 to(Len-1) do
begin
ColorToHSL(GetColor(Points[i].x,Points[i].y),h,s,l);
//writeln('H ='+tostr(h)+' S ='+tostr(s)+' L ='+tostr(l));
if (l<MinLum) then
MinLum := l;
if (l>MaxLum) then
MaxLum := l;
end;
//Item dots always have a higher luminance then door dots
for i:=0 to(Len-1) do
begin
ColorToHSL(GetColor(Points[i].x,Points[i].y),h,s,l);
//writeln('H ='+tostr(h)+' S ='+tostr(s)+' L ='+tostr(l));
if (l>(MaxLum-1))and(l<=MaxLum) then
begin
TempPoints[q] := points[i];
Inc(q);
end;
end;
//writeln('there are '+tostr(q)+' points that meet the criteria');
Points := CopyTPA(TempPoints);
SetLength(Points,q);
end;