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).
<-- 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).