33 // Scale a number relative to the map size |
33 // Scale a number relative to the map size |
34 uint ScaleByMapSize(uint); // Scale relative to the number of tiles |
34 uint ScaleByMapSize(uint); // Scale relative to the number of tiles |
35 uint ScaleByMapSize1D(uint); // Scale relative to the circumference of the map |
35 uint ScaleByMapSize1D(uint); // Scale relative to the circumference of the map |
36 |
36 |
37 typedef uint32 TileIndex; |
37 typedef uint32 TileIndex; |
38 |
38 enum { |
|
39 INVALID_TILE = (uint32) -1 |
|
40 }; |
39 |
41 |
40 static inline uint TileX(TileIndex tile) |
42 static inline uint TileX(TileIndex tile) |
41 { |
43 { |
42 return tile & MapMaxX(); |
44 return tile & MapMaxX(); |
43 } |
45 } |
69 #define TILE_ADD(x, y) (TileAdd((x), (y), #x " + " #y, __FILE__, __LINE__)) |
71 #define TILE_ADD(x, y) (TileAdd((x), (y), #x " + " #y, __FILE__, __LINE__)) |
70 #endif |
72 #endif |
71 |
73 |
72 #define TILE_ADDXY(tile, x, y) TILE_ADD(tile, TILE_XY(x, y)) |
74 #define TILE_ADDXY(tile, x, y) TILE_ADD(tile, TILE_XY(x, y)) |
73 |
75 |
|
76 uint TileAddWrap(TileIndex tile, int addx, int addy); |
|
77 |
|
78 static inline TileIndexDiffC TileIndexDiffCByDir(uint dir) { |
|
79 extern const TileIndexDiffC _tileoffs_by_dir[4]; |
|
80 return _tileoffs_by_dir[dir]; |
|
81 } |
|
82 |
|
83 /* Returns tile + the diff given in diff. If the result tile would end up |
|
84 * outside of the map, INVALID_TILE is returned instead. |
|
85 */ |
|
86 static inline TileIndex AddTileIndexDiffCWrap(TileIndex tile, TileIndexDiffC diff) { |
|
87 int x = TileX(tile) + diff.x; |
|
88 int y = TileY(tile) + diff.y; |
|
89 if (x < 0 || y < 0 || x > (int)MapMaxX() || y > (int)MapMaxY()) |
|
90 return INVALID_TILE; |
|
91 else |
|
92 return TILE_XY(x, y); |
|
93 } |
74 |
94 |
75 // Functions to calculate distances |
95 // Functions to calculate distances |
76 uint DistanceManhattan(TileIndex, TileIndex); // also known as L1-Norm |
96 uint DistanceManhattan(TileIndex, TileIndex); // also known as L1-Norm |
77 uint DistanceSquare(TileIndex, TileIndex); // euclidian- or L2-Norm squared |
97 uint DistanceSquare(TileIndex, TileIndex); // euclidian- or L2-Norm squared |
78 uint DistanceMax(TileIndex, TileIndex); // also known as L-Infinity-Norm |
98 uint DistanceMax(TileIndex, TileIndex); // also known as L-Infinity-Norm |