Coh3n
2009-11-12 14:46:24
MSI_FindTool(ToolMaterial: TItem);
I've come up with the final version. I think it works really well, and can easily be edited for further tools.
{*******************************************************************************}
{ function MSI_FindTool(ToolMaterial: TItem): Boolean; }
{ By: Coh3n }
{ Rev: 25 }
{ Date: 12 Nov 09 }
{ Description: Finds the specified tool when equipped or when in the inventory. }
{*******************************************************************************}
function MSI_FindTool(ToolMaterial: TItem): Boolean;
var
SearchLocation: TIntegerArray;
ColorsArr: TPointArray;
I, II, H, X, Y, X1, X2, Y1, Y2, MIDX, MIDY, Tol: Integer;
CheckDTM, FoundBitmap, FoundDTM: Boolean;
begin
if not LoggedIn then Exit;
SearchLocation := [tab_Inv, tab_Equip];
{ Checks both the inventory and equipment tab. }
for II := 0 to 1 do
begin
GameTab(SearchLocation[II]);
if II = 0 then
begin
{ Edited MI Coords }
X1 := 550; X2 := 735;
Y1 := 209; Y2 := 459;
end else begin
{ Weapon Equipment Slot }
X1 := 570; X2 := 602;
Y1 := 289; Y2 := 322;
end;
{ Loops through the item's color record array. }
H := High(ToolMaterial.Colors);
for I := 0 to H do
if FindColorsTolerance(ColorsArr, ToolMaterial.Colors[I], X1, Y1, X2, Y2, ToolMaterial.Tol) then
begin
{ Writeln('ColorsArr: ' + IntToStr(Length(ColorsArr)) + '.'); }
MiddleTPAEx(ColorsArr, MIDX, MIDY);
{ Writeln('Middle point: (' + IntToStr(MIDX) + ', ' + IntToStr(MIDY) + ').');
DebugTPA(ColorsArr, ''); }
{ Look for the DTM in a 50 x 50 box around the middle color of the ColorsArr. }
FoundDTM := FindDTM(ToolMaterial.DTM, X, Y, MIDX - 25, MIDY - 25, MIDX + 25, MIDY + 25);
if FoundDTM then
Break;
{ begin
Writeln('Found DTM in 50 x 50 box.');
Break;
end else
Writeln('Couldn''t find DTM in 50 x 50 box.'); }
end;
{ Checks for bitmap, only if color method fails. }
if not FoundDTM then
begin
Tol := 0;
repeat
FoundBitmap := FindBitmapToleranceIn(ToolMaterial.BMP, X, Y, X1, Y1, X2, Y2, Tol);
IncEx(Tol, 2);
until((Tol >= 20) or FoundBitmap);
{ if FoundBitmap then
Writeln('Found Bitmap.')
else
Writeln('Couldn''t find Bitmap.'); }
end;
{ Checks for DTM, only if bitmap and color finding fails. }
if not FoundBitmap and not FoundDTM then
begin
CheckDTM := FindDTM(ToolMaterial.DTM, X, Y, X1, Y1, X2, Y2);
{ if CheckDTM then
Writeln('Found DTM.')
else
Writeln('Couldn''t find DTM.'); }
end;
Result := FoundDTM or FoundBitmap or CheckDTM;
if Result then
begin
Writeln('Found ' + ToolMaterial.Name + '.');
Break;
end;
end; { of GameTab for..to..do loop. }
FreeBitmap(ToolMaterial.BMP);
FreeDTM(ToolMaterial.DTM);
end;
:biggrin: