author | celestar |
Mon, 19 Mar 2007 12:38:16 +0000 | |
branch | gamebalance |
changeset 9895 | 7bd07f43b0e3 |
parent 6527 | f584ab6d87f8 |
child 6303 | 84c215fc8eb8 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5847
diff
changeset
|
3 |
/** @file map.h */ |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5847
diff
changeset
|
4 |
|
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
diff
changeset
|
5 |
#ifndef MAP_H |
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
diff
changeset
|
6 |
#define MAP_H |
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
diff
changeset
|
7 |
|
1210 | 8 |
#include "stdafx.h" |
9 |
||
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5847
diff
changeset
|
10 |
/* Putting externs inside inline functions seems to confuse the aliasing |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5847
diff
changeset
|
11 |
* checking on MSVC6. Never use those variables directly. */ |
2051 | 12 |
extern uint _map_log_x; |
13 |
extern uint _map_size_x; |
|
14 |
extern uint _map_size_y; |
|
15 |
extern uint _map_tile_mask; |
|
16 |
extern uint _map_size; |
|
17 |
||
18 |
#define TILE_MASK(x) ((x) & _map_tile_mask) |
|
1394
449e84bdc04e
(svn r1898) Remove some unused macros from macros.h and move some others to more appropriate headers
tron
parents:
1330
diff
changeset
|
19 |
#define TILE_ASSERT(x) assert(TILE_MASK(x) == (x)); |
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
20 |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6527
diff
changeset
|
21 |
struct Tile { |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1981
diff
changeset
|
22 |
byte type_height; |
2360
09e42e4ee139
(svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents:
2186
diff
changeset
|
23 |
byte m1; |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1981
diff
changeset
|
24 |
uint16 m2; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1981
diff
changeset
|
25 |
byte m3; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1981
diff
changeset
|
26 |
byte m4; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1981
diff
changeset
|
27 |
byte m5; |
5847
9ce114e1d90d
(svn r8050) -Codechange: Rename map member extra to m6, since its usage has been widden.
belugas
parents:
5838
diff
changeset
|
28 |
byte m6; |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6527
diff
changeset
|
29 |
}; |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1981
diff
changeset
|
30 |
|
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1981
diff
changeset
|
31 |
extern Tile* _m; |
1218 | 32 |
|
2051 | 33 |
void AllocateMap(uint size_x, uint size_y); |
34 |
||
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5847
diff
changeset
|
35 |
/* binary logarithm of the map size, try to avoid using this one */ |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6527
diff
changeset
|
36 |
static inline uint MapLogX() { return _map_log_x; } |
689 | 37 |
/* The size of the map */ |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6527
diff
changeset
|
38 |
static inline uint MapSizeX() { return _map_size_x; } |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6527
diff
changeset
|
39 |
static inline uint MapSizeY() { return _map_size_y; } |
689 | 40 |
/* The maximum coordinates */ |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6527
diff
changeset
|
41 |
static inline uint MapMaxX() { return _map_size_x - 1; } |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6527
diff
changeset
|
42 |
static inline uint MapMaxY() { return _map_size_y - 1; } |
689 | 43 |
/* The number of tiles in the map */ |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6527
diff
changeset
|
44 |
static inline uint MapSize() { return _map_size; } |
689 | 45 |
|
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5847
diff
changeset
|
46 |
/* Scale a number relative to the map size */ |
1202
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1174
diff
changeset
|
47 |
uint ScaleByMapSize(uint); // Scale relative to the number of tiles |
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1174
diff
changeset
|
48 |
uint ScaleByMapSize1D(uint); // Scale relative to the circumference of the map |
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1174
diff
changeset
|
49 |
|
1174
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1059
diff
changeset
|
50 |
typedef uint32 TileIndex; |
1981 | 51 |
typedef int32 TileIndexDiff; |
52 |
||
53 |
static inline TileIndex TileXY(uint x, uint y) |
|
54 |
{ |
|
2051 | 55 |
return (y * MapSizeX()) + x; |
1981 | 56 |
} |
57 |
||
58 |
static inline TileIndexDiff TileDiffXY(int x, int y) |
|
59 |
{ |
|
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5847
diff
changeset
|
60 |
/* Multiplication gives much better optimization on MSVC than shifting. |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5847
diff
changeset
|
61 |
* 0 << shift isn't optimized to 0 properly. |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5847
diff
changeset
|
62 |
* Typically x and y are constants, and then this doesn't result |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5847
diff
changeset
|
63 |
* in any actual multiplication in the assembly code.. */ |
2051 | 64 |
return (y * MapSizeX()) + x; |
1981 | 65 |
} |
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1247
diff
changeset
|
66 |
|
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
67 |
static inline TileIndex TileVirtXY(uint x, uint y) |
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
68 |
{ |
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
69 |
return (y >> 4 << MapLogX()) + (x >> 4); |
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
70 |
} |
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
71 |
|
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1247
diff
changeset
|
72 |
|
1247 | 73 |
enum { |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
74 |
INVALID_TILE = (TileIndex)-1 |
1247 | 75 |
}; |
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
76 |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1679
diff
changeset
|
77 |
enum { |
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5847
diff
changeset
|
78 |
TILE_SIZE = 16, ///< Tiles are 16x16 "units" in size |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5847
diff
changeset
|
79 |
TILE_PIXELS = 32, ///< a tile is 32x32 pixels |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5847
diff
changeset
|
80 |
TILE_HEIGHT = 8, ///< The standard height-difference between tiles on two levels is 8 (z-diff 8) |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1679
diff
changeset
|
81 |
}; |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1679
diff
changeset
|
82 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1679
diff
changeset
|
83 |
|
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
84 |
static inline uint TileX(TileIndex tile) |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
85 |
{ |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
86 |
return tile & MapMaxX(); |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
87 |
} |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
88 |
|
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
89 |
static inline uint TileY(TileIndex tile) |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
90 |
{ |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
91 |
return tile >> MapLogX(); |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
92 |
} |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
93 |
|
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
909
diff
changeset
|
94 |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6527
diff
changeset
|
95 |
struct TileIndexDiffC { |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
96 |
int16 x; |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
97 |
int16 y; |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6527
diff
changeset
|
98 |
}; |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
99 |
|
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
100 |
static inline TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc) |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
101 |
{ |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
102 |
return (tidc.y << MapLogX()) + tidc.x; |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
103 |
} |
900 | 104 |
|
955
25bc5b97e3e2
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
105 |
|
25bc5b97e3e2
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
106 |
#ifndef _DEBUG |
25bc5b97e3e2
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
107 |
#define TILE_ADD(x,y) ((x) + (y)) |
25bc5b97e3e2
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
108 |
#else |
25bc5b97e3e2
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
109 |
extern TileIndex TileAdd(TileIndex tile, TileIndexDiff add, |
25bc5b97e3e2
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
110 |
const char *exp, const char *file, int line); |
25bc5b97e3e2
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
111 |
#define TILE_ADD(x, y) (TileAdd((x), (y), #x " + " #y, __FILE__, __LINE__)) |
25bc5b97e3e2
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
112 |
#endif |
25bc5b97e3e2
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
113 |
|
1981 | 114 |
#define TILE_ADDXY(tile, x, y) TILE_ADD(tile, TileDiffXY(x, y)) |
955
25bc5b97e3e2
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
115 |
|
1247 | 116 |
uint TileAddWrap(TileIndex tile, int addx, int addy); |
117 |
||
4561 | 118 |
static inline TileIndexDiffC TileIndexDiffCByDiagDir(uint dir) { |
119 |
extern const TileIndexDiffC _tileoffs_by_diagdir[4]; |
|
120 |
||
121 |
assert(dir < lengthof(_tileoffs_by_diagdir)); |
|
122 |
return _tileoffs_by_diagdir[dir]; |
|
1247 | 123 |
} |
124 |
||
125 |
/* Returns tile + the diff given in diff. If the result tile would end up |
|
126 |
* outside of the map, INVALID_TILE is returned instead. |
|
127 |
*/ |
|
128 |
static inline TileIndex AddTileIndexDiffCWrap(TileIndex tile, TileIndexDiffC diff) { |
|
129 |
int x = TileX(tile) + diff.x; |
|
130 |
int y = TileY(tile) + diff.y; |
|
131 |
if (x < 0 || y < 0 || x > (int)MapMaxX() || y > (int)MapMaxY()) |
|
132 |
return INVALID_TILE; |
|
133 |
else |
|
1981 | 134 |
return TileXY(x, y); |
1247 | 135 |
} |
955
25bc5b97e3e2
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
136 |
|
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5847
diff
changeset
|
137 |
/* Functions to calculate distances */ |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5847
diff
changeset
|
138 |
uint DistanceManhattan(TileIndex, TileIndex); ///< also known as L1-Norm. Is the shortest distance one could go over diagonal tracks (or roads) |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5847
diff
changeset
|
139 |
uint DistanceSquare(TileIndex, TileIndex); ///< euclidian- or L2-Norm squared |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5847
diff
changeset
|
140 |
uint DistanceMax(TileIndex, TileIndex); ///< also known as L-Infinity-Norm |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5847
diff
changeset
|
141 |
uint DistanceMaxPlusManhattan(TileIndex, TileIndex); ///< Max + Manhattan |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5847
diff
changeset
|
142 |
uint DistanceFromEdge(TileIndex); ///< shortest distance from any edge of the map |
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1218
diff
changeset
|
143 |
|
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1218
diff
changeset
|
144 |
|
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
145 |
#define BEGIN_TILE_LOOP(var,w,h,tile) \ |
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
146 |
{ \ |
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
147 |
int h_cur = h; \ |
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
148 |
uint var = tile; \ |
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
149 |
do { \ |
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
150 |
int w_cur = w; \ |
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
151 |
do { |
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
152 |
|
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
153 |
#define END_TILE_LOOP(var,w,h,tile) \ |
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
154 |
} while (++var, --w_cur != 0); \ |
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
155 |
} while (var += TileDiffXY(0, 1) - (w), --h_cur != 0); \ |
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
156 |
} |
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
157 |
|
4561 | 158 |
static inline TileIndexDiff TileOffsByDiagDir(uint dir) |
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4344
diff
changeset
|
159 |
{ |
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4344
diff
changeset
|
160 |
extern const TileIndexDiffC _tileoffs_by_diagdir[4]; |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
161 |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4344
diff
changeset
|
162 |
assert(dir < lengthof(_tileoffs_by_diagdir)); |
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4344
diff
changeset
|
163 |
return ToTileIndexDiff(_tileoffs_by_diagdir[dir]); |
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4344
diff
changeset
|
164 |
} |
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4344
diff
changeset
|
165 |
|
4561 | 166 |
static inline TileIndexDiff TileOffsByDir(uint dir) |
900 | 167 |
{ |
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4344
diff
changeset
|
168 |
extern const TileIndexDiffC _tileoffs_by_dir[8]; |
900 | 169 |
|
170 |
assert(dir < lengthof(_tileoffs_by_dir)); |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
171 |
return ToTileIndexDiff(_tileoffs_by_dir[dir]); |
900 | 172 |
} |
173 |
||
5118
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
4849
diff
changeset
|
174 |
typedef bool TestTileOnSearchProc(TileIndex tile, uint32 data); |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
4849
diff
changeset
|
175 |
bool CircularTileSearch(TileIndex tile, uint size, TestTileOnSearchProc proc, uint32 data); |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
4849
diff
changeset
|
176 |
|
1677
c18884ca76d5
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1433
diff
changeset
|
177 |
/* Approximation of the length of a straight track, relative to a diagonal |
c18884ca76d5
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1433
diff
changeset
|
178 |
* track (ie the size of a tile side). #defined instead of const so it can |
c18884ca76d5
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1433
diff
changeset
|
179 |
* stay integer. (no runtime float operations) Is this needed? |
1679
62f9e55a3835
(svn r2183) - Fix: Removed brackets from around STRAIGHT_TRACK_LENGTH, they caused preliminary rounding...
matthijs
parents:
1677
diff
changeset
|
180 |
* Watch out! There are _no_ brackets around here, to prevent intermediate |
62f9e55a3835
(svn r2183) - Fix: Removed brackets from around STRAIGHT_TRACK_LENGTH, they caused preliminary rounding...
matthijs
parents:
1677
diff
changeset
|
181 |
* rounding! Be careful when using this! |
1677
c18884ca76d5
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1433
diff
changeset
|
182 |
* This value should be sqrt(2)/2 ~ 0.7071 */ |
1679
62f9e55a3835
(svn r2183) - Fix: Removed brackets from around STRAIGHT_TRACK_LENGTH, they caused preliminary rounding...
matthijs
parents:
1677
diff
changeset
|
183 |
#define STRAIGHT_TRACK_LENGTH 7071/10000 |
1677
c18884ca76d5
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1433
diff
changeset
|
184 |
|
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2403
diff
changeset
|
185 |
#endif /* MAP_H */ |