Simba Code:
program new;
{$i srl/srl/misc/Smart.simba}
{$i srl/srl.simba}
{$i srl/srl/misc/paintsmart.simba}
Type
TTPA2Item = Record
Tolerance, CountHi, CountLow, Color: Integer;
Bitmaps: TIntegerArray;
Hue, Sat, BmpAcc: Extended;
end;
Var
TPAItems: Array of TTPA2Item;
Mask_Ore, Mask_Bar: Integer;
Function FindTPA2Item(var x, y, BmpNum: integer; Item: TTPA2Item; Area: TBox): Boolean;
var
cts, target, C, w, h, bmp, i: Integer;
TPA, TPA2: TPointArray;
Acc: Extended;
ATPA: T2DPointArray;
B: TBox;
begin
cts := GetColorToleranceSpeed;
target := GetImageTarget;
SetColorToleranceSpeed(2);
SetColorspeed2Modifiers(Item.Hue, Item.Sat)
with Area do
FindColorsTolerance(TPA, Item.Color, X1, Y1, X2, Y2, Item.Tolerance);
SetColorToleranceSpeed(cts);
ATPA := SplitTPA(TPA, 2);
for i := 0 to High(ATPA) do
begin
if not InRange(Length(ATPA[i]), Item.CountLow, Item.CountHi) then
Continue;
Writeln('ATPA['+ToStr(i)+'] Length: '+ToStr(Length(ATPA[i])));
SMART_DrawDotsEx(False, ATPA[i], clBlue);
B := GetTPABounds(ATPA[i]);
OffsetTPA(ATPA[i], Point(-B.X1, -B.Y1));
bmp := CreateBitmap(B.X2-B.X1+2, B.Y2-B.Y1+2);
DrawTPABitmap(bmp, ATPA[i], 255);
GetbitmapSize(bmp,w,h);
SetTargetBitmap(bmp);
for i := 0 to High(Item.Bitmaps) do
begin
FindDeformedBitmapToleranceIn(Item.Bitmaps[i], x, y, 0, 0, w-1, h-1, 0, 0, True, Acc);
Writeln('Acc: '+ToStr(Acc));
if Acc >= Item.BmpAcc then
begin
Result := True;
GetbitmapSize(Item.Bitmaps[i], w, h);
x := x+B.X1+(w/2);
y := y+B.Y1+(h/2);
BmpNum := i;
Break;
end;
end;
if Result then
Break;
end;
SetImageTarget(Target);
if bmp <> 0 then
FreeBitmap(bmp);
end;
Procedure LoadColorArrays;
begin
SetLength(TPAItems, 30);
Mask_Ore := BitmapFromString(14, 18, 'meJxjYICD/9gQVkBrlfgVEATEWI' +
'fLecSrJMnLWBXjUompGI/K/+Said9TWDViqiTG2bj04gK0UwkFALE' +
'LeYc=');
Mask_Bar := BitmapFromString(28, 16, 'meJxjYMAF/lOAqG4gVjMpNBDTTM' +
'oN/E8DA/+PGkjteKFdIqfEcJIA1Q0kbDgTBSbiMJ+KgOoGMhBjIAB' +
'KeAsG');
with TPAItems[bmp_Ore_Iron] do
begin
Tolerance := 4;
Color := 1317678;
CountHi := 150;
CountLow := 130;
Hue := 0.20;
Sat := 0.37;
Bitmaps := [Mask_Ore];
BmpAcc := 0.85;
end;
with TPAItems[bmp_Ore_Coal] do
begin
Tolerance := 4;
Color := 1515295;
CountHi := 145;
CountLow := 100;
Hue := 0.00;
Sat := 0.74;
Bitmaps := [Mask_Ore];
BmpAcc := 0.85;
end;
with TPAItems[bmp_Bar_Steel] do
begin
Tolerance := 15;
Color := 6053216;
CountHi := 350;
CountLow := 150;
Hue := 0.28;
Sat := 0.03;
Bitmaps := [Mask_Bar];
BmpAcc := 0.85;
end;
with TPAItems[bmp_Ore_Tin] do
begin
Tolerance := 15;
Color := 6053216;
CountHi := 150;
CountLow := 100;
Hue := 0.28;
Sat := 0.03;
Bitmaps := [Mask_Ore];
BmpAcc := 0.85;
end;
with TPAItems[bmp_Bar_Gold] do
begin
Tolerance := 16;
Color := 1473692;
CountHi := 350;
CountLow := 150;
Hue := 0.01;
Sat := 0.09;
Bitmaps := [Mask_Bar];
BmpAcc := 0.85;
end;
end;
var
i, BmpNum: integer;
T: TPoint;
begin
Smart_Server := 1;
Smart_Members:= true;
Smart_Signed := true;
Smart_SuperDetail := false;
SetupSRL;
LoadColorArrays;
SMART_ClearCanvas;
{This looks through Inventory}
for i := 1 to 28 do
if FindTPA2Item(T.x, T.y, BmpNum, TPAItems[bmp_Bar_Gold], InvBox(i)) then
begin
Writeln('Object found - Inv: '+ToStr(i)+' - MidPoint'+ToStr(T)+' BmpNum: '+ToStr(BmpNum));
SMART_DrawDot(False, T, clRed);
end;
{This looks on MS}
if FindTPA2Item(T.x, T.y, BmpNum, TPAItems[bmp_Bar_Gold], MSBox) then
begin
Writeln('Object found - MidPoint'+ToStr(T)+' BmpNum: '+ToStr(BmpNum));
SMART_DrawDot(False, T, clRed);
end;
end.