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