SRL Archive - Senior Scripts and Snippets

SRL's Autocolor.scar


Nava2

2009-12-16 17:54:00

Cohen and I have been working on this for awhile (mostly Cohen).

We need some help/input. I don't have the time, right now, I will soon, and Cohen is frustrated.

program AutoColor;
{.Include SRL/SRL.scar}
{.include srl/srl/misc/debug.scar}

{ const AutoColor Constants;
Description: Constants representing the different types of AutoColors. To be
used in the funtion Find(); }
const
srl_AutoColorCount = 14;
srl_VarrockRoadColor = 0;
srl_LumbridgeRoadColor = 1;
srl_FaladorRoadColor = 2;
srl_AlKharidRoadColor = 3;
srl_DarkDirtRoadColor = 4;
srl_LightDirtRoadColor = 5;
srl_SandColor = 6;
srl_WaterColor = 7;
srl_SwampWaterColor = 8;
srl_LadderColor = 9;
srl_RockColor = 10;
srl_MineRockColor = 11;
srl_TreeColor = 12;

srl_ROADSPLIT = 4;

var
{ var ACArr
Description: Stores the information needed for the autocolour functions. }
acArr: array of TAutoColorInfo;

{ var isACLoaded
Description: Boolean array to make sure that all TAutoColorInfos are loaded
prior to calling. Optimizes AutoColors significantly. }
isACLoaded: array of Boolean;

{ Need to initialize the global vars Which store information. }
procedure SetupAutoColors;
begin
setLength(acArr, srl_AutoColorCount);
setLength(isACLoaded, srl_AutoColorCount);
end;

{*******************************************************************************
function LoadACArray(Which: Integer): TIntegerArray;
By: Coh3n
Description: Returns a color array depending on the parameter Which.
*******************************************************************************}
function LoadACArray(Which: Integer): TIntegerArray;
begin
case Which of

{ Done, tested. }
srl_VarrockRoadColor:
Result := [ 8620683, 8752269, 8489097, 8291717, 8160131, 8357511, 8818318,
8949648, 8816777, 8422019, 8947853, 8555145, 8094342, 8686479,
9013897, 8947848, 8487296, 9145489, 8947337, 9013386, 9013388,
8355458, 8487043, 7960700 ];

{ Done, tested. }
srl_LumbridgeRoadColor:
Result := [ 7963536, 7568520, 6318195, 7832206, 8161171, 7634570, 8095122,
7305605, 7766156, 7107969, 8095891, 7964305, 6977152, 7569290,
7437960, 7832975, 8357520, 8226190, 8160140, 7106937, 8489106,
7435903, 7702922, 7373956, 6847355, 6252912, 6186862, 7701377,
8161929, 7964549, 7832963, 8359564, 7306361, 7503741 ];

{ Done, tested. }
srl_FaladorRoadColor:
Result := [ 7569029, 7306114, 7437443, 6976892, 6647670, 6450290, 6318704,
6121068, 6581876, 7635079, 6910842, 7108478, 7240064, 5726310,
5265501, 7831939, 7305081, 7173751, 8029318, 6844529, 7504518,
7043967, 6583669, 7569021, 7700351, 8095623, 8226953, 6975865,
6778229 ];

{ Done, but doesn't work. }
srl_AlKharidRoadColor:
Result := [ 6195595, 6327438, 6063495, 6525074, 6590868, 6656917, 6459024,
6261644, 6327187, 6261137, 6129293, 6458773, 5931658, 6656666,
6853530, 6852759, 6457486, 6789533 ];

{ Done, tested. }
srl_DarkDirtRoadColor:
Result := [ 1853017, 1786966, 1786452, 1918811, 1654093, 2049630, 2049116,
2114904, 2115418 ];

{ Done, tested. }
srl_LightDirtRoadColor:
Result := [ 6784402, 7047575, 6652302, 6586508, 6520459, 6455952, 6390158,
6653845, 6192778, 6060678, 6456974, 6720403, 6589073, 6127750,
6586772, 6652566, 6784666, 6257293, 6326163, 6589592, 6655386,
6261136, 5799813, 6063501, 6260882, 5865353 ];

{ Done, tested. }
srl_SandColor:
Result := [ 8367041, 8103355, 8368321, 8566214, 6859196, 6133416, 6727353,
7188934, 8829900, 8696521, 8630728, 6395825, 6857148, 6659512,
6263724, 6988992, 5737886, 5605787, 4814213, 5409429, 5541273,
5607323, 8435903, 8501953, 7124673, 5937826, 6927036, 8633796,
8304060, 9224908, 7314081, 5869721 ];

{ Done, tested. }
srl_WaterColor:
Result := [ 10524303, 9603459, 10064009, 9142909, 8748408, 8617079,
10655889, 10721682, 11180175, 10851211, 10127746, 10655624,
10261123, 10063744, 10719630, 10588045, 9338236, 10327945,
10262151, 10130566, 9670272, 8682096, 10917513, 11114892 ];

{ Done, but doesn't work. }
srl_SwampWaterColor:
Result := [ 6121029, 6515785, 6647370, 6384199, 6187848, 5858628, 5793600,
6122820, 6252619, 5923399, 6121034, 6123596, 5728584, 5597509,
5463361, 5331776, 5595720, 6450502, 6055490, 6122571, 5793351,
6123082, 5728070, 6189387, 5794631, 6383946, 6054726 ];

srl_LadderColor:
Result := [ 405597, 207703, 405078, 470616, 601431, 404825, 339287, 338262,
404569, 470108, 208989, 274010, 338780, 601175, 272982, 208733,
536151, 272730, 208215, 339037, 405596, 601944, 207958, 601949 ];

{ The color of the rocks found on the Minimap. This also works with the
GRAY mine rocks. }
{ Done. }
srl_RockColor:
Result := [ 5725020, 4474183, 3685438, 2829872, 5987671, 4736834, 3948089,
4539973, 5855580, 3815998, 4604743 ];

{ The REDish color of the rocks in a mine on the minimap. Use srl_RockColor
for the GRAY mine rocks. }
{ Done. }
srl_MineRockColor:
Result := [ 3100807, 2573687, 2573941, 3101061, 2177633, 2706292, 3233412,
2309984, 2770298, 3297418, 2373990, 2509689, 3036809, 2971525,
2444405, 2048097, 2971271, 2444151, 2047843 ];

{ Done. }
srl_TreeColor:
Result := [ 2121284, 1463332, 1527603, 1333281, 1267488, 1202468, 999966 ];

else
srl_Warn('AutoColor',
'Index ''' + IntToStr(Which) + ''' is not a valid SRL AutoColor.',
warn_AllVersions);
end;
end;

{*******************************************************************************
function ReturnCorrectColors(possCols: TIntegerArray; Which: Integer): TIntegerArray;
By: Nava2
Description: Returns an array based on criteria passed.
*******************************************************************************}
function ReturnCorrectColors(possCols: TIntegerArray; Which: Integer): TIntegerArray;
var
i, h: Integer;
validArr: TIntegerArray;
dPts: T2DPointArray;
outPts: TPointArray;
begin
if (Length(possCols) = 0) then
Exit;

with acArr[Which] do
case Which of

srl_VarrockRoadColor..srl_SwampWaterColor:
begin
h := High(possCols);
setLength(dPts, h + 1);
for i := 0 to h do
begin
FindColors(dPts[i], possCols[i], MMX1, MMY1, MMX2, MMY2);
end;

outPts := MergeATPA(dPts);
RemoveDistTPointArray(MMCX, MMCY, MMX2 - MMCX, outPts, True);
ClearDoubleTPA(outPts);

dPts := SplitTPA(outPts, srl_ROADSPLIT);

SortATPASize(dPts, True);

validArr := getColors(dPts[0]);
ClearSameIntegers(validArr);
//DebugATPA(dPts, 'atpa');

srl_Warn('ReturnCorrectColors',
'Length: ' + IntToStr(length(validArr)) + '.',
warn_Debug);
Result := validArr;
end;

srl_LadderColor:
begin
end;

else
begin
Result := PossCols;
srl_Warn('ReturnCorrectColors',
'Unknown sort number.',
warn_AllVersions);
end;
end;
end;

{*******************************************************************************
function srl_AutoColor(Which: Integer): Integer;
By: Nava2 & Coh3n
Description: Finds the color on the minimap depending on the parameter Which.
i.e. srl_AutoColor(VarrockRoadColor);
*******************************************************************************}
function loadAutoColor(Which: Integer; out theAC: TAutoColorInfo): Boolean;
var
X, Y, Z: Extended;
autoColorInfo: TAutoColorInfo;
foundCols, newCols: TIntegerArray;
R, G, B: Integer;
curCTS: Integer;
h, i, c: Integer;
t: TPointArray;
functTime: Integer;
begin
Result := False;

{ Check if not loggedIn, or an invalid number has been passed. }
if (not LoggedIn) then Exit;
if (not InRange(Which, 0, (srl_AutoColorCount - 1))) then
begin;
srl_Warn('AutoColor',
'Index ''' + IntToStr(Which) + ''' is not a valid AutoColor.',
warn_AllVersions);
Exit;
end;

functTime := getTimeRunning;

autoColorInfo := GetSRLAutoColor(Which);
with autoColorInfo do
begin
curCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);

{ Find the colours Which match the TAutoColorInfo and filter out points that
are not part of the Minimap using RemoveDistTPointArray. }
SetColorSpeed2Modifiers(HueMod, satMod);
FindColorsTolerance(t, Color, MMX1, MMY1, MMX2, MMY2, LumTol);
RemoveDistTPointArray(MMCX, MMCY, (MMX2 - MMCX), t, True);

SetColorSpeed2Modifiers(0.2, 0.2);
ColorToleranceSpeed(curCTS);

if (Length(t) = 0) then Exit;

foundCols := getColors(t);
//DebugTPA(t, 'tpa');
ClearSameIntegers(foundCols);

{ Cycle through the colors found on the minimap, creating a new array based
on their RGB/XYZ ranges. }
h := High(foundCols);
setLength(newCols, h + 1);
for i := 0 to h do
begin
ColorToRGB(foundCols[i], R, G, B);

if (R >= MinR) and (R <= MaxR) and (G >= MinG) and (G <= MaxG) and
(B >= MinB) and (B <= MaxB) then
begin
ColorToXYZ(foundCols[i], X, Y, Z);

if (X >= MinX) and (X <= MaxX) and (Y >= MinY) and (Y <= MaxX) and
(Z >= MinZ) and (Z <= MaxZ) then
begin
newCols[c] := foundCols[i];
Inc(c);
end;
end;
end;

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

newCols := ReturnCorrectColors(newCols, Which);

if (Length(newCols) > 0) then
begin
acArr[Which] := CreateAutoColorInfo(newCols);
theAC := acArr[Which];
Result := True;
srl_Warn('srl_AutoColor',
'Function Successful: srl_AutoColor. Found Color = '
+ IntToStr(Result.Color) + '.',
warn_Debug);
end else
srl_Warn('srl_AutoColor',
'Couldn''t Find Color Index ' + IntToStr(Which) + '. ',
warn_AllVersions);
end;

srl_Warn('srl_AutoColor',
'Took: ' + IntToStr(getTimeRunning - functTime) + 'ms.',
warn_Debug);
end;

{*******************************************************************************
function CustomAutoColor(Colors: TIntegerArray): TAutoColorInfo;
By: Coh3n
Description: Runs custom colors through the srl AutoColor functions. Returns the
index in the AutoColor array.
*******************************************************************************}
function CustomAutoColor(Colors: TIntegerArray): Integer;
var
arrCount: Integer;
begin
arrCount := Length(acArr);
setLength(acArr, arrCount + 1);

acArr[arrCount] := CreateAutoColorInfo(Colors);
isACLoaded[arrCount] := True;

Result := arrCount;
end;

{*******************************************************************************
function GetSRLAutoColor(i: Integer): TAutoColorInfo;
by: Nava2
Description: Check the isACLoaded boolean for the asked AC, if true, we know the
AutoColorInfo has been loaded, and we will not do it again.
Otherwise, load the initial TAutoColorInfo from the stored array of
colours.
*******************************************************************************}
function srl_AutoColor(i: Integer): TAutoColorInfo;
begin
if isACLoaded[i] then
result := acArr[i]
else
begin
acArr[i] := CreateAutoColorInfo(LoadACArray(i));
isACLoaded[i] := loadAutoColor(i, Result);
if (not isACLoaded[i]) then
result := acArr[i];
end;
end;

{*******************************************************************************
function RadialWalkAutoColor(autoColorInd, sRadial, eRadial, rad, modX, modY: Integer): Boolean;
By: Coh3n & Nava2
Description: Radial Walks using the AutoColor stored at AutoColorInd
*******************************************************************************}
function RadialWalkAutoColor(autoColorInd, sRadial, eRadial, rad, modX, modY: Integer): Boolean;
var
TPA: TPointArray;
i, h, cts: Integer;
ACInfo: TAutoColorInfo;
begin
Result := False;

ACInfo := srl_AutoColor(autoColorInd);
with ACInfo do
begin
cts := getColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(hueMod, satMod);
if (RadialWalkEx(TPA, MMCX, MMCY, Color, LumTol, sRadial, eRadial, rad)) then
begin
h := High(TPA);
for i := 0 to h do
if (MFNF(TPA[i].x, TPA[i].y, modX, modY))then
begin
FFlag(10);
Result := True;
Break;
end;
end;
ColorToleranceSpeed(cts);
end;
end;

var
i, t: Integer;
//c: TAutoColorInfo;
begin
SetupSRL;
ActivateClient;
SetupAutoColors;
WarnSensitivity := -5;

t := GetSystemTime;
// for i := 1 to 25 do
srl_AutoColor(srl_VarrockRoadColor);
//Writeln('Took ' + IntToStr((GetSystemTime - t) div 25) + ' each time.');

{ c := srl_AutoColor(srl_LumbridgeRoadColor);
if not RadialWalkTolerance(c.Color, 45, 65, 70, 2 , 1, 70) then
Writeln('Couldn''t RadialWalk.'); }
end.

Well, what do you think? :)

I think we could also just get the colour thats the middle and use that with a tolerance rather than the arrays.. but I'm not sure if it makes more sense to leave it this way.

Also, maybe returning a TAutoColorInfo of all the colours found, then creating a new RadialWalk which will use the AutoColorInfo to walk would be good.. all ideas!


Anyways, criticism/help is wanted/appreciated.

Method

2009-12-16 17:56:07

I think you should rename your constants to something that will guarantee that they won't conflict with script identifiers. Some of them are probably commonly used (like TreeColor, RockColor, etc.) and may cause problems.

Nava2

2009-12-16 17:56:37

From: Method
I think you should rename your constants to something that will guarantee that they won't conflict with script identifiers. Some of them are probably commonly used (like TreeColor, RockColor, etc.) and may cause problems.


Yup, no question. This is still just testing.

E: Changed names.

Coh3n

2009-12-17 11:34:30

From: Nava2
Cohen and I have been working on this for awhile (mostly Cohen).

Mostly me? If you call staring at it for endless hours, figuring out what you did 'working', then yes, I have done most of the work. ;)

EDIT: I went to go test it, and got an Out of range error in line 159.

Result := possCols[j];


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

{ const AutoColor Constants;
Description: Constants representing the different types of AutoColors. To be
used in the funtion Find(); }
const
srl_AutoColorCount = 12;
srl_GeneralRoadColor = 0;
srl_VarrockRoadColor = 1;
srl_LumbridgeRoadColor = 2;
srl_FaladorRoadColor = 3;
srl_AlKharidRoadColor = 4;
srl_DirtRoadColor = 5;
srl_SandColor = 6;
srl_WaterColor = 7;
srl_LadderColor = 8;
srl_RockColor = 9;
srl_MineRockColor = 10;
srl_TreeColor = 11;

var
{ var ACArr
Description: Stores the information needed for the autocolour functions. }
acArr: array of TAutoColorInfo;

{ var isACLoaded
Description: Boolean array to make sure that all TAutoColorInfos are loaded
prior to calling. Optimizes AutoColors significantly. }
isACLoaded: array of Boolean;

{ Need to initialize the global vars Which store information. }
procedure SetupAutoColors;
begin
setLength(acArr, srl_AutoColorCount);
setLength(isACLoaded, srl_AutoColorCount);
end;

{*******************************************************************************
function ChooseAutoColor(Which: Integer): TIntegerArray;
By: Coh3n
Description: Returns a color array depending on the parameter Which.
*******************************************************************************}
function ChooseAutoColor(Which: Integer): TIntegerArray;
begin
case Which of

{ Represents the DARKER road color on the RS Minimap. }
srl_GeneralRoadColor:
Result := [ 6841703, 5920600, 6973289, 6710117, 7104875, 7368047, 7236461,
6446945, 6975092, 6711920, 6843506, 6053990, 6580334, 6448748,
6185576, 6317162, 5922403, 6909043, 7040629, 6777457, 6251113,
6645871, 6119527, 5724768, 5330009, 5198423, 6382699, 5856354 ];

srl_VarrockRoadColor:
Result := [ 8620683, 8752269, 8489097, 8291717, 8160131, 8357511, 8818318,
8949648, 8816777, 8422019, 8947853, 8555145, 8094342, 8686479,
9013897, 8947848, 8487296, 9145489, 8947337, 9013386, 9013388 ];

srl_LumbridgeRoadColor:
Result := [ 7963536, 7568520, 6318195, 7832206, 8161171, 7634570, 8095122,
7305605, 7766156, 7107969 ];

srl_FaladorRoadColor:
Result := [ 7569029, 7306114, 7437443, 6976892, 6647670, 6450290, 6318704,
6121068, 6581876, 7635079, 6910842, 7108478, 7240064, 5726310,
5265501 ];

srl_AlKharidRoadColor:
Result := [ 6195595, 6327438, 6063495, 6525074, 6590868, 6656917, 6459024,
6261644 ];

srl_DirtRoadColor:
Result := [ 2114650, 2114908, 2048599, 1982549, 1916499, 6588565, 6391185,
6325135 ];

srl_SandColor:
Result := [ 8367041, 8103355, 8368321, 8566214, 6859196, 6133416, 6727353,
7188934, 8829900, 8696521, 8630728, 6395825, 6857148, 6659512,
6263724, 6988992, 5737886, 5605787, 4814213, 5409429, 5541273,
5607323 ];

{ Includes swamp water color. }
srl_WaterColor:
Result := [ 10524303, 9603459, 10064009, 9142909, 8748408, 8617079,
10655889, 10721682, 6383946, 5989190 ];

srl_LadderColor:
Result := [ 207703 ];

{ The color of the rocks found on the Minimap. This IS NOT the mine rocks! }
srl_RockColor:
Result := [ 5725020, 4474183, 3685438, 2829872 ];

{ The REDish color of the rocks in a mine on the minimap. }
srl_MineRockColor:
Result := [ 3100807, 2573687 ];

srl_TreeColor:
Result := [ 2121284, 1463332, 1527603 ];

else
srl_Warn('AutoColor',
'Index ''' + IntToStr(Which) + ''' is not a valid SRL AutoColor.',
warn_AllVersions);
end;
end;

{*******************************************************************************
function GetSRLAutoColor(i: Integer): TAutoColorInfo;
by: Nava2
Description: Check the isACLoaded boolean for the asked AC, if true, we know the
AutoColorInfo has been loaded, and we will not do it again.
Otherwise, load the initial TAutoColorInfo from the stored array of
colours.
*******************************************************************************}
function GetSRLAutoColor(i: Integer): TAutoColorInfo;
begin
if isACLoaded[i] then
result := acArr[i]
else
begin
acArr[i] := CreateAutoColorInfo(ChooseAutoColor(i));
result := acArr[i];
isACLoaded[i] := True;
end;
end;

{*******************************************************************************
function ReturnCorrectColor(possCols: TIntegerArray; Which: Integer): Integer;
By: Nava2
Description: Returns an array based on criteria passed.
*******************************************************************************}
function ReturnCorrectColor(possCols: TIntegerArray; Which: Integer): Integer;
var
i, j, c, h, curMax: Integer;
t: TPointArray;
begin
with acArr[Which] do
case Which of

srl_GeneralRoadColor..srl_WaterColor:
begin
with acArr[Which] do
begin
{ Return the colour with the highest count. }
h := High(possCols);
for i := 0 to h do
begin
FindColorsTolerance(t, possCols[i], MMX1, MMY1, MMX2, MMY2, lumTol);
c := Length(t);
if (c > curMax) then
begin
j := i;
curMax := c;
end;
end;
end;
Result := possCols[j];
end;

srl_LadderColor:
begin
end;
end;
end;

{*******************************************************************************
function srl_AutoColor(Which: Integer): Integer;
By: Nava2
Description: Finds the color on the minimap depending on the parameter Which.
i.e. Find(VarrockRoadColor);
*******************************************************************************}
function srl_AutoColor(Which: Integer): Integer;
var
R, G, B: Integer;
X, Y, Z: Extended;
i, h, c, curCTS: Integer;
t: TPointArray;
newCols, aC: TIntegerArray;
autoColorInfo: TAutoColorInfo;
begin
Result := -1;
{ Check if not loggedIn, or an invalid number has been passed. }
if (not LoggedIn) then Exit;
if (not InRange(Which, 0, (srl_AutoColorCount - 1))) then
begin;
srl_Warn('AutoColor',
'Index ''' + IntToStr(Which) + ''' is not a valid AutoColor.',
warn_AllVersions);
Exit;
end;

autoColorInfo := GetSRLAutoColor(Which);

curCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
with autoColorInfo do
begin
{ Find the colours Which match the TAutoColorInfo and filter out points that
are not part of the Minimap using RemoveDistTPointArray. }
SetColorSpeed2Modifiers(HueMod, SatMod);
FindColorsTolerance(t, Color, MMX1, MMY1, MMX2, MMY2, LumTol);
RemoveDistTPointArray(MMCX, MMCY, (MMX2 - MMX1) shr 1, t, True);

{ Load all the colours into a new array. Removing any duplicates for speed. }
aC := getColors(t);
ClearSameIntegers(aC);

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

if (R >= MinR) and (R <= MaxR) and (G >= MinG) and (G <= MaxG) and
(B >= MinB) and (B <= MaxB) then
begin
ColorToXYZ(aC[i], X, Y, Z);

if (X >= MinX) and (X <= MaxX) and (Y >= MinY) and (Y <= MaxX) and
(Z >= MinZ) and (Z <= MaxZ) then
begin
newCols[c] := aC[i];
Inc(c);
end;
end;
end;

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

{ Pass the newCols array to the ReturnCorrectColors function Which will
return the best match. }
Result := ReturnCorrectColor(newCols, Which);
end;

if (Result = -1) then
srl_Warn('AutoColor', 'Couldn''t Find Color Index ' + IntToStr(Which) +
'. ', warn_AllVersions)
else
srl_Warn('AutoColor', 'Found Color: ' + IntToStr(Result) + '. ',
warn_AllVersions);

SetColorSpeed2Modifiers(0.2, 0.2);
ColorToleranceSpeed(curCTS);
end;

{*******************************************************************************
function CustomAutoColor(Colors: TIntegerArray): Integer;
By: Coh3n
Description: Runs custom colors through the AutoColor function, and returns the
best color.
*******************************************************************************}
function CustomAutoColor(Colors: TIntegerArray): Integer;
var
Index, arrCount: Integer;
begin
Result := -1;

arrCount := Length(acArr);
Inc(arrCount);
Index := Length(acArr);

acArr[Index] := CreateAutoColorInfo(Colors);
isACLoaded[Index] := True;

Result := srl_AutoColor(Index);
end;

var
t, i: Integer;
begin
SetupSRL;
ActivateClient;
SetupAutoColors;

t := GetSystemTime;
for i := 1 to 50 do
srl_AutoColor(srl_SandColor);
Writeln('Took ' + IntToStr((GetSystemTime - t) div 50) + ' each time.');

{ RadialWalkTolerance(Find(VarrockRoadColor), 45, 65, 70, 2 , 1, 10); }
end.

Zeph helped me come to the conclusion that it's because the length of possColors isn't > 0. However, I can't see how to fix it, and I have to go for a couple hours. Hopefully someone here can help me. :)

Nava2

2009-12-17 12:57:38

Fixed the add AutoColor and the issue with OutOfRange, if that is passed, then no valid colours were found.

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

{ const AutoColor Constants;
Description: Constants representing the different types of AutoColors. To be
used in the funtion Find(); }
const
srl_AutoColorCount = 12;
srl_GeneralRoadColor = 0;
srl_VarrockRoadColor = 1;
srl_LumbridgeRoadColor = 2;
srl_FaladorRoadColor = 3;
srl_AlKharidRoadColor = 4;
srl_DirtRoadColor = 5;
srl_SandColor = 6;
srl_WaterColor = 7;
srl_LadderColor = 8;
srl_RockColor = 9;
srl_MineRockColor = 10;
srl_TreeColor = 11;

var
{ var ACArr
Description: Stores the information needed for the autocolour functions. }
acArr: array of TAutoColorInfo;

{ var isACLoaded
Description: Boolean array to make sure that all TAutoColorInfos are loaded
prior to calling. Optimizes AutoColors significantly. }
isACLoaded: array of Boolean;

{ Need to initialize the global vars Which store information. }
procedure SetupAutoColors;
begin
setLength(acArr, srl_AutoColorCount);
setLength(isACLoaded, srl_AutoColorCount);
end;

{*******************************************************************************
function ChooseAutoColor(Which: Integer): TIntegerArray;
By: Coh3n
Description: Returns a color array depending on the parameter Which.
*******************************************************************************}
function ChooseAutoColor(Which: Integer): TIntegerArray;
begin
case Which of

{ Represents the DARKER road color on the RS Minimap. }
srl_GeneralRoadColor:
Result := [ 6841703, 5920600, 6973289, 6710117, 7104875, 7368047, 7236461,
6446945, 6975092, 6711920, 6843506, 6053990, 6580334, 6448748,
6185576, 6317162, 5922403, 6909043, 7040629, 6777457, 6251113,
6645871, 6119527, 5724768, 5330009, 5198423, 6382699, 5856354 ];

srl_VarrockRoadColor:
Result := [ 8620683, 8752269, 8489097, 8291717, 8160131, 8357511, 8818318,
8949648, 8816777, 8422019, 8947853, 8555145, 8094342, 8686479,
9013897, 8947848, 8487296, 9145489, 8947337, 9013386, 9013388 ];

srl_LumbridgeRoadColor:
Result := [ 7963536, 7568520, 6318195, 7832206, 8161171, 7634570, 8095122,
7305605, 7766156, 7107969 ];

srl_FaladorRoadColor:
Result := [ 7569029, 7306114, 7437443, 6976892, 6647670, 6450290, 6318704,
6121068, 6581876, 7635079, 6910842, 7108478, 7240064, 5726310,
5265501 ];

srl_AlKharidRoadColor:
Result := [ 6195595, 6327438, 6063495, 6525074, 6590868, 6656917, 6459024,
6261644 ];

srl_DirtRoadColor:
Result := [ 2114650, 2114908, 2048599, 1982549, 1916499, 6588565, 6391185,
6325135 ];

srl_SandColor:
Result := [ 8367041, 8103355, 8368321, 8566214, 6859196, 6133416, 6727353,
7188934, 8829900, 8696521, 8630728, 6395825, 6857148, 6659512,
6263724, 6988992, 5737886, 5605787, 4814213, 5409429, 5541273,
5607323 ];

{ Includes swamp water color. }
srl_WaterColor:
Result := [ 10524303, 9603459, 10064009, 9142909, 8748408, 8617079,
10655889, 10721682, 6383946, 5989190 ];

srl_LadderColor:
Result := [ 207703 ];

{ The color of the rocks found on the Minimap. This IS NOT the mine rocks! }
srl_RockColor:
Result := [ 5725020, 4474183, 3685438, 2829872 ];

{ The REDish color of the rocks in a mine on the minimap. }
srl_MineRockColor:
Result := [ 3100807, 2573687 ];

srl_TreeColor:
Result := [ 2121284, 1463332, 1527603 ];

else
srl_Warn('AutoColor',
'Index ''' + IntToStr(Which) + ''' is not a valid SRL AutoColor.',
warn_AllVersions);
end;
end;

{*******************************************************************************
function GetSRLAutoColor(i: Integer): TAutoColorInfo;
by: Nava2
Description: Check the isACLoaded boolean for the asked AC, if true, we know the
AutoColorInfo has been loaded, and we will not do it again.
Otherwise, load the initial TAutoColorInfo from the stored array of
colours.
*******************************************************************************}
function GetSRLAutoColor(i: Integer): TAutoColorInfo;
begin
if isACLoaded[i] then
result := acArr[i]
else
begin
acArr[i] := CreateAutoColorInfo(ChooseAutoColor(i));
result := acArr[i];
isACLoaded[i] := True;
end;
end;

{*******************************************************************************
function ReturnCorrectColor(possCols: TIntegerArray; Which: Integer): Integer;
By: Nava2
Description: Returns an array based on criteria passed.
*******************************************************************************}
function ReturnCorrectColor(possCols: TIntegerArray; Which: Integer): Integer;
var
i, j, c, h, curMax: Integer;
t: TPointArray;
begin
Result := -1;
if (Length(possCols) = 0) then
Exit;

with acArr[Which] do
case Which of

srl_GeneralRoadColor..srl_WaterColor:
begin
with acArr[Which] do
begin
{ Return the colour with the highest count. }
h := High(possCols);
for i := 0 to h do
begin
FindColorsTolerance(t, possCols[i], MMX1, MMY1, MMX2, MMY2, lumTol);
c := Length(t);
if (c > curMax) then
begin
j := i;
curMax := c;
end;
end;
end;
Result := possCols[j];
end;

srl_LadderColor:
begin
end;
end;
end;

{*******************************************************************************
function srl_AutoColor(Which: Integer): Integer;
By: Nava2
Description: Finds the color on the minimap depending on the parameter Which.
i.e. Find(VarrockRoadColor);
*******************************************************************************}
function srl_AutoColor(Which: Integer): Integer;
var
R, G, B: Integer;
X, Y, Z: Extended;
i, h, c, curCTS: Integer;
t: TPointArray;
newCols, aC: TIntegerArray;
autoColorInfo: TAutoColorInfo;
begin
Result := -1;
{ Check if not loggedIn, or an invalid number has been passed. }
if (not LoggedIn) then Exit;
if (not InRange(Which, 0, (srl_AutoColorCount - 1))) then
begin;
srl_Warn('AutoColor',
'Index ''' + IntToStr(Which) + ''' is not a valid AutoColor.',
warn_AllVersions);
Exit;
end;

autoColorInfo := GetSRLAutoColor(Which);

curCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
with autoColorInfo do
begin
{ Find the colours Which match the TAutoColorInfo and filter out points that
are not part of the Minimap using RemoveDistTPointArray. }
SetColorSpeed2Modifiers(HueMod, SatMod);
FindColorsTolerance(t, Color, MMX1, MMY1, MMX2, MMY2, LumTol);
RemoveDistTPointArray(MMCX, MMCY, (MMX2 - MMX1) shr 1, t, True);

{ Load all the colours into a new array. Removing any duplicates for speed. }
aC := getColors(t);
ClearSameIntegers(aC);

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

if (R >= MinR) and (R <= MaxR) and (G >= MinG) and (G <= MaxG) and
(B >= MinB) and (B <= MaxB) then
begin
ColorToXYZ(aC[i], X, Y, Z);

if (X >= MinX) and (X <= MaxX) and (Y >= MinY) and (Y <= MaxX) and
(Z >= MinZ) and (Z <= MaxZ) then
begin
newCols[c] := aC[i];
Inc(c);
end;
end;
end;

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

{ Pass the newCols array to the ReturnCorrectColors function Which will
return the best match. }
Result := ReturnCorrectColor(newCols, Which);
end;

if (Result = -1) then
srl_Warn('AutoColor', 'Couldn''t Find Color Index ' + IntToStr(Which) +
'. ', warn_AllVersions)
else
srl_Warn('AutoColor', 'Found Color: ' + IntToStr(Result) + '. ',
warn_AllVersions);

SetColorSpeed2Modifiers(0.2, 0.2);
ColorToleranceSpeed(curCTS);
end;

{*******************************************************************************
function CustomAutoColor(Colors: TIntegerArray): Integer;
By: Coh3n
Description: Runs custom colors through the AutoColor function, and returns the
best color.
*******************************************************************************}
function CustomAutoColor(Colors: TIntegerArray): Integer;
var
Index, arrCount: Integer;
begin
Result := -1;

arrCount := Length(acArr);
setLength(acArr, arrCount + 1);

acArr[arrCount] := CreateAutoColorInfo(Colors);
isACLoaded[arrCount] := True;

Result := srl_AutoColor(arrCount);
end;

var
t, i: Integer;
begin
SetupSRL;
ActivateClient;
SetupAutoColors;

t := GetSystemTime;
for i := 1 to 50 do
srl_AutoColor(srl_SandColor);
Writeln('Took ' + IntToStr((GetSystemTime - t) div 50) + ' each time.');

{ RadialWalkTolerance(Find(VarrockRoadColor), 45, 65, 70, 2 , 1, 10); }
end.

Coh3n

2009-12-17 13:25:36

Pfft, as if I didn't think of that. That's like the most basic thing. :duh:

Nava2

2009-12-30 16:39:33

Updated a lot.

Anything to add before its committed?

Coh3n

2009-12-30 16:41:53

The ladder color stuff?

Wanted

2009-12-30 17:12:38

From: Nava2
Updated a lot.

Anything to add before its committed?


Color wise:

FindRockColor

http://www.villavu.com/forum/showthread.php?t=53671

Other stuff:

Bee_Puzzle: http://www.villavu.com/forum/showthread.php?t=53227

Foresterr : http://www.villavu.com/forum/showthread.php?t=53542
Pinball: http://www.villavu.com/forum/showthread.php?t=53865
Demon: http://www.villavu.com/forum/showthread.php?t=53503

Stuff in making:

Evil bob should be done soon
Fix quiz is a bit buggy… this http://www.villavu.com/forum/showthread.php?t=53454 will fix it for Quizmaster but not normal quiz
Prison pete is untested, but the plugin is still gone?

That's all I can think of

Nava2

2009-12-30 17:15:06

From: IceFire908
Color wise:

FindRockColor

http://www.villavu.com/forum/showthread.php?t=53671

Other stuff:

Bee_Puzzle: http://www.villavu.com/forum/showthread.php?t=53227

Foresterr : http://www.villavu.com/forum/showthread.php?t=53542
Pinball: http://www.villavu.com/forum/showthread.php?t=53865
Demon: http://www.villavu.com/forum/showthread.php?t=53503

Stuff in making:

Evil bob should be done sone
Fix quiz is a bit buggy… this http://www.villavu.com/forum/showthread.php?t=53454 will fix it for Quizmaster but not normal quiz
Prison pete is untested, but the plugin is still gone?

That's all I can think of


Silly boy, I ninja'd you badly.

Wanted

2009-12-30 17:15:32

From: Nava2
Silly boy, I ninja'd you badly.


Awww :duh:

Nava2

2009-12-30 17:19:33

From: IceFire908
Awww :duh:


Although, I *did* miss the quiz.

Wanted

2009-12-30 17:21:56

From: Nava2
Although, I *did* miss the quiz.


Yea and I'm not sure but maybe molly is different still, and pete has the plugin functions commented out and I'm not sure if everything in SolveTeleportRanomds is setup correctly, meh it will get fixed eventually.

Town

2009-12-30 17:54:23

http://www.villavu.com/forum/showthread.php?p=670783#post670783

Nava2

2009-12-30 19:10:51

Already fixed that.

But, I was looking for things todo with this file..

Town

2009-12-30 23:04:23

From: IceFire908
Prison pete is untested, but the plugin is still gone?


Is the plugin in the latest revision? The functions are.

Nava2

2010-05-25 11:50:05

Bump as someone asked for this in dev forums. I might have a better version on my computer. I will check later on!