The Dink Network

Error in map_tile(); documentation.

May 9th 2012, 07:40 PM
custom_magicman.gif
magicman
Peasant Netherlands steam duck
Mmmm, pizza. 
While I don't think people have actually used this function, dinkc.chm has things wrong here:

The tile_index will range from 1 to 4428. tile_index 1 is the tile in the upper-left corner of tileset 1, tile 109 is the tile in the upper-left corner of tileset 2, and so on.

The tile_index will range from 0 to 5355. tile_index 0 is the tile in the upper-left corner of tileset 1, tile 128 is the tile in the upper-left corner of tileset 2, and so on.

The get_map_tile_index() function provided after it is wrong as well, here is a modified version that's correct:

// get_map_tile_index 
// &arg1 = Tileset (1-41)
// &arg2 = Tile X coordinate (1-12)
// &arg3 = Tile Y coordinate (1-9)
void get_map_tile_index( void )
{
      // Calculate the Tileset offset
      int &temp = &arg1;
      &temp -= 1;
      &temp * 128;
      int &index = &temp;

      // Calculate the X offset
      &temp = &arg2;
      &temp -= 1;
      &index += &temp;

      // Calculate the Y offset
      &temp = &arg3;
      &temp -= 1;
      &temp * 12;
      &index += &temp;

      return(&index);
}


If you know what tile on what tileset you're looking for, you can use that function to get the appropriate tile_index:

void main( void )
{
  // Assuming the above procedure lives in tiles.c
  // Retrieve the tile_index for the tile on tileset 5, second column, first row.
  external("tiles","get_map_tile_index",5,2,1);
  // Replace the top-left tile of the current screen with the tile on tileset 5, second column, first row, of which we just got the tile_index.
  map_tile(1, &return);
  // Needed to see it happen:
  draw_background();
}
May 9th 2012, 07:53 PM
anon.gif
shevek
Ghost
 
I don't remember reading this documentation... I do remember that my tile handling required some trial and error before it actually did what I tried to make it do. So perhaps I did read the documentation.
May 10th 2012, 03:31 AM
slimeg.gif
metatarasal
Bard Male Netherlands
I object 
Did you actually find that mistake exactly the same day as I did? Wow... I used the map_tile(); function yesterday as I couldn't use part of the tileset as a sprite (which would have been the easy solution) because of the throwback contest.

I'd like to mention that the while 0 refers to the upper left tile of tileset 1, it doesn't actually work when you try to place it. Only tiles from index 1 onward can be placed using map_tile();

Also, map_hard_tile(); does work exactly as documented. (So the upper left hardness tile does have index 1 rather than 0)
May 10th 2012, 04:20 AM
wizardb.gif
Kyle
Peasant Male Belgium
 
I love how this contest is going to bring out extreme workarounds through scripting just to avoid the contest limitations xD Keep it up!
May 10th 2012, 08:17 AM
custom_magicman.gif
magicman
Peasant Netherlands steam duck
Mmmm, pizza. 
I'll go one further: The engine counts 128 tiles per tileset (probably a power of 2 was chosen because that makes division and modulo calculations faster... even though the modulo operator isn't used in the original Dink source), with 12 tiles per row. What does this mean for the amount of rows? You might in theory get 10 full rows, and 8 tiles on the 11th row.

If the engine doesn't do any bounds checks on the row of tiles (and I haven't seen it in the code, but I may have missed something), this may mean that you *can* have tilesets of 600x550, where only the last 4 tiles on the last row would be unusable.

Not that this matters for the contest, as we can't add new tilesets, but it's something to experiment with

Edit: If that indeed works, then the upper bound isn't 5355 either, but 5375.
May 10th 2012, 10:36 AM
pq_knight.gif
ExDeathEvn
Peasant Male New Zealand xbox steam
Don't look at me, I'm a ghost 
Kyle: I would laugh if someone did manage a Dmod that didn't use new scripts though.
May 10th 2012, 04:12 PM
wizardb.gif
Kyle
Peasant Male Belgium
 
Some summer paradise mod for the original! xD More flowers! More shrooms! MORE WATER SPLASH SPLASH FUN! More fish... More enemies for increased difficulty! (pesky summer insects)

I could see it work! But I wouldn't play it xD