PDA

View Full Version : FindPartialDDTM



mixster
01-28-2008, 09:49 PM
After (trying) to use a DTM to do walking in the crafting guild, I soon realised it would be near impossible because of the constantly moving symbols. To get over this, I started working on a function that could interpret setup DDTM data and then run each subpoint on its own with a mainpoint, then seeing if it can find it. At the moment I haven't tested it very thoroughly, but I'm (fairly) sure it should work for themost part.

<-- This post has been edited from here onwards -->

Function FindPartialDDTM(MainPoint: TDTMPointDef; SubPoints: Array of TDTMPointDef; Var x,y: Integer; x1,y1,x2,y2: Integer): Boolean;
Var
DDTMSkeleton: TDTM;
DTM,i,storeTol: Integer;
time: Integer;
ia: Array[0..0] of Integer;
foundAngle: Extended;

Begin
DDTMSkeleton.MainPoint := MainPoint;
DDTMSkeleton.SubPoints := SubPoints;
DTM:= AddDTM(DDTMSkeleton);
If(FindDTMRotated(DTM,x,y,x1,y1,x2,y2,-PI*2,PI*2,0.5,foundAngle)) Then
Begin
Result:= True;
FreeDTM(DTM);
// Writeln('Yay, DTM found with all points');
Exit;
End
Else
Begin
FreeDTM(DTM);
// Writeln('DTM not found with all points');
End;
For i:= 0 to (GetArrayLength(SubPoints)-1) do
Begin
storeTol:= SubPoints[i].Tolerance;
// Writeln('Stored tolerance');
SubPoints[i].Tolerance:= 999;
// Writeln('Maxed tolerance on point '+IntToStr(i));
DDTMSkeleton.MainPoint := MainPoint;
DDTMSkeleton.SubPoints := SubPoints;
DTM:= AddDTM(DDTMSkeleton);
// Writeln('Assembled DDTM');
If(FindDTMRotated(DTM,x,y,x1,y1,x2,y2,-PI*2,PI*2,0.5,foundAngle)) Then
Begin
Result:= True;
FreeDTM(DTM);
// Writeln('Found DTM - Point '+IntToStr(i)+' was not used');
Exit;
End
Else
Begin
FreeDTM(DTM);
// Writeln('DTM was not found when not using point '+IntToStr(i));
End;
SubPoints[i].Tolerance:= storeTol;
// Writeln('Restored tolerance of point '+IntToStr(i));
End;
End;


The function works just like FindDTM, except it uses DDTM variables/ array of variable. At the moment, it only works if there's 1 missing point. It wokrs by changing the tolerance of a point to 999 then seraching for the DTM. If it finds it, it exits, otherwise it restores the previous tolerance and goes onto the next point. If people find it useful/ demand increases, I may change it to export other variables and add more changeable options (though it's easy enough to do yourself). Also, it still has all my writeln's in it (commented out), so you can uncomment them if you want a detail of what it's doing when it's running.

Lastly, as an example:

MainPointS.x:= 53;
MainPointS.y:= 38;
MainPointS.areasize:= 0;
MainPointS.areashape:= 0;
MainPointS.color:= 10525679;
MainPointS.tolerance:= 255;

SubPointsS[0].x:= 32;
SubPointsS[0].y:= 28;
SubPointsS[0].areasize:= 0;
SubPointsS[0].areashape:= 0;
SubPointsS[0].color:= 10525679;
SubPointsS[0].tolerance:= 5;

SubPointsS[1].x:= 31;
SubPointsS[1].y:= 53;
SubPointsS[1].areasize:= 0;
SubPointsS[1].areashape:= 0;
SubPointsS[1].color:= 1514015;
SubPointsS[1].tolerance:= 5;

SubPointsS[2].x:= 34;
SubPointsS[2].y:= 73;
SubPointsS[2].areasize:= 0;
SubPointsS[2].areashape:= 0;
SubPointsS[2].color:= 1514015;
SubPointsS[2].tolerance:= 5;

SubPointsS[3].x:= 14;
SubPointsS[3].y:= 48;
SubPointsS[3].areasize:= 0;
SubPointsS[3].areashape:= 0;
SubPointsS[3].color:= 1514015;
SubPointsS[3].tolerance:= 5;

SubPointsS[4].x:= 66;
SubPointsS[4].y:= 24;
SubPointsS[4].areasize:= 0;
SubPointsS[4].areashape:= 0;
SubPointsS[4].color:= 10525679;
SubPointsS[4].tolerance:= 5;

If(FindPartialDDTM(x,y,MainPointS,SubPointsS,0,0,6 00,350)) Then
Begin
Writeln('yay');
MoveMouse(x,y);
End;

Which should write 'Yay' and move the mouse just to the right of the middle when it finds the attatched bmp (tested it by loading it into the DTM editor and moving it to the top left).

Negaal
01-28-2008, 10:14 PM
Dude, is you name Ben?

...


So basically it finds DTM <toMatch> times?, I really cant understand what did you made? FindDTMRotated works well for me :D

mixster
01-29-2008, 07:43 AM
Naw, my name is Michael.
But anyway, what it does is if it matches 'toMatch' of the subpoints for a DDTM, then it returns true - useful when you have mapwalking that involved DTM/DDTM's, but sometimes an annoying symbol pops up over a point.
The only problem I can think of coming up is that it matches each DDTM subpoint to different points, but as I said, I haven't tested it extensively yet, so not sure if that's the case.

n3ss3s
01-29-2008, 01:15 PM
Dude, is you name Ben?


...?


Good job, maybe you should make it return the DTM that was found, I mean save the i in the found dtms to an integer array, and then create a new DTM with those subpoints? :)

mixster
01-29-2008, 04:10 PM
I'll try adding that into the next version, though making sure it works 100% wil come first. Also, on a side note, aren't D/DTM's just a quick way of doing multiple Findcolor/Tolerance's and returning true if they all return true? Ahwell, if the DDTM way doesn't work out, I'll go to finding colours (though rotating points could cause me some problems ><)

n3ss3s
01-29-2008, 04:17 PM
Quite - but not, a DTM is found if the points are in certain angle and distance from eachother, around the MainPoint.

DDTM is just a different way of making a DTM.

Markus
01-29-2008, 04:18 PM
DTMSkel = TDTMPointDef?

Negaal
01-29-2008, 05:15 PM
Dude, is you name Ben?


BenLand100, Benleegt...I bet wizzy's real name starts with Ben aswell...;)
Auto memberize this guy?!:p


Kidding, he still needs to apply...

There hasn't been such smart registered dude long time, I'v seen all your functions...Quite feeling you know more than pascal/delphi...?

Edit:
And as Markus mentioned above, TDTMPointDef is wrong, it needs to be TDTM

mixster
01-29-2008, 05:35 PM
I just know php and html outside of scar (still then it's fairly basic). I've got a knack of picking things up and a good logical mind for solving problems.
DTMSkel is just TDTMPointDef as a separate type as I wasn't sure whether it would work with TDTMPointDef's (made it late at night and just wanted to get it generally working) so this way was quicker than making it and finding it didn't work. Also, there's TDTM inside the function Negaal and it does compile/find the DDTM, so that isn't a problem.
However, the problem is that after adding a bit more debugging stuff to it, I've discovered it finds the individual DTM's with different mainpoints/locations, so it's pretty much failed. Now I have to look into making a FindColor based DTM duplicate :(

Edit: Made a first draft FindColorFromDDTM function - only problem is it runs very slow (at the moment, about 10 seconds per 200 by 25 pixels) and doesn't actually work very well. Ahwell, I'll get there eventually, even if I have to learn Delphi just to make it run quickly!

mixster
02-01-2008, 07:03 PM
Sorry for the double post, but I have just about rewrote the entire function (now works correctly, though only drops 1 point at most - will raise the amount possible with next release) and wanted people to know. Check my 1st post for the script etc.

footballjds
02-01-2008, 07:36 PM
VERY nice!!!!!!!!!!!!!!!! :D
you := brilliant :D

Naum
02-01-2008, 08:21 PM
Nice you have more skills than me i think...

mixster
02-01-2008, 08:30 PM
I wouldn't go that far. At the moment, all it is is a 'For' loop that changes which point to change for the DDTM, then after it changes it, it puts the DDTM together and sees if it can find it. The next 'version' will allow different amounts of points to be matched (e.g. If you have a 12 point DDTM, then you can decide that as long as it has a minimum of 9 matching points, it's O.K). I also want to add an auto-tolerance, where you just input an extra number, and it starts at 0 and increases the tolerance in that number before progressing.

n3ss3s
02-01-2008, 09:28 PM
255 is the max tol, no need for 999.

Why do you want to find any color? (255 finds any color)

mixster
02-01-2008, 09:34 PM
I was trying with 255, but for some reason it wasn't working. When I changed it to 999, it worked, so I just left it at that.
I set it to find any color (only does it to 1 point), because the reason for it is that it looks for a DDTM without 1 of the points in case it isn't visible (developed it for mapwalking in the crafting guild where there's way too many symbols).

Markus
02-01-2008, 09:36 PM
422 finds any colour, 255 doesn't.