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); |