SRL Archive - MSI Suggestions

MSI_FindObj(Obj: TItem): TPoint;


NCDS

2009-11-15 09:19:55

Made a few changes. Still plan to add some more debug and work on a more accurate way of being 100% positive we have the correct object before we move the mouse.

Still, any suggestions are openly welcome :)


{*******************************************************************************}
{ function MSI_FindMSObj(Obj: TMSObj; var x, y: Integer; Action: fnct_ActionOptions): Boolean; }
{ By: NCDS }
{ Rev: 25 }
{ Date: 12 Nov 09 }
{ Description: Searches for Obj specified by TMSObj record. }
{ Returns x and y values.
{ Valid Arguments for 'Action': Nothing. ClickRight. ClickLeft. Move.
{*******************************************************************************}
function MSI_FindMSObj(Obj: TMSObj; var x, y: Integer; Action: fnct_ActionOptions): Boolean;
var
cArr: array of TPoint; i, ii, Tol: Integer; Fail, N, Bool: Boolean;
atpa: T2DPointArray;
begin
if not LoggedIn then Exit;
Tol := 0;
// Set bool for mouse click
if Action = ClickRight then
Bool := False;

// 3 attempts for a succesful result.
for i := 0 to 2 do
begin
Fail := False;

// Loop through Color array.
for ii := 0 to High(Obj.Colors) do
begin
FindColorsSpiralTolerance(
MSCx, MSCy,
cArr, Obj.Colors[ii],
MSx1, MSy1, MSx2, MSy2,
Tol
);

// Check if Color is found.
if Length(cArr) > 3 then
begin
MSIDebug('MSI_FindMSObj', 'Length(cArr) = '+IntToStr(Length(cArr))+';', {number});
Break;
end;
if ii = High(Obj.Colors) then
begin
Fail := True;
IncEx(Tol, 2);
Break;
end;
end;

if Fail then
Continue;

// Convert to T2DPointArray.
atpa := TPAToATPAEx(cArr, Obj.w, Obj.h);
// Sort atpa to search closest points first.
SortATPAFrom(atpa, Point(MSCx, MSCy));

case Action of
Nothing : N := True;
ClickLeft,
ClickRight,
Move :
for ii := 0 to High(atpa) do
begin
MMouse(atpa[ii].x, atpa[ii].y, 2, 2);
Wait(RandomRange(200, 500));
if Action = Move then Break;
if IsUpTextMultiCustom(Obj.UpTexts) then
begin
GetMousePos(x, y);
Mouse(x, y, 0, 0, bool);
end;
end;
end;
end;// of 3 attempt loop.

if N or x > 0 or y > 0 then
begin
Result := True;
MSIDebug('MSI_FindMSObj', 'Successful.', {number});
end else
MSIDebug('MSI_FindMSObj', 'Failed.', {number});
end;

Coh3n

2009-11-15 10:51:22

Alright, I'll give you some feedback. :biggrin:

There's a type (TMSObj) in Globals.scar that would better fit this situation than TItem. ;) Using this type, we can use CTS(2). I'm guessing this function is meant to be used for finding rocks and trees in which case I don't think we should even bother using bitmaps/DTMs at all. If anything, we should use FindColorsSpiralTolerance, like you have, and then a simple FindObj function for a failsafe.

Also, I think an 'Action' option is a great idea. Whether to right/left click, just check the uptext, or do nothing, etc. It'll be different for all types of objects.

Once again, I forgot about when you suggestion having the Objects.scar function return a TPoint. I think this could go both ways, and I may have an idea to make it work. It's pretty simple actually. We can make it work like SCAR's finding bitmaps/DTMs/colors functions. Have the function return a boolean, but store the coords in parameters x and y. This way if we simply want to check for the object, we can. And if we want to interact with the object, we can.

Hopefully that makes sense, lol. Let me know what you think,

Coh3n

NCDS

2009-11-15 10:57:12

Actually this one was meant for searching Inventory, that's why I have DTM and bmp searches. I forgot all about TMSObj, must be a side effect of having no MSI folder >.< I'm still working on fixing that.

I will take care of that "Action" param then as well :)

and I like the idea to just store x and y's and still have the function return a boolean. I don't really know why I never did that before.

I'll update here once I update the function.

marpis

2009-11-15 11:17:25

It should actually be MSI_FindItem, I think.


FindColorsSpiralTolerance(x, y, cArr, Obj.Colors, MIx1, MIy1, MIx2,
MIy2, Obj.Tol);
Isn't Colors a TIntegerArray?

NCDS

2009-11-15 11:19:25

Both will be fixed when I post the full function ;)

Coh3n

2009-11-15 11:30:04

From: NCDS
Actually this one was meant for searching Inventory, that's why I have DTM and bmp searches. I forgot all about TMSObj, must be a side effect of having no MSI folder >.< I'm still working on fixing that.

I will take care of that "Action" param then as well :)

and I like the idea to just store x and y's and still have the function return a boolean. I don't really know why I never did that before.

I'll update here once I update the function.

Awesome! And MSI_FindTool is the function meant to find items in the inventory. It's not necessarily just for tools, it can be for whichever item we have a record for. :smile:

Also, I e-mailed you the MSI folder as an attachment, did you not get it?

NCDS

2009-11-15 11:35:11

From: Coh3n
Awesome! And MSI_FindTool is the function meant to find items in the inventory. It's not necessarily just for tools, it can be for whichever item we have a record for. :smile:

Also, I e-mailed you the MSI folder as an attachment, did you not get it?


I rarely check my email, but I will now thank you :)

and in that case, awesome! :) I will have the TMSObj function posted shortly!

NCDS

2009-11-15 22:24:00

Check out first post.

Sir R. M8gic1an

2009-11-15 22:35:04


const
DoNothing = 0;
LeftClick = 1;
RightClick = 2;

No Hardcoded values!

~RM

Coh3n

2009-11-15 23:53:10

From: marpis
It should actually be MSI_FindItem, I think.

I think MSI_FindObject would be a better fit. ;)

if Nothing or x <> 0 or y <> 0 then
I doubt this matters at all, but the values of x and y should never be negative, so you can just say x > 0 or y > 0.

I would also suggesting using a WaitUpText function, in case of possible lag.

I also think you should add in more MSI_Debug functions. The more we have, the easier our jobs will be when MSI gets huge. I mean debug if the color is found or not, the length of the color, whether uptext is found or not, etc. After Narcle's explanation on one of the other threads, I'm all for it, how about you guys?

NCDS

2009-11-16 06:38:04

Sounds good to me. after work I will fix it up a bit.

NCDS

2009-11-21 18:04:07

Check first post

Sir R. M8gic1an

2009-11-22 05:57:46

when it right clicks it'll never choose the option…. maybe add that in?

if not bool then ChooseOption()…. after the right click?

~RM

NCDS

2009-11-22 08:46:41

From: Rasta Magician
when it right clicks it'll never choose the option…. maybe add that in?

if not bool then ChooseOption()…. after the right click?

~RM


Yeah I thought about that and if it should be left up to the user, but I can add it in no problem.

Coh3n

2009-11-22 12:17:17

I hate to be the guy that brings down anyone's work, but what about SmartColors? By the looks of things, wouldn't that be the best way to find objects? Or are we trying to keep it unique for MSI?

NCDS

2009-11-22 19:40:50

From: Coh3n
I hate to be the guy that brings down anyone's work, but what about SmartColors? By the looks of things, wouldn't that be the best way to find objects? Or are we trying to keep it unique for MSI?


I thought about this as well, just haven't had a chance to discuss it with anyone yet.

Whats everyone else's opinions on this? It would make Objects.scar quite simple, but effective.

Coh3n

2009-11-22 19:48:53

The simpler the better. We could still use Objects.scar a lot. We could use a case to create the object and then use SmartColors for that object. Wouldn't be difficult at all, and it would work really well.

NCDS

2009-11-22 21:02:33

anyone else have any opinions on this? I'm all for it.

Coh3n

2009-11-23 10:38:27

Actually, we wouldn't even need a case for each one, it could be a 2 or 3 line function. Someones like this would probably work:

function MSI_FindObject(Obj: TMSObj): Boolean;
I, H: Integer;
begin
H := High(Obj.Colors)
for I := 0 to H do
begin
MakeObj(Obj.Name, Obj.Color[I], Obj.Tol, Obj.Hue, Obj.Sat, Obj.UpText, Obj.Options); // We would have to add Option to the TMSObj record.
SetupSmartColorsDetails( { if we wanted to go with the advanced method } );

Result := SmartColors(Obj.Name);

if Result then
Break;
end;
end;

Also, if we wanted to use the advanced method, we would have to add to the TMSObj record, but that's not a big deal.