Results 1 to 3 of 3

Thread: ATPA from TPA

  1. #1
    Join Date
    Jul 2008
    Location
    California
    Posts
    255
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default ATPA from TPA

    I'm relatively new to using TPA's and ATPA's and I was wondering how I can improve this procedure. The point of the procedure is to find groups of TPoints within a TPA, and sort those groups into an ATPA.

    I'm writing this because I'm creating a hybrid auto-fighter, and I need a way of detecting each of the monsters, preferably using color.

    Code:
    procedure FindObjInTPA(SearchTPA : TPointArray; var Objs : T2dPointArray);
    var
      i, j, k, STL, OATL, OTL : Integer;
      Temp : Boolean;
    begin
      if GetArrayLength(SearchTPA) > 0 then
      begin
        SetArrayLength(Objs, 1);  //Set initial condition for Objs ATPA
        SetArrayLength(Objs[0], 1); //^^
        Objs[0][0] := SearchTPA[0]; //^^
    
        STL := High(SearchTPA);
        for i := 1 to STL do // For all TPoints in SearchTPA
        begin
          Temp := False;
          OATL := High(Objs);
          //***Find out if SearchTPA[i] is near any TPoint in Objs***
          for j := 0 to OATL do // For all TPAs in Objs
          begin
            OTL := High(Objs[j])
            for k := 0 to OTL do // For all Points in Objs[k]
            begin
              if Distance(SearchTPA[i].x, SearchTPA[i].y, Objs[j][k].x, Objs[j][k].y) < 25 then //Find out if SearchTPA[i] is near any TPoint in Objs[k]
              begin
                SetArrayLength(Objs[j], GetArrayLength(Objs[j])+1);
                Objs[j][High(Objs[j])] := SearchTPA[i];
                Temp := True;
                //WriteLn('Break A');
                Break;
              end;
            end;
            if Temp then
            begin
              //WriteLn('Break B');
              Break;
            end;
          end;
          //***If SearchTPA[i] is not near a point in Objs[k] then increase size of***
          //***Objs and add SearchTPA[i] to the new TPA. ***
          if not Temp then
            begin
              SetArrayLength(Objs, GetArrayLength(Objs) + 1);
              WriteLn('Objs Length: ' + IntToStr(GetArrayLength(Objs)));
              SetArrayLength(Objs[High(Objs)], 1);
              Objs[High(Objs)][0] := SearchTPA[i];
            end;
        end;
      end;
    end;
    The procedure itself works, but it gets slow, and is inefficient. I want to speed up the process so that I can use this procedure to find all monsters in the screen using color and then check if each monster is in a fight and have it fight one that isn't in a fight.

    Even if I can't get it to be really fast that's okay because this will only be a backup option to reflection findings.

    Sorry it's so messy. This procedure is kicking my butt!

    Thanks in advance!
    ~DooM
    Unfortunately, no active scripts atm.

  2. #2
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    What about SplitTPA and all that? In wizzyplugin.
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  3. #3
    Join Date
    Jul 2008
    Location
    California
    Posts
    255
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Sex View Post
    What about SplitTPA and all that? In wizzyplugin.
    Oh my. I missed that one when I read through the wizzyplugin 0.o

    The ending result is almost exactly like mine only 100x faster!

    Thank you!
    Unfortunately, no active scripts atm.

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
  •