Results 1 to 16 of 16

Thread: FindPartialDDTM

  1. #1
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default FindPartialDDTM

    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 -->
    SCAR Code:
    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:
    SCAR Code:
    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,600,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).

  2. #2
    Join Date
    Jul 2007
    Posts
    1,431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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
    [CENTER][SIZE="4"]Inactive[/SIZE]I forgot my password[/CENTER]

  3. #3
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    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.

  4. #4
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    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?

  5. #5
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

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

  6. #6
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    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.

  7. #7
    Join Date
    Feb 2007
    Location
    Het ademt zwaar en moedeloos vannacht.
    Posts
    7,211
    Mentioned
    26 Post(s)
    Quoted
    72 Post(s)

    Default

    DTMSkel = TDTMPointDef?
    I made a new script, check it out!.

  8. #8
    Join Date
    Jul 2007
    Posts
    1,431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by n3ss3s View Post
    Dude, is you name Ben?
    BenLand100, Benleegt...I bet wizzy's real name starts with Ben aswell...
    Auto memberize this guy?!


    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
    [CENTER][SIZE="4"]Inactive[/SIZE]I forgot my password[/CENTER]

  9. #9
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    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!

  10. #10
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    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.

  11. #11
    Join Date
    Feb 2007
    Location
    PA, USA
    Posts
    5,240
    Mentioned
    36 Post(s)
    Quoted
    496 Post(s)

    Default

    VERY nice!!!!!!!!!!!!!!!!
    you := brilliant

  12. #12
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Nice you have more skills than me i think...

  13. #13
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    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.

  14. #14
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    255 is the max tol, no need for 999.

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

  15. #15
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

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

  16. #16
    Join Date
    Feb 2007
    Location
    Het ademt zwaar en moedeloos vannacht.
    Posts
    7,211
    Mentioned
    26 Post(s)
    Quoted
    72 Post(s)

    Default

    422 finds any colour, 255 doesn't.
    I made a new script, check it out!.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •