author | tron |
Thu, 21 Jul 2005 22:15:02 +0000 | |
changeset 2159 | f6284cf5fab0 |
parent 2051 | e369160ce2f3 |
child 2186 | db48cf29b983 |
permissions | -rw-r--r-- |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
diff
changeset
|
1 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1677
diff
changeset
|
2 |
#include "openttd.h" |
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1247
diff
changeset
|
3 |
#include "debug.h" |
1218 | 4 |
#include "functions.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
5 |
#include "macros.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
diff
changeset
|
6 |
#include "map.h" |
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
diff
changeset
|
7 |
|
1218 | 8 |
uint _map_log_x; |
2051 | 9 |
uint _map_size_x; |
10 |
uint _map_size_y; |
|
11 |
uint _map_tile_mask; |
|
12 |
uint _map_size; |
|
689 | 13 |
|
2049
538e73c53f54
(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:
2043
diff
changeset
|
14 |
Tile* _m = NULL; |
863
6a1444534f62
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
817
diff
changeset
|
15 |
|
1218 | 16 |
|
2051 | 17 |
void AllocateMap(uint size_x, uint size_y) |
1218 | 18 |
{ |
2051 | 19 |
// Make sure that the map size is within the limits and that |
20 |
// the x axis size is a power of 2. |
|
21 |
if (size_x < 64 || size_x > 2048 || |
|
22 |
size_y < 64 || size_y > 2048 || |
|
23 |
(size_x&(size_x-1)) != 0 || |
|
24 |
(size_y&(size_y-1)) != 0) |
|
1244 | 25 |
error("Invalid map size"); |
1218 | 26 |
|
2051 | 27 |
DEBUG(map, 1)("Allocating map of size %dx%d", size_x, size_y); |
1218 | 28 |
|
2051 | 29 |
_map_log_x = FindFirstBit(size_x); |
30 |
_map_size_x = size_x; |
|
31 |
_map_size_y = size_y; |
|
32 |
_map_size = size_x * size_y; |
|
33 |
_map_tile_mask = _map_size - 1; |
|
1218 | 34 |
|
2051 | 35 |
// free/malloc uses less memory than realloc. |
2049
538e73c53f54
(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:
2043
diff
changeset
|
36 |
free(_m); |
2051 | 37 |
_m = malloc(_map_size * sizeof(*_m)); |
1218 | 38 |
|
39 |
// XXX TODO handle memory shortage more gracefully |
|
2049
538e73c53f54
(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:
2043
diff
changeset
|
40 |
if (_m == NULL) error("Failed to allocate memory for the map"); |
1218 | 41 |
} |
900 | 42 |
|
955
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
43 |
|
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
44 |
#ifdef _DEBUG |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
45 |
TileIndex TileAdd(TileIndex tile, TileIndexDiff add, |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
46 |
const char *exp, const char *file, int line) |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
47 |
{ |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
48 |
int dx; |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
49 |
int dy; |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
50 |
uint x; |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
51 |
uint y; |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
52 |
|
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
53 |
dx = add & MapMaxX(); |
957
a1cb5aac6a6f
(svn r1449) -Fix: signed/unsigned error on windows
darkvater
parents:
955
diff
changeset
|
54 |
if (dx >= (int)MapSizeX() / 2) dx -= MapSizeX(); |
955
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
55 |
dy = (add - dx) / (int)MapSizeX(); |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
56 |
|
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
57 |
x = TileX(tile) + dx; |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
58 |
y = TileY(tile) + dy; |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
59 |
|
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
60 |
if (x >= MapSizeX() || y >= MapSizeY()) { |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
61 |
char buf[512]; |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
62 |
|
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
63 |
sprintf(buf, "TILE_ADD(%s) when adding 0x%.4X and 0x%.4X failed", |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
64 |
exp, tile, add); |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
65 |
#if !defined(_MSC_VER) |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
66 |
fprintf(stderr, "%s:%d %s\n", file, line, buf); |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
67 |
#else |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
68 |
_assert(buf, (char*)file, line); |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
69 |
#endif |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
70 |
} |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
71 |
|
1981 | 72 |
assert(TileXY(x,y) == TILE_MASK(tile + add)); |
955
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
73 |
|
1981 | 74 |
return TileXY(x,y); |
955
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
75 |
} |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
76 |
#endif |
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
77 |
|
62b8588f50c8
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
tron
parents:
927
diff
changeset
|
78 |
|
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
79 |
uint ScaleByMapSize(uint n) |
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
80 |
{ |
2051 | 81 |
// First shift by 12 to prevent integer overflow for large values of n. |
82 |
// >>12 is safe since the min mapsize is 64x64 |
|
83 |
// Add (1<<4)-1 to round upwards. |
|
84 |
return (n * (MapSize() >> 12) + (1<<4) - 1) >> 4; |
|
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
85 |
} |
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
86 |
|
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
87 |
|
2051 | 88 |
// Scale relative to the circumference of the map |
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
89 |
uint ScaleByMapSize1D(uint n) |
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
90 |
{ |
2051 | 91 |
// Normal circumference for the X+Y is 256+256 = 1<<9 |
92 |
// Note, not actually taking the full circumference into account, |
|
93 |
// just half of it. |
|
94 |
// (1<<9) - 1 is there to scale upwards. |
|
95 |
return (n * (MapSizeX() + MapSizeY()) + (1<<9) - 1) >> 9; |
|
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
96 |
} |
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
97 |
|
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
98 |
|
1247 | 99 |
// This function checks if we add addx/addy to tile, if we |
100 |
// do wrap around the edges. For example, tile = (10,2) and |
|
101 |
// addx = +3 and addy = -4. This function will now return |
|
102 |
// INVALID_TILE, because the y is wrapped. This is needed in |
|
103 |
// for example, farmland. When the tile is not wrapped, |
|
1981 | 104 |
// the result will be tile + TileDiffXY(addx, addy) |
1247 | 105 |
uint TileAddWrap(TileIndex tile, int addx, int addy) |
106 |
{ |
|
107 |
uint x, y; |
|
108 |
x = TileX(tile) + addx; |
|
109 |
y = TileY(tile) + addy; |
|
110 |
||
111 |
// Are we about to wrap? |
|
1981 | 112 |
if (x < MapMaxX() && y < MapMaxY()) |
113 |
return tile + TileDiffXY(addx, addy); |
|
1247 | 114 |
|
115 |
return INVALID_TILE; |
|
116 |
} |
|
117 |
||
118 |
const TileIndexDiffC _tileoffs_by_dir[] = { |
|
119 |
{-1, 0}, |
|
120 |
{ 0, 1}, |
|
121 |
{ 1, 0}, |
|
122 |
{ 0, -1} |
|
123 |
}; |
|
124 |
||
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
125 |
uint DistanceManhattan(TileIndex t0, TileIndex t1) |
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
126 |
{ |
1677
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
127 |
const uint dx = abs(TileX(t0) - TileX(t1)); |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
128 |
const uint dy = abs(TileY(t0) - TileY(t1)); |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
129 |
return dx + dy; |
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
130 |
} |
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
131 |
|
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
132 |
|
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
133 |
uint DistanceSquare(TileIndex t0, TileIndex t1) |
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
134 |
{ |
1677
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
135 |
const int dx = TileX(t0) - TileX(t1); |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
136 |
const int dy = TileY(t0) - TileY(t1); |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
137 |
return dx * dx + dy * dy; |
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
138 |
} |
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
139 |
|
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
140 |
|
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
141 |
uint DistanceMax(TileIndex t0, TileIndex t1) |
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
142 |
{ |
1677
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
143 |
const uint dx = abs(TileX(t0) - TileX(t1)); |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
144 |
const uint dy = abs(TileY(t0) - TileY(t1)); |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
145 |
return dx > dy ? dx : dy; |
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
146 |
} |
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
147 |
|
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
148 |
|
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
149 |
uint DistanceMaxPlusManhattan(TileIndex t0, TileIndex t1) |
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
150 |
{ |
1677
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
151 |
const uint dx = abs(TileX(t0) - TileX(t1)); |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
152 |
const uint dy = abs(TileY(t0) - TileY(t1)); |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
153 |
return dx > dy ? 2 * dx + dy : 2 * dy + dx; |
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
154 |
} |
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
155 |
|
1677
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
156 |
uint DistanceTrack(TileIndex t0, TileIndex t1) |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
157 |
{ |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
158 |
const uint dx = abs(TileX(t0) - TileX(t1)); |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
159 |
const uint dy = abs(TileY(t0) - TileY(t1)); |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
160 |
|
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
161 |
const uint straightTracks = 2 * min(dx, dy); /* The number of straight (not full length) tracks */ |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
162 |
/* OPTIMISATION: |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
163 |
* Original: diagTracks = max(dx, dy) - min(dx,dy); |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
164 |
* Proof: |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
165 |
* (dx-dy) - straightTracks == (min + max) - straightTracks = min + // max - 2 * min = max - min */ |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
166 |
const uint diagTracks = dx + dy - straightTracks; /* The number of diagonal (full tile length) tracks. */ |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
167 |
|
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
168 |
return diagTracks + straightTracks * STRAIGHT_TRACK_LENGTH; |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1410
diff
changeset
|
169 |
} |
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
170 |
|
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
171 |
uint DistanceFromEdge(TileIndex tile) |
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
172 |
{ |
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
173 |
const uint xl = TileX(tile); |
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
174 |
const uint yl = TileY(tile); |
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
175 |
const uint xh = MapSizeX() - 1 - xl; |
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
176 |
const uint yh = MapSizeY() - 1 - yl; |
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
177 |
const uint minl = xl < yl ? xl : yl; |
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
178 |
const uint minh = xh < yh ? xh : yh; |
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
179 |
return minl < minh ? minl : minh; |
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
180 |
} |
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
181 |