marpis
2009-05-05 19:29:28
i have made this function that requires autocoloring doors and white walls in MM. I hope someone who can do this will help me! They'd be very useful anyways
It tells if the point P in MM is behind either a door or a white wall.
'door' or 'wall' is saved to variable: obstacle
Its working very well when i pick the colors myself.
You must include Doorprofiles too
EDIT: Fucks sake, i never get this to work 100%
It tells if the point P in MM is behind either a door or a white wall.
'door' or 'wall' is saved to variable: obstacle
Its working very well when i pick the colors myself.
You must include Doorprofiles too
{.include SRL/SRL.scar}
{.include SRL/SRL/misc/Doorprofiles.scar}
// FindWallColor by XcandamanX + ACA2
Function FindWallColor: Integer;
var
arP: TPointArray;
arC: TIntegerArray;
tmpCTS, i, arL: Integer;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(15.88, 8.03);
if not (FindColorsTolerance(arP, 15856104, MMX1, MMY1, MMX2, MMY2, 5)) then
begin
Writeln('Failed to find the Wallcolor');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;
arC := GetColors(arP);
ClearSameIntegers(arC);
arL := High(arC);
for i := 0 to arL do
begin
Result := arC[i];
Writeln('WallColor = ' + IntToStr(arC[i]));
Break;
end;
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
if (i = arL + 1) then
Writeln('AutoColor failed in finding the color.');
end;
// PointBehindWall by marpis
function PointBehindWall(P: TPoint; var fx, fy: integer; var obstacle: string): boolean;
var
wallc, doorc, h, x, y, i, hi: integer;
Walls, Doors: TPointArray;
k: extended;
begin
if (not InRange(P.x, MMX1, MMX2)) or
(not InRange(P.y, MMY1, MMY2)) then
begin
writeln('[ERROR] PointBehindWall: ('+IntToStr(P.x)+', '+IntToStr(P.y)+') is not in MM!');
exit;
end;
// colors
wallc:= FindWallColor; //PICK YOUR COLOR HERE!
doorc:= 225;
ColorToleranceSpeed(3);
FindColorsSpiralTolerance(MMCX, MMCY, Walls, wallc, MMX1, MMY1, MMX2, MMY2, 10);
FindColorsSpiralTolerance(MMCX, MMCY, Doors, doorc, MMX1, MMY1, MMX2, MMY2, 6);
if (High(Walls) < 1) or (High(Doors) < 1) then exit;
// filter dropdots
Doors:= FilterDropDots(Doors);
//filter self
for i:= 0 to high(walls) do
if distance(walls[i].x, walls[i].y, MMCX, MMCY) < 5 then
begin
swap(walls[i], walls[high(walls)]);
setlength(walls, high(walls));
end;
// calculations
k:= (P.y - (MMCY)) / (P.x - MMCX);
h:= P.x - MMCX;
// find obstacles
if h < 0 then
begin
for x:= 0 downto h do
begin
y:= MMCY + Round(k * x);
hi := High(Walls);
for i:= 0 to hi do
if ((x + MMCX) = Walls[i].x) then
if (y = Walls[i].y) then
begin
Result:= true;
obstacle:= 'wall';
fx:= x + MMCX;
fy:= y;
exit;
end;
hi := High(doors);
for i:= 0 to hi do
if ((x + MMCX) = Doors[i].x) then
if (y = Doors[i].y) then
begin
Result:= true;
obstacle:= 'door';
fx:= x + MMCX;
fy:= y;
exit;
end;
end;
end else
if h > 0 then
for x:= 0 to h do
begin
y:= MMCY + Round(k * x);
for i:= 0 to hi do
if ((x + MMCX) = Walls[i].x) then
if (y = Walls[i].y) then
begin
Result:= true;
obstacle:= 'wall';
fx:= x + MMCX;
fy:= y;
exit;
end;
for i:= 0 to High(Doors) do
if ((x + MMCX) = Doors[i].x) then
if (y = Doors[i].y) then
begin
Result:= true;
obstacle:= 'door';
fx:= x + MMCX;
fy:= y;
exit;
end;
end;
end;
EDIT: Fucks sake, i never get this to work 100%