SRL Archive - SRL Archives

We need Autocolors: Door and Whitewall!


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

{.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%

footballjds

2009-05-05 19:32:47

srl/scripting tools/ auto color aid v2 <—–

ill try to make it as i wanted it anyhow

marpis

2009-05-05 19:35:30

alrdy tried, didnt work accurately

footballjds

2009-05-05 19:36:48

lol, u need to pick one color of white walll… log then pick another on another world.. etc until you get about 3-4…
or make a bmp of about 1*4 and search mm for that or do the same with a dtm ;)

marpis

2009-05-05 21:09:23

but i'd have to use tolerance anyway? and i rly don't understand your idea.
if i have a 1x4 bmp with 4 "white" pixels all different color, how could i find anything with it? or how could i use a dtm made of these pixels? because there are soo many different colors used in these walls.

Anyways i got an idea to make my function work with color tolerance :)
instead of
if GetColor(P[a].x, P[a].y) = wallc
i use:
if FindColorTolerance(x, y, P[a].x, P[a].y, P[a].x, P[a].y, 40)

i post it here if it works

footballjds

2009-05-05 21:10:56

40 might be high lol

footballjds

2009-05-05 21:24:27

works perfectly ;)

function AutoWallColor :integer;
var
wall2by1, tmx, tmy: integer;
begin
wall2by1 := DTMFromString('78DA632C60626050674001EF9FBF629004D28' +
'C503E23488D1A6E35FF81000004520AE4');
FindDTMRotated(wall2by1, tmx, tmy, mmx1, mmy1, mmx2, mmy2, 0, 360, 1, angle);
freedtm(wall2by1);
result := GetColor(tmx, tmy);
if not(SimilarColors(result, 16247020, 35)) then result := 0;
end;

footballjds

2009-05-05 21:29:54

to test:

program New;
{.include srl/srl.scar}
var
I, x, y, z :integer;
dtm1, dtm2, dtm3 :integer;
angle :extended;
function AutoWallColor :integer;
var
wall2by1, tmx, tmy: integer;
begin
wall2by1 := DTMFromString('78DA632C60626050674001EF9FBF629004D28' +
'C503E23488D1A6E35FF81000004520AE4');
FindDTMRotated(wall2by1, tmx, tmy, mmx1, mmy1, mmx2, mmy2, 0, 360, 1, angle);
freedtm(wall2by1);
result := GetColor(tmx, tmy);
if not(SimilarColors(result, 16247020, 35)) then result := 0;
moveMouse(tmx, tmy);
end;
begin
MouseSpeed := 15+random(3);
writeln(inttoStr(autoWallColor));
end.
it ignores player dots etc :D

marpis

2009-05-05 21:52:55

doesnt work.
wallcolor = 7176587 says your function, but
Color Picked: 15462379 at (652, 82)

EDIT: Im taking a new point of view to this case: TPA.