Results 1 to 5 of 5

Thread: Reflection Tile Grid + Object Tile Bounds

  1. #1
    Join Date
    Apr 2016
    Location
    New Zealand
    Posts
    76
    Mentioned
    0 Post(s)
    Quoted
    32 Post(s)

    Default Reflection Tile Grid + Object Tile Bounds

    Playing around with Tribots draw tile debug feature, I wanted something similar.

    After doing some reading through the forums, I came upon these threads:

    https://villavu.com/forum/showthread.php?t=72965
    https://villavu.com/forum/showthread.php?t=73768

    With some inspiration, I have come up with these 2 scripts.

    Reflection Tile Grid:
    tzzOk41.png
    Simba Code:
    program TileGridDrawing

    {$DEFINE SMART}
    {$i Reflection/Reflection.simba}

    {
      Tile Grid Drawing
      Author: Dissimulo (https://villavu.com/forum/member.php?u=160877)
      Last Update: 19/05/2016
      Version: 1.0
      Category: Utility
      Description: Displays a grid of the tiles surrounding the player
      Includes: Reflection
      Features:
        - Reflection (https://villavu.com/forum/showthread.php?t=111662)
        - Simple SMART paint
      Versions:
        - 1.0 (19/05/2016)
          Cleaned up for the public
      Credits:
        - Kyle (Lape Reflection)
    }


    var MyGuy: TReflectLocalPlayer;

    procedure DrawTileGrid();
    var
      i, j, k: integer;
      TileArray: Array[0..8] of Array [0..8] of TPoint;
      PointTileArray: Array[0..7] of Array [0..7] of TPoint;

    begin
      for j := 0 to 8 do
      begin
        for k := 0 to 8 do
        begin
          TileArray[j][k] := Point((MyGuy.GetTile.X - 4 + j), (MyGuy.GetTile.Y - 4 + k));

          if ((MSX1 < TReflectionTiles.TileToMS(TileArray[j][k]).X) and (TReflectionTiles.TileToMS(TileArray[j][k]).X < MSX2) and
              (MSY1 < TReflectionTiles.TileToMS(TileArray[j][k]).Y) and (TReflectionTiles.TileToMS(TileArray[j][k]).Y < MSY2)) then
          begin
            Reflect.Smart.Graphics.DrawCircle(TReflectionTiles.TileToMS(TileArray[j][k]), 1, clRed, True);
            //Reflect.Smart.Graphics.DrawClippedText((inttostr(k) + ', ' + inttostr(j)),statChars,TReflectionTiles.TileToMS(TileArray[j][k]),clRed);
          end;
        end;
      end;

      for j := 0 to 7 do
      begin
        for k := 0 to 7 do
        begin
            PointTileArray[j][k] := MiddleTPA([TReflectionTiles.TileToMS(TileArray[j][k]), TReflectionTiles.TileToMS(TileArray[j+1][k+1]),
                                                    TReflectionTiles.TileToMS(TileArray[j+1][k]), TReflectionTiles.TileToMS(TileArray[j][k+1])]);    
            if ((MSX1 < PointTileArray[j][k].X) and (PointTileArray[j][k].X < MSX2) and
              (MSY1 < PointTileArray[j][k].Y) and (PointTileArray[j][k].Y < MSY2)) then
            begin
              Reflect.Smart.Graphics.DrawCircle(PointTileArray[j][k], 1, clYellow, True);
              //Reflect.Smart.Graphics.DrawClippedText((inttostr(k) + ', ' + inttostr(j)),statChars,PointTileArray[j][k],clYellow);
            end;
        end;
      end;

      for j := 0 to 7 do
      begin
        for k := 0 to 7 do
        begin

          if (k - 1 > -1) then
            if ((MSX1 < PointTileArray[j][k].X) and (PointTileArray[j][k].X < MSX2) and
              (MSY1 < PointTileArray[j][k].Y) and (PointTileArray[j][k].Y < MSY2) and
              (MSX1 < PointTileArray[j][k - 1].X) and (PointTileArray[j][k - 1].X < MSX2) and
              (MSY1 < PointTileArray[j][k - 1].Y) and (PointTileArray[j][k - 1].Y < MSY2)) then
                Reflect.Smart.Graphics.DrawLine(PointTileArray[j][k], PointTileArray[j][k - 1], clPurple);

          if (j - 1 > -1) then
            if ((MSX1 < PointTileArray[j][k].X) and (PointTileArray[j][k].X < MSX2) and
              (MSY1 < PointTileArray[j][k].Y) and (PointTileArray[j][k].Y < MSY2) and
              (MSX1 < PointTileArray[j - 1][k].X) and (PointTileArray[j - 1][k].X < MSX2) and
              (MSY1 < PointTileArray[j - 1][k].Y) and (PointTileArray[j - 1][k].Y < MSY2)) then
                Reflect.Smart.Graphics.DrawLine(PointTileArray[j][k], PointTileArray[j - 1][k], clPurple);

        end;
      end;
    end;

    begin
      Reflect.Setup;
      MyGuy.Username := 'USERNAME';
      MyGuy.Password := 'PASSWORD';

      MyGuy.Active := True;
      MyGuy.Login;
      repeat
        wait(600);
        Reflect.Smart.Graphics.Clear;
        DrawTileGrid();
      until(False);
    end.

    Object Tile Bounds:
    7K95Kdf.png
    yjgMWaN.png
    44EXIXx.png
    Simba Code:
    program ObjectTileBounds

    {$DEFINE SMART}
    {$i Reflection/Reflection.simba}

    {
      Object Tile Bounds
      Author: Dissimulo (https://villavu.com/forum/member.php?u=160877)
      Last Update: 19/05/2016
      Version: 1.0
      Category: Utility
      Description: Displays the bounds of the tile that the object is on
      Includes: Reflection
      Features:
        - Reflection (https://villavu.com/forum/showthread.php?t=111662)
        - Simple SMART paint
      Versions:
        - 1.0 (19/05/2016)
          Cleaned up for the public
      Credits:
        - Kyle (Lape Reflection)
    }


    var MyGuy: TReflectLocalPlayer;
    ObjectArray: TReflectObjectArray;
    tmpTPA, tmpTPAx, tmpTPAy: TPointArray;
    tmpATPA, tmpATPAcolor: Array of TPointArray;
    i: integer;

    function GetObjectTileBounds(ObjectName: String; ObjectType: TObjectType; DrawBounds: Boolean; var OutputATPA: Array of TPointArray): Boolean;
    var
      i, j, k: integer;
      MyTile: TTile;
      TileArray: Array[0..2] of Array [0..2] of TPoint;
      PointTileArray: Array[0..1] of Array [0..1] of TPoint;

    begin
      ObjectArray.Get(ObjectType, ObjectName, 10);
      SetLength(OutputATPA, (High(ObjectArray) + 1));
         for i:= 0 to High(ObjectArray) do
         begin
          for j := 0 to 2 do
          begin
            for k := 0 to 2 do
            begin
              TileArray[j][k] := Point((ObjectArray[i].GetTile.X - 1 + j), (ObjectArray[i].GetTile.Y - 1 + k));
            end;
          end;

          for j := 0 to 1 do
          begin
            for k := 0 to 1 do
            begin
                PointTileArray[j][k] := MiddleTPA([TReflectionTiles.TileToMS(TileArray[j][k]), TReflectionTiles.TileToMS(TileArray[j+1][k+1]),
                                                    TReflectionTiles.TileToMS(TileArray[j+1][k]), TReflectionTiles.TileToMS(TileArray[j][k+1])]);
            end;
          end;

          for j := 0 to 1 do
          begin
            for k := 0 to 1 do
            begin
              if (k - 1 > -1) then
                if ((MSX1 < PointTileArray[j][k].X) and (PointTileArray[j][k].X < MSX2) and
                  (MSY1 < PointTileArray[j][k].Y) and (PointTileArray[j][k].Y < MSY2) and
                  (MSX1 < PointTileArray[j][k - 1].X) and (PointTileArray[j][k - 1].X < MSX2) and
                  (MSY1 < PointTileArray[j][k - 1].Y) and (PointTileArray[j][k - 1].Y < MSY2) and DrawBounds) then
                    Reflect.Smart.Graphics.DrawLine(PointTileArray[j][k], PointTileArray[j][k - 1], clPurple);
              if (j - 1 > -1) then
                if ((MSX1 < PointTileArray[j][k].X) and (PointTileArray[j][k].X < MSX2) and
                  (MSY1 < PointTileArray[j][k].Y) and (PointTileArray[j][k].Y < MSY2) and
                  (MSX1 < PointTileArray[j - 1][k].X) and (PointTileArray[j - 1][k].X < MSX2) and
                  (MSY1 < PointTileArray[j - 1][k].Y) and (PointTileArray[j - 1][k].Y < MSY2) and DrawBounds) then
                    Reflect.Smart.Graphics.DrawLine(PointTileArray[j][k], PointTileArray[j - 1][k], clPurple);
            end;
          end;

          OutputATPA[i] := [PointTileArray[0][0], PointTileArray[0][1], PointTileArray[1][1], PointTileArray[1][0]];
          Result := True;
      end;
    end;

    begin
      Reflect.Setup;
      MyGuy.Username := 'USERNAME';
      MyGuy.Password := 'PASSWORD';
      MyGuy.Active := True;
      MyGuy.Login;
      repeat
        wait(400);
        Reflect.Smart.Graphics.Clear;
        if GetObjectTileBounds('Rocks', ObjGame, True, tmpATPA) then
        begin
          for i := 0 to high(tmpATPA) do
          begin
            tmpTPAx := CopyTPA(tmpATPA[i]);
            SortTPAByX(tmpTPAx, True);
            tmpTPAy := CopyTPA(tmpATPA[i]);
            SortTPAByY(tmpTPAy, True);
            if (PointInBox(Point(Round((tmpTPAx[0].X + tmpTPAx[1].X) / 2), Round((tmpTPAy[0].Y + tmpTPAy[1].Y) / 2)), intToBox(MSX1, MSY1, MSX2, MSY2)) and
                PointInBox(Point(Round((tmpTPAx[2].X + tmpTPAx[3].X) / 2), Round((tmpTPAy[2].Y + tmpTPAy[3].Y) / 2)), intToBox(MSX1, MSY1, MSX2, MSY2))) then
            begin
                  Reflect.Smart.Graphics.DrawBox(Round((tmpTPAx[0].X + tmpTPAx[1].X) / 2), Round((tmpTPAy[0].Y + tmpTPAy[1].Y) / 2),
                                                  Round((tmpTPAx[2].X + tmpTPAx[3].X) / 2), Round((tmpTPAy[2].Y + tmpTPAy[3].Y) / 2), False, clYellow);
            end;
          end;
        end;
      until(False);
    end.

    The last 2 images are combining color finding within the TBoxes.
    Last edited by Dissimulo; 05-20-2016 at 08:56 AM.

  2. #2
    Join Date
    Jun 2008
    Posts
    56
    Mentioned
    0 Post(s)
    Quoted
    13 Post(s)

    Default

    This is so awesome! I was just testing out something similar. Now does anyone have / know any good method of verifying "isTileInTileArray" or something like that? My efforts so far have rendered me facing a lot of "access vialations". Needless to say that im used to a little bit higher abstraction programming languages than Pascal But it is fun - can't say it isn't fun
    “Programming is like sex. One mistake and you have to support it for the rest of your life.”
    - Michael Sinz

  3. #3
    Join Date
    Jun 2013
    Location
    Scranton
    Posts
    496
    Mentioned
    5 Post(s)
    Quoted
    220 Post(s)

    Default

    this is pretty cool, here is a picture of the object tile highlighter used on a Barrel

  4. #4
    Join Date
    Dec 2013
    Location
    Sweden
    Posts
    269
    Mentioned
    17 Post(s)
    Quoted
    161 Post(s)

    Default

    Quote Originally Posted by prostaker View Post
    This is so awesome! I was just testing out something similar. Now does anyone have / know any good method of verifying "isTileInTileArray" or something like that? My efforts so far have rendered me facing a lot of "access vialations". Needless to say that im used to a little bit higher abstraction programming languages than Pascal But it is fun - can't say it isn't fun
    A TTile is the same as a TPoint, if you look at TPA methods (a TPA is a TPointArray) you'll find PointInArray (or something like that)

    This looks very interesting by the way!
    "Once you begin to think, you can't stop."

    Life > 0

  5. #5
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    Looks like world-to-screen calculation is off.

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
  •