SRL Archive - SRL Archives

FindBridgeColors: Integer;


Claymore

2008-10-18 22:41:42


function FindBridgeColors: Integer;
var
GC, I, L, TestColor, WaterColor, X, Y: integer;
P : TPointArray;
begin
WaterColor := FindWaterColor;
if (not (FindColor(X, Y, WaterColor, MMX1, MMY1, MMX2, MMY2))) then
WaterColor := FindWaterColor;
if (WaterColor = 0) then
begin
Result := 0;
Exit;
end;
GC := 1389645;
Flag;
FindColorsSpiralTolerance(MMCX, MMCY, P, GC, MMX1, MMY1, MMX2, MMY2, 60);
L := GetArrayLength(P);
for I := 0 to L - 1 do
begin
if rs_OnMinimap(P[I].X, P[I].Y) then
begin
TestColor := GetColor(P[I].X, P[I].Y);
if GetColor(P[I].X + 1, P[I].Y) = WaterColor then
if GetColor(P[I].X - 2, P[I].Y) = TestColor then
if GetColor(P[I].X, P[I].Y - 3) = TestColor then
begin
Result := TestColor;
WriteLn('Bridge Color = ' + IntToStr(Result));
Exit;
end;
end;
end;
WriteLn('Could not find Bridge Color.');
Result := 0;
end;

The old one is broken, this one works on the Entrana Bridge. Yes I am making a Law Crafter, but anyways this should be fixed (Mine might be incorrect, but I'm just saying this function needs to be fixed.)

Peace out! And look for my Law Crafter when it comes out! (Its not based on Reflection.) :f:

The_Shermanator

2008-10-18 23:28:58

Looks nice, Good Job!! :D

Claymore

2008-10-18 23:36:40

Thanks Shermanator ;p I am gonna make a tutorial of this sometime ;p

tarajunky

2008-10-19 00:02:17

Good job on the rewrite. I fixed the old function, and this should now work for any "striped" bridge, including the one on Entrana.


function FindBridgeColor: Integer;
var
GC, a, l, TestColor, x, y: integer;
var
P:array of Tpoint;
begin
if WaterColor = 0 then WaterColor := FindWaterColor;
if not(FindColor(x, y, WaterColor, MMX1, MMY1, MMX2, MMY2)) then
WaterColor := FindWaterColor;
if WaterColor = 0 then
begin
WriteLn('No water on screen... aborting');
Result := 0;
Exit;
end;
GC := 1389645;
Flag;
FindColorsSpiralTolerance(MMCX, MMCY, P, GC, MMX1, MMY1, MMX2, MMY2, 60);
l:=GetArrayLength(P);
for a:= 0 to l-1 do
begin
if rs_OnMinimap(P[a].x,P[a].y) then
begin
TestColor := GetColor(P[a].x,P[a].y);
if GetColor(P[a].x-1,P[a].y)=Testcolor+395277 then
begin
if FindColor(x,y,WaterColor,P[a].x-3,P[a].y-3,P[a].x+3,P[a].y+3) then
begin
Result := TestColor;
WriteLn('Bridge Color = ' + IntToStr(TestColor));
Exit;
end;
end;
end;
end;
WriteLn('Could not find Bridge Color!');
Result := 0;
end;

Your function looks like it's based on a geometric arrangement of 4 pixels. It's essentially a DDTM. There's nothing wrong with that, and it may work great on Entrana, but it might run into problems other places around the map where the riverbanks are wide. The old broken function and this function are based on the color "distance" between the two adjacent bridge colors being a specific value, 395277. I will update this one to SRL, but use what works best for you.

Claymore

2008-10-19 00:45:02

Thanks tarajunky, seems my version works so far in Entrana, but i still don't seem to get how the SRL Auto coloring works. I see this…


if GetColor(P[a].x-1,P[a].y)=Testcolor+395277 then

I thought a while ago it meant the differences of the color next to the Testcolor. So like, the Testcolor - 395277 = Color of the other strip of the bridge.

EDIT:
And yes, it is like a DTM (DDTM because of a auto-color). :p I just noticed!

EDIT EDIT:
Never mind, i figured it out thanks to you. Although i was right the whole time.

Claymore

2008-10-19 16:12:28


function FindBridgeColors: Integer;
var
GC, A, L, TestColor, x, y: integer;
P: TPointArray;
begin
if (WaterColor = 0) then
WaterColor := FindWaterColor;
if (not (FindColor(X, Y, WaterColor, MMX1, MMY1, MMX2, MMY2))) then
WaterColor := FindWaterColor;
if (WaterColor = 0) then
begin
Result := 0;
Exit;
end;
GC := 1389645;
Flag;
FindColorsSpiralTolerance(MMCX, MMCY, P, GC, MMX1, MMY1, MMX2, MMY2, 60);
L := GetArrayLength(P);
for A := 0 to L-1 do
begin
if rs_OnMinimap(P[A].X, P[A].Y) and rs_OnMinimap(P[A].X-1, P[A].Y) then
begin
TestColor := GetColor(P[A].X, P[A].Y);
if (GetColor(P[A].X-1, P[A].Y) = TestColor+395277) then
begin
if (FindColor(X, Y, WaterColor, P[A].X-3, P[A].Y-3, P[A].X+3, P[A].Y+3)) then
begin
Result := TestColor;
WriteLn('Bridge Color = ' + IntToStr(TestColor));
Exit;
end;
end
else
begin
if (InRange(iAbs(TestColor - GetColor(P[A].X-1, P[A].Y)), 264205, 395277)) then
if (FindColor(X, Y, WaterColor, P[A].X-3, P[A].Y-3, P[A].X+3, P[A].Y+3)) then
begin
Result := TestColor;
WriteLn('Bridge Color = ' + IntToStr(TestColor));
Exit;
end;
end;
end;
end;
WriteLn('Could not find Bridge Color.');
Result := 0;
end;

I found out the difference changes every 12 hours i think, anyways i added a fail safe if yours fail ;p