Results 1 to 15 of 15

Thread: DTMs closest to center screen

  1. #1
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default DTMs closest to center screen

    Is there a simple bit of code already out there that finds the DTM nearest to the center of MS?

    Thanks in advance.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  2. #2
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    MSCX and MSCY are the main screen points.

    Search around there.

  3. #3
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Yes, but the 'searching' is what I'm asking about. I guess since no one's posted anything then no such code exists.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  4. #4
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default

    Simba Code:
    {***
    function GetClosestDTM(DTMs: TIntegerArray; SearchBox: TBox; P: TPoint; var ResultPoint: TPoint): Boolean;
    By: TomTuff
    Desc: Finds all the DTMs in the TIA within the SearchBox, then finds the closest one
    to point "P". Point is stored in ResultPoint as well.
    ***}

    function GetClosestDTM(DTMs: TIntegerArray; SearchBox: TBox; P: TPoint; var ResultPoint: TPoint): Boolean;
    var
      ATPA: T2DPointArray;
      i: Integer;
      TPA: TPointArray;
    begin
      SetLength(ATPA, Length(DTMs));
      for i := 0 to High(DTMs) do
        FindDTMs(DTMs[i], ATPA[i], SearchBox.X1, SearchBox.Y1, SearchBox.X2, SearchBox.X2);
      Result := (Length(TPA) > 0);
      if not(Result) then
        Exit;
      TPA := MergeATPA(ATPA);
      SortTPAFrom(TPA, P);
      ResultPoint := TPA[0];
    end;

    Use as you wish

  5. #5
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    What I would do would be just use a for loop. After each iteration, just increase .x2 and .y2 by ten, and decrease .x1 and .y1 by ten, until your search area is too big or whatever.

    I think there's a better way to do it but whatever.

  6. #6
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    P (TPoint) would be the center of your search box, or do we leave that bank to get defined later in the function?

    Looks awesome by the way, I really appreciate it. I'll test it in a while and see what I come up with.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  7. #7
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default

    Quote Originally Posted by Flight View Post
    P (TPoint) would be the center of your search box, or do we leave that bank to get defined later in the function?

    Looks awesome by the way, I really appreciate it. I'll test it in a while and see what I come up with.
    It's whatever point to find the closest point to, so it doesn't have to be the middle.

  8. #8
    Join Date
    Oct 2006
    Posts
    1,190
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    i would use the tpoint of the middle of the screen, create an array of DTMs then sort by length and go from there, i would handle it the same as searching for TPAs

    sorry i didnt post any code, but i dont see how that wont work



  9. #9
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default

    Quote Originally Posted by Bonfield View Post
    i would use the tpoint of the middle of the screen, create an array of DTMs then sort by length and go from there, i would handle it the same as searching for TPAs

    sorry i didnt post any code, but i dont see how that wont work
    You mean like what i did?

  10. #10
    Join Date
    Oct 2006
    Posts
    1,190
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    yeah, i skimmed over it cant really make sense of it looking on an iphone =]



  11. #11
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Wouldn't you need to free the DTMs within this procedure?

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  12. #12
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default

    Quote Originally Posted by Flight View Post
    Wouldn't you need to free the DTMs within this procedure?
    the DTM's are loaded externally from the Function so would there be any reason to free them internally?

  13. #13
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default

    Quote Originally Posted by pur3b100d View Post
    the DTM's are loaded externally from the Function so would there be any reason to free them internally?
    Yeah what he said

    Simba Code:
    function Example: boolean;
    var
      DTMa, DTMb: Integer;
    begin
      DTMa := ...
      DTMb := ...
      FindClosestDTM
      FreeDTM(DTMa);
      FreeDTM(DTMb);
    end;
    Last edited by TomTuff; 04-20-2011 at 06:07 PM.

  14. #14
    Join Date
    Sep 2007
    Location
    Michigan
    Posts
    3,862
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    I'd keep the DTMs as a global declaration anyways if you use them a lot.
    (Scripts outdated until I update for new SRL changes)
    AK Smelter & Crafter [SRL-Stats] - Fast Fighter [TUT] [SRL-Stats]
    If you PM me with a stupid question or one listed in FAQ I will NOT respond. -Narcle
    Summer = me busy, won't be around much.

  15. #15
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Ok, I'll declare the DTMs globally and free them within the function that calls this. Thanks guys, and rep for you TomTuff.

    I think just one more question. How are you grabbing the point, or even the x/y of the result point, from your function? I've tried this:

    Here's your function that I modified:

    Simba Code:
    Function GetClosestDTM(DTMs: TIntegerArray): Boolean;
    Var
      i: Integer;
      TPA: TPointArray;
      ResultPoint: TPoint;
      ATPA: T2DPointArray;
    begin
      SetLength(ATPA, Length(DTMs));
      for i := 0 to High(DTMs) do
        FindDTMs(DTMs[i], ATPA[i], MSX1, MSY1, MSX2, MSY2);
      Result := (Length(TPA) > 0);
      if not(Result) then
        Exit;
      TPA := MergeATPA(ATPA);
      SortTPAFrom(TPA, Point(MSCX,MSCY));
      ResultPoint := TPA[0];
    end;

    And in another function, I tried to use this to deprive the X/Y from that:

    Simba Code:
    X := GetClosestDTM(RockDTM).ResultPoint.x;
          Y := GetClosestDTM(RockDTM).ResultPoint.y;

    Edit: Even tried getting the ResultPoint itself, then drawing the x/y from the point, but I keep getting compile errors and it's beyond me why it doesn't work. It's probably a really simple mistake and I'm sure I'll feel really stupid when someone answers it.

    Edit2: Nevermind, I did changed the result type that your function outputs and grabbed the point from it, then deprived the x/y from the result's point. I'll test it to see if it works now.
    Last edited by Flight; 04-21-2011 at 03:49 AM.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


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
  •