SRL Archive - MSI Suggestions

MSI_FindTool


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:

Sir R. M8gic1an

2009-11-13 04:59:31

it looks really good except for one thing


if EndsWith('ickaxe', ToolMaterial.Name) then
LengthCheck := Length(ToolMaterial.Colors)
else
LengthCheck := 10;
FindColorsTolerance(ColorsArr, ToolMaterial.Colors[I], X1, Y1, X2, Y2, ToolMaterial.Tol);

{ Compares the ColorsArr length depending on the tool type. }
ColorCheck := Length(ColorsArr) >= LengthCheck;

Meaning that if we give the Pickaxe TItem only one color, and it finds that one color in the inv/equpped tab, (even if it finds just one pixel), it will return true. You sure this bit is accurate enough?

Honestly I'd search for color and if found confirm it with the DTM ;)

~RM

Coh3n

2009-11-13 11:10:50

From: Rasta Magician
Meaning that if we give the Pickaxe TItem only one color, and it finds that one color in the inv/equpped tab, (even if it finds just one pixel), it will return true. You sure this bit is accurate enough?

Honestly I'd search for color and if found confirm it with the DTM ;)


I know what you mean. I didn't really know what to do here because the pickaxe colors are so close many other colors. When I picked the colors for the records, I picked the lightest colors on the pickaxe (there are only one or two anyway) because if I picked any of the darker colors, it would find basically every part of the inventory.

I edited the first post with what I came up with (with a little help from Naum ;)). I just commented out everything I used for debugging, let me know if you think I should get rid of it before I commit. Also, I was thinking about a procedure in Debug.scar (something like MSI_Successful). Something that will come up if the MSI procedure is successful. Not sure if that's a good idea, or if it can be done with the MSIDebug procedure. Let me know what you think.

Coh3n

Sir R. M8gic1an

2009-11-14 06:39:17

MSIDebug('MSI_FindTool', 'succesful', Debug_Functions); ;)


if FindColorsTolerance(ColorsArr, ToolMaterial.Colors[I], X1, Y1, X2, Y2, ToolMaterial.Tol) then
begin
{ Writeln('ColorsArr: ' + IntToStr(Length(ColorsArr)) + '.'); }

MiddleTPAEx(ColorsArr, MIDX, MIDY);

you need to SplitTPA / TPAToATPA before middleing TPA, otherise you might find few items and end up aiming completly for the wrong place.

~RM

Coh3n

2009-11-14 10:37:32

Ah, I knew I was missing something. I was thinking about that exact scenario last night. :tongue: