Results 1 to 15 of 15

Thread: Some TBox Functions

  1. #1
    Join Date
    Aug 2007
    Posts
    52
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Some TBox Functions

    Some TBox functions dan cardin requested.

    function OrderTBox(TBoxInput : TBox) : TBox;
    function CheckTBoxIntersection(TBox1, TBox2 : TBox) : boolean;
    function CollideTBoxs(TBox1, TBox2 : TBox) : TBox;

    SCAR Code:
    {*******************************************************************************
    function OrderTBox(TBoxInput : TBox) : TBox;
    By: Light
    Description: Orders a TBox so it's upper left point is (x1,y1) and it's lower
    right point is (x2,y1)
    *******************************************************************************}


    function OrderTBox(TBoxInput : TBox) : TBox;
    var returnTBox : TBox;
    begin
      if(TBoxInput.x1 < TBoxInput.x2)then
      begin
        returnTBox.x1 := TBoxInput.x1;
        returnTBox.x2 := TBoxInput.x2;
      end else
      begin
        returnTBox.x1 := TBoxInput.x2;
        returnTBox.x2 := TBoxInput.x1;
      end;
      if(TBoxInput.y1 < TBoxInput.y2)then
      begin
        returnTBox.y1 := TBoxInput.y1;
        returnTBox.y2 := TBoxInput.y2;
      end else
      begin
        returnTBox.y1 := TBoxInput.y2;
        returnTBox.y2 := TBoxInput.y1;
      end;
      Result := returnTBox;
    end;

    {*******************************************************************************
    function CheckTBoxIntersection(TBox1, TBox2 : TBox) : boolean;
    By: Light
    Description: Checks if two TBoxs intersect with an area. Two sides touching is
    not an intersection.
    *******************************************************************************}


    function CheckTBoxIntersection(TBox1, TBox2 : TBox) : boolean;
    var orderedTBox1, orderedTBox2 : TBox;
    begin
      orderedTBox1 := OrderTBox(TBox1);
      orderedTBox2 := OrderTBox(TBox2);
      if((orderedTBox1.x1 >= orderedTBox2.x2)OR(orderedTBox1.x2 <= orderedTBox2.x1)
      OR(orderedTBox1.y1 >= orderedTBox2.y2)OR(orderedTBox1.y2 <= orderedTBox2.y1))
      then
      begin
        Result := False;
      end else
      begin
        Result := True;
      end;
    end;

    {*******************************************************************************
    function CollideTBoxs(TBox1, TBox2 : TBox) : TBox;
    By: Light
    Description: Finds the TBox of intersection for two TBoxs. If there is no area
    of intersection, then the return TBoxs x1, y1, x2 and y2 are all set to 0.
    __________
    |        |
    |        |
    |       _|______
    |_______|_|     |
            |       |
            |       |
            |_______|

    *******************************************************************************}


    function CollideTBoxs(TBox1, TBox2 : TBox) : TBox;
    var returnTBox, orderedTBox1, orderedTBox2 : TBox;
    begin
      if(CheckTBoxIntersection(TBox1, TBox2))then
      begin
        orderedTBox1 := OrderTBox(TBox1);
        orderedTBox2 := OrderTBox(TBox2);
        if(orderedTBox1.x1 < orderedTBox2.x1)then
        begin
          returnTBox.x1 := orderedTBox2.x1;
        end else
        begin
          returnTBox.x1 := orderedTBox1.x1;
        end;
        if(orderedTBox1.y1 < orderedTBox2.y1)then
        begin
          returnTBox.y1 := orderedTBox2.y1;
        end else
        begin
          returnTBox.y1 := orderedTBox1.y1;
        end;
        if(orderedTBox1.x2 < orderedTBox2.x2)then
        begin
          returnTBox.x2 := orderedTBox1.x2;
        end else
        begin
          returnTBox.x2 := orderedTBox2.x2;
        end;
        if(orderedTBox1.y2 < orderedTBox2.y2)then
        begin
          returnTBox.y2 := orderedTBox1.y2;
        end else
        begin
          returnTBox.y2 := orderedTBox2.y2;
        end;
      end else
      begin
        returnTBox.x1 := 0;
        returnTBox.y1 := 0;
        returnTBox.x2 := 0;
        returnTBox.y2 := 0;
      end;
      Result := returnTBox;
    end;
    Quote Originally Posted by Boreas View Post
    I think of my players as secret agents, that I send out into the field to be invisible. I properly train them to blend in and not die.

    It's my fantasy game within the fantasy game.

  2. #2
    Join Date
    Apr 2007
    Posts
    3,152
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    why thanks!
    SCAR Tutorials: The Form Tutorial | Types, Arrays, and Classes
    Programming Projects: NotePad | Tetris | Chess


  3. #3
    Join Date
    Jan 2007
    Location
    USA
    Posts
    1,782
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    pretty nice. have you thought about applying to members?

    most nonmembers dont even understand tbox, much less make functions like these

    Join the fastest growing merchanting clan on the the net!

  4. #4
    Join Date
    Aug 2007
    Posts
    52
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks pwnaz0r! I think I need to make a full script first (correct me if I'm wrong). I'm in the process of creating my first full script, which will also go into my member application.

    Hopefully I can get your vote when I do apply
    Quote Originally Posted by Boreas View Post
    I think of my players as secret agents, that I send out into the field to be invisible. I properly train them to blend in and not die.

    It's my fantasy game within the fantasy game.

  5. #5
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by pwnaz0r View Post
    pretty nice. have you thought about applying to members?

    most nonmembers dont even understand tbox, much less make functions like these
    Applying for member with 3 functions, doesn't get you in..
    Verrekte Koekwous

  6. #6
    Join Date
    Jan 2007
    Location
    USA
    Posts
    1,782
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by mastaraymond View Post
    Applying for member with 3 functions, doesn't get you in..
    Point being? I didnt say apply with the three functions

    Join the fastest growing merchanting clan on the the net!

  7. #7
    Join Date
    Jan 2007
    Location
    Kansas
    Posts
    3,760
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    Very nice.


  8. #8
    Join Date
    Apr 2007
    Location
    California
    Posts
    259
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Looks awesome, but you don't have to create a TBox to store each result into. Like, you can do this:
    SCAR Code:
    function OrderTBox(TBoxInput : TBox) : TBox;
    begin
      if(TBoxInput.x1 < TBoxInput.x2)then
      begin
        result.x1 := TBoxInput.x1;
        result.x2 := TBoxInput.x2;
      end else
      begin
        result.x1 := TBoxInput.x2;
        result.x2 := TBoxInput.x1;
      end;
      if(TBoxInput.y1 < TBoxInput.y2)then
      begin
        result.y1 := TBoxInput.y1;
        result.y2 := TBoxInput.y2;
      end else
      begin
        result.y1 := TBoxInput.y2;
        result.y2 := TBoxInput.y1;
      end;
    end;

    Also, you could save a lot of lines by doing this instead:
    SCAR Code:
    function OrderTBox(TBoxInput : TBox) : TBox;
    begin
      result.x1 := min(TBoxInput.x1, TBoxInput.x2);
      result.x2 := max(TBoxInput.x1, TBoxInput.x2);
      result.y1 := min(TBoxInput.y1, TBoxInput.y2);
      result.y2 := max(TBoxInput.y1, TBoxInput.y2);
    end;

    There might be another way to do it to, that's even shorter, but i'm not sure. Basically min returns the lesser number, and max returns the greater number. Sorry to shorten up your function, but i just thought i should show you that

  9. #9
    Join Date
    Jun 2006
    Location
    USA
    Posts
    1,828
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Good job!
    Maybe easier for your eyes:
    SCAR Code:
    function CheckTBoxIntersection(TBox1, TBox2 : TBox) : boolean;
    var
      orderedTBox1, orderedTBox2 : TBox;
    begin
    Result:= (orderedTBox1.x1 >= orderedTBox2.x2)
          or (orderedTBox1.x2 <= orderedTBox2.x1)
          or (orderedTBox1.y1 >= orderedTBox2.y2)
          or (orderedTBox1.y2 <= orderedTBox2.y1)
    end;


    function CollideTBoxs(TBox1, TBox2 : TBox) : TBox;
    var
      returnTBox, orderedTBox1, orderedTBox2 : TBox;
    begin
      if CheckTBoxIntersection(TBox1, TBox2) then
      begin
        orderedTBox1 := OrderTBox(TBox1);
        orderedTBox2 := OrderTBox(TBox2);

        if(orderedTBox1.x1 < orderedTBox2.x1)then
        Result.x1 := orderedTBox2.x1 else
        Result.x1 := orderedTBox1.x1;

        if(orderedTBox1.y1 < orderedTBox2.y1)then
        Result.y1 := orderedTBox2.y1 else
        Result.y1 := orderedTBox1.y1;

        if(orderedTBox1.x2 < orderedTBox2.x2)then
        Result.x2 := orderedTBox1.x2 else
        Result.x2 := orderedTBox2.x2;

        if(orderedTBox1.y2 < orderedTBox2.y2)then
        Result.y2 := orderedTBox1.y2 else
        Result.y2 := orderedTBox2.y2;
      end;
    end;

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

    Default

    Id like to see a script from you

  11. #11
    Join Date
    May 2006
    Location
    Qld, Australia
    Posts
    223
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    SCAR Code:
    function OrderTBox(TBoxInput : TBox) : TBox;
    begin
      result.x1 := min(TBoxInput.x1, TBoxInput.x2);  result.x2 := max(TBoxInput.x1, TBoxInput.x2);  result.y1 := min(TBoxInput.y1, TBoxInput.y2);  result.y2 := max(TBoxInput.y1, TBoxInput.y2);
    end;

    Even shorter =]


    Very good functions, However as NewToAutoing & Pentti pointed out you have some begin & end which aren't needed.
    Haven't scripted in a while, Willing to proofread, test and provide feedback.

  12. #12
    Join Date
    Aug 2007
    Posts
    52
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks to everyone. I'm not sure if it's good to make it that short kevin wolf... but it could be made better. I definitely will use some everyone's suggestions in my next script and hopefully it'll be even better.

    @n3ss3s: Thanks, I don't know when I'll be making a full script... There's a lot of SRL stuff I don't know and still aren't comfortable with. I'm learning and hopefully I'll be able to make a good contribution to SRL in the future.
    Quote Originally Posted by Boreas View Post
    I think of my players as secret agents, that I send out into the field to be invisible. I properly train them to blend in and not die.

    It's my fantasy game within the fantasy game.

  13. #13
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    ehm what are tbox funtions
    ~Hermen

  14. #14
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    scar Code:
    function OrderTBox(TBoxInput : TBox) : TBox;
    begin
      Result := IntToBox(Min(TBoxInput.x1, TBoxInput.x2), Max(TBoxInput.x1, TBoxInput.x2), Min(TBoxInput.y1, TBoxInput.y2), Max(TBoxInput.y1, TBoxInput.y2));
    end;
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  15. #15
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Nava2 View Post
    scar Code:
    function OrderTBox(TBoxInput : TBox) : TBox;
    begin
      Result := IntToBox(Min(TBoxInput.x1, TBoxInput.x2), Max(TBoxInput.x1, TBoxInput.x2), Min(TBoxInput.y1, TBoxInput.y2), Max(TBoxInput.y1, TBoxInput.y2));
    end;
    Ouch! Huge gravedig..
    Verrekte Koekwous

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Functions
    By lordsaturn in forum OSR Help
    Replies: 1
    Last Post: 08-13-2007, 10:12 PM
  2. Inventory Tbox
    By jhildy in forum Research & Development Lounge
    Replies: 8
    Last Post: 08-02-2007, 10:20 PM
  3. Array of Tbox - And TPoint array helps.
    By R0b0t1 in forum OSR Help
    Replies: 4
    Last Post: 06-10-2007, 06:43 PM
  4. how to use functions? need help
    By jayohaycheen in forum OSR Help
    Replies: 1
    Last Post: 03-23-2007, 11:39 PM

Posting Permissions

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