map.c
changeset 1247 3851739bfd09
parent 1245 3822f77cbc53
child 1299 39c06aba09aa
equal deleted inserted replaced
1246:eb66ff34348f 1247:3851739bfd09
   106 	else
   106 	else
   107 		return n << shift;
   107 		return n << shift;
   108 }
   108 }
   109 
   109 
   110 
   110 
       
   111 // This function checks if we add addx/addy to tile, if we
       
   112 //  do wrap around the edges. For example, tile = (10,2) and
       
   113 //  addx = +3 and addy = -4. This function will now return
       
   114 //  INVALID_TILE, because the y is wrapped. This is needed in
       
   115 //  for example, farmland. When the tile is not wrapped,
       
   116 //  the result will be tile + TILE_XY(addx, addy)
       
   117 uint TileAddWrap(TileIndex tile, int addx, int addy)
       
   118 {
       
   119 	uint x, y;
       
   120 	x = TileX(tile) + addx;
       
   121 	y = TileY(tile) + addy;
       
   122 
       
   123 	// Are we about to wrap?
       
   124 		if (x < MapMaxX() && y < MapMaxY())
       
   125 		return tile + TILE_XY(addx, addy);
       
   126 
       
   127 	return INVALID_TILE;
       
   128 }
       
   129 
       
   130 const TileIndexDiffC _tileoffs_by_dir[] = {
       
   131 	{-1,  0},
       
   132 	{ 0,  1},
       
   133 	{ 1,  0},
       
   134 	{ 0, -1}
       
   135 };
       
   136 
   111 uint DistanceManhattan(TileIndex t0, TileIndex t1)
   137 uint DistanceManhattan(TileIndex t0, TileIndex t1)
   112 {
   138 {
   113 	return
   139 	return
   114 		abs(TileX(t0) - TileX(t1)) +
   140 		abs(TileX(t0) - TileX(t1)) +
   115 		abs(TileY(t0) - TileY(t1));
   141 		abs(TileY(t0) - TileY(t1));
   149 	const uint minl = xl < yl ? xl : yl;
   175 	const uint minl = xl < yl ? xl : yl;
   150 	const uint minh = xh < yh ? xh : yh;
   176 	const uint minh = xh < yh ? xh : yh;
   151 	return minl < minh ? minl : minh;
   177 	return minl < minh ? minl : minh;
   152 }
   178 }
   153 
   179 
   154 
       
   155 const TileIndexDiffC _tileoffs_by_dir[] = {
       
   156 	{-1,  0},
       
   157 	{ 0,  1},
       
   158 	{ 1,  0},
       
   159 	{ 0, -1}
       
   160 };