src/map.h
branchNewGRF_ports
changeset 6743 cabfaa4a0295
parent 6719 4cc327ad39d5
child 6870 ca3fd1fbe311
equal deleted inserted replaced
6742:1337d6c9b97b 6743:cabfaa4a0295
     4 
     4 
     5 #ifndef MAP_H
     5 #ifndef MAP_H
     6 #define MAP_H
     6 #define MAP_H
     7 
     7 
     8 #include "stdafx.h"
     8 #include "stdafx.h"
       
     9 #include "direction.h"
     9 
    10 
    10 extern uint _map_tile_mask;
    11 extern uint _map_tile_mask;
    11 
    12 
    12 /**
    13 /**
    13  * 'Wraps' the given tile to it is within the map. It does
    14  * 'Wraps' the given tile to it is within the map. It does
   188 
   189 
   189 #define TILE_ADDXY(tile, x, y) TILE_ADD(tile, TileDiffXY(x, y))
   190 #define TILE_ADDXY(tile, x, y) TILE_ADD(tile, TileDiffXY(x, y))
   190 
   191 
   191 uint TileAddWrap(TileIndex tile, int addx, int addy);
   192 uint TileAddWrap(TileIndex tile, int addx, int addy);
   192 
   193 
   193 static inline TileIndexDiffC TileIndexDiffCByDiagDir(uint dir) {
   194 static inline TileIndexDiffC TileIndexDiffCByDiagDir(DiagDirection dir)
   194 	extern const TileIndexDiffC _tileoffs_by_diagdir[4];
   195 {
   195 
   196 	extern const TileIndexDiffC _tileoffs_by_diagdir[DIAGDIR_END];
   196 	assert(dir < lengthof(_tileoffs_by_diagdir));
   197 
       
   198 	assert(IsValidDiagDirection(dir));
   197 	return _tileoffs_by_diagdir[dir];
   199 	return _tileoffs_by_diagdir[dir];
   198 }
   200 }
   199 
   201 
   200 /* Returns tile + the diff given in diff. If the result tile would end up
   202 /* Returns tile + the diff given in diff. If the result tile would end up
   201  * outside of the map, INVALID_TILE is returned instead.
   203  * outside of the map, INVALID_TILE is returned instead.
   202  */
   204  */
   203 static inline TileIndex AddTileIndexDiffCWrap(TileIndex tile, TileIndexDiffC diff) {
   205 static inline TileIndex AddTileIndexDiffCWrap(TileIndex tile, TileIndexDiffC diff)
       
   206 {
   204 	int x = TileX(tile) + diff.x;
   207 	int x = TileX(tile) + diff.x;
   205 	int y = TileY(tile) + diff.y;
   208 	int y = TileY(tile) + diff.y;
   206 	if (x < 0 || y < 0 || x > (int)MapMaxX() || y > (int)MapMaxY())
   209 	if (x < 0 || y < 0 || x > (int)MapMaxX() || y > (int)MapMaxY())
   207 		return INVALID_TILE;
   210 		return INVALID_TILE;
   208 	else
   211 	else
   245 #define END_TILE_LOOP(var, w, h, tile)                        \
   248 #define END_TILE_LOOP(var, w, h, tile)                        \
   246 			} while (++var, --w_cur != 0);                       \
   249 			} while (++var, --w_cur != 0);                       \
   247 		} while (var += TileDiffXY(0, 1) - (w), --h_cur != 0); \
   250 		} while (var += TileDiffXY(0, 1) - (w), --h_cur != 0); \
   248 	}
   251 	}
   249 
   252 
   250 static inline TileIndexDiff TileOffsByDiagDir(uint dir)
   253 static inline TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
   251 {
   254 {
   252 	extern const TileIndexDiffC _tileoffs_by_diagdir[4];
   255 	extern const TileIndexDiffC _tileoffs_by_diagdir[DIAGDIR_END];
   253 
   256 
   254 	assert(dir < lengthof(_tileoffs_by_diagdir));
   257 	assert(IsValidDiagDirection(dir));
   255 	return ToTileIndexDiff(_tileoffs_by_diagdir[dir]);
   258 	return ToTileIndexDiff(_tileoffs_by_diagdir[dir]);
   256 }
   259 }
   257 
   260 
   258 static inline TileIndexDiff TileOffsByDir(uint dir)
   261 static inline TileIndexDiff TileOffsByDir(Direction dir)
   259 {
   262 {
   260 	extern const TileIndexDiffC _tileoffs_by_dir[8];
   263 	extern const TileIndexDiffC _tileoffs_by_dir[DIR_END];
   261 
   264 
   262 	assert(dir < lengthof(_tileoffs_by_dir));
   265 	assert(IsValidDirection(dir));
   263 	return ToTileIndexDiff(_tileoffs_by_dir[dir]);
   266 	return ToTileIndexDiff(_tileoffs_by_dir[dir]);
   264 }
   267 }
   265 
   268 
   266 typedef bool TestTileOnSearchProc(TileIndex tile, uint32 data);
   269 typedef bool TestTileOnSearchProc(TileIndex tile, uint32 data);
   267 bool CircularTileSearch(TileIndex tile, uint size, TestTileOnSearchProc proc, uint32 data);
   270 bool CircularTileSearch(TileIndex tile, uint size, TestTileOnSearchProc proc, uint32 data);