SRL Archive - SRL Suggestions

New AutoColor.scar


Coh3n

2009-11-26 17:15:18

AutoColor.scar

So as a result of the autocoloring functions not working for me, Nava has graciously made an awesome function for me to use that can be used for any color by editing only one line. This gave me a cool idea (well, cool to me at least :tongue:). Basically, it consists of a single AutoColor funtion instead of a whole function for every color. It has a second function that loads the necessary RGB ranges for the AutoColor function to work.

This way is very fast (takes 19ms to find the color), works 99.9% of the time, and is much for efficient then the current AutoColor.scar. Anyway, I just wanted to see what people think.

program AutoColor;
{.Include SRL/SRL.scar}

{ const AutoColor Constants;
Description: Constants representing the different types of AutoColors. }
const
DraynorRoadColor = 0;
DraynorBankColor = 1;
{
.
.
.
}

{ const RGB Constants;
Description: Constants representing the placement of RGB ranges in the
ChooseAutoColor array. }
const
minR = 0;
maxR = 1;
minG = 2;
maxG = 3;
minB = 4;
maxB = 5;

var
srl_MMTPA: TPointArray;

{*******************************************************************************
function ChooseAutoColor(Which: Integer): TIntegerArray;
By: Coh3n
Description: Creates an array of the RGB ranges to use in the autocolor function.
*******************************************************************************}
function ChooseAutoColor(Which: Integer): TIntegerArray;
begin
case Which of

RoadColor:
Result := [{minR} 73, {maxR} 100, {minG} 75, {maxG} 100, {minB} 72, {maxB} 97];

DraynorBankColor:
Result := [{minR} 49, {maxR} 63, {minG} 51, {maxG} 64, {minB} 47, {maxB} 60];

{
.
.
.
}

else
srl_Warn('ChooseAutoColor', 'Not a vaild minimap color. ', warn_Debug);
end;
end;

{*******************************************************************************
function CircleTPA(cX, cY, r: Integer): TPointArray;
By: Nava2
Description: Creates a TPA of a circle with radius 'r' and center point cX, cY.
*******************************************************************************}
function CircleTPA(cX, cY, r: Integer): TPointArray;
var
i, j, l, tX, tY: Integer;
begin
setLength(Result, 4 * r * r);
l := 2 * r - 1;
tX := cX - r;
tY := cY - r;
for i := 0 to l do
for j := 0 to l do
Result[j + l * i] := Point(tX + i, tY + j);

Result := RemoveDistTPointArray(cX, cY, r, Result, True);
end;

{*******************************************************************************
function srl_ReturnMMTPA: TPointArray;
By: Nava2
Description: Performs CircleTPA for the RS minimap.
*******************************************************************************}
function srl_ReturnMMTPA: TPointArray;
begin
if High(srl_MMTPA) < 0 then
begin
Result := CircleTPA(MMCX, MMCY, (MMX2 - MMX1) div 2);
srl_MMTPA := Result;
end else
Result := srl_MMTPA;
end;

{*******************************************************************************
function Find(Which: Integer): Integer;
By: Nava2
Description: Finds best color on the minimap, depending on the RGB ranges.
*******************************************************************************}
function Find(Which: Integer): Integer;
var
R, G, B: Integer;
i, h, c, curMax, j: Integer;
t: TPointArray;
CycleCols, newCols, colorCounts, Color: TIntegerArray;
begin
Color := ChooseAutoColor(Which);

{ Get all the colours in the minimap. }
CycleCols := GetColors(srl_ReturnMMTPA);
ClearSameIntegers(CycleCols);

{ Cycle through creating a new array based on the inputted RGB max/mins. }
h := High(CycleCols);
setLength(newCols, h + 1);
for i := 0 to h do
begin
ColorToRGB(CycleCols[i], R, G, B);

if (InRange(R, Color[minR], Color[maxR]) and
InRange(G, Color[minG], Color[maxG]) and
InRange(B, Color[minB], Color[maxB])) then
begin
newCols[c] := CycleCols[i];
Inc(c);
end;

end;

setLength(newCols, c);
setLength(colorCounts, c);
Dec(c);

{
Use the colour which is most common. Could be substituted to use other
means to pick the right colour post-RGB checks. (Density, TPA spread, etc.)
}
for i := 0 to c do
begin
FindColors(t, newCols[i], MMX1, MMY1, MMX2, MMY2);
h := Length(t);
if (h > curMax) then
begin
j := i;
curMax := h;
end;
end;

Result := newCols[j];
Writeln('Found Color: ' + IntToStr(Result));
end;

begin
SetupSRL;
ActivateClient;
ClearDebug;

Find(DraynorBankColor);
Find(DraynorRoadColor);
end.

Nava2

2009-11-26 18:26:40

Haha, I'd just like to point out you changed almost nothing..

But I think it would be faster to actually get the max spread, do a FindColorsTolerance and then do that stuff.. less colours.

Rather traditional, really.

Coh3n

2009-12-04 00:02:50

From: Nava2
Haha, I'd just like to point out you changed almost nothing..

But I think it would be faster to actually get the max spread, do a FindColorsTolerance and then do that stuff.. less colours.

Rather traditional, really.

I didn't say I did? Could you explain what you mean when you say 'max spread'?

Does anyone else have an opinion on this? I don't care if you shoot it down, I just thought it might be a neat idea since the current autocolor functions don't seem to work all that well. Not to mention a lot of them are the same, and just take just needless space in the include.

Thanks. :smile:

Nava2

2009-12-04 00:10:25

From: Coh3n
I didn't say I did? Could you explain what you mean when you say 'max spread'?

Does anyone else have an opinion on this? I don't care if you shoot it down, I just thought it might be a neat idea since the current autocolor functions don't seem to work all that well. Not to mention a lot of them are the same, and just take just needless space in the include.

Thanks. :smile:


Max distance between R, R ; G, G; and B, B which is the tolerance

Coh3n

2009-12-04 00:15:31

From: Nava2
Max distance between R, R ; G, G; and B, B which is the tolerance

It that not the same as when you used the InRange if..then statement?

Nava2

2009-12-04 08:41:49

From: Coh3n
It that not the same as when you used the InRange if..then statement?


Yes, but if you do the findColorsTolerance first, less colours are found and its faster.

Coh3n

2009-12-04 12:25:53

From: Nava2
Yes, but if you do the findColorsTolerance first, less colours are found and its faster.

I don't see how less colors are found, because wouldn't the RGB ranges narrow it down, so it would look for only a certain color with tolerance?