author | Darkvater |
Sat, 26 Feb 2005 13:57:40 +0000 | |
changeset 1410 | 3b5f94893633 |
parent 1299 | 0a6510cc889b |
child 1677 | c18884ca76d5 |
permissions | -rw-r--r-- |
679
e959706a3e4d
(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" |
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
diff
changeset
|
2 |
#include "ttd.h" |
1299
0a6510cc889b
(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" |
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 |
#include "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 |
|
1218 | 7 |
uint _map_log_x; |
8 |
uint _map_log_y; |
|
689 | 9 |
|
1218 | 10 |
byte *_map_type_and_height = NULL; |
11 |
byte *_map_owner = NULL; |
|
12 |
uint16 *_map2 = NULL; |
|
13 |
byte *_map3_lo = NULL; |
|
14 |
byte *_map3_hi = NULL; |
|
15 |
byte *_map5 = NULL; |
|
16 |
byte *_map_extra_bits = NULL; |
|
863
8d09f9331a80
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
817
diff
changeset
|
17 |
|
1218 | 18 |
|
19 |
void InitMap(uint log_x, uint log_y) |
|
20 |
{ |
|
21 |
uint map_size; |
|
22 |
||
1244 | 23 |
if (log_x < 6 || log_x > 11 || log_y < 6 || log_y > 11) |
24 |
error("Invalid map size"); |
|
1218 | 25 |
|
1233
2ee427ec9014
(svn r1737) Add DEBUG category "map" and use it to print the map size when allocating the map
tron
parents:
1218
diff
changeset
|
26 |
DEBUG(map, 1)("Allocating map of size %dx%d", log_x, log_y); |
2ee427ec9014
(svn r1737) Add DEBUG category "map" and use it to print the map size when allocating the map
tron
parents:
1218
diff
changeset
|
27 |
|
1410
3b5f94893633
(svn r1914) - Fix: [ 1119147 ] Stop startup memory corruption crash using optimized MSVC6. MSVC6 workaround as it's too stupid again for its own good
Darkvater
parents:
1299
diff
changeset
|
28 |
// XXX - MSVC6 volatile workaround |
3b5f94893633
(svn r1914) - Fix: [ 1119147 ] Stop startup memory corruption crash using optimized MSVC6. MSVC6 workaround as it's too stupid again for its own good
Darkvater
parents:
1299
diff
changeset
|
29 |
*(volatile uint*)&_map_log_x = log_x; |
3b5f94893633
(svn r1914) - Fix: [ 1119147 ] Stop startup memory corruption crash using optimized MSVC6. MSVC6 workaround as it's too stupid again for its own good
Darkvater
parents:
1299
diff
changeset
|
30 |
*(volatile uint*)&_map_log_y = log_y; |
1218 | 31 |
|
32 |
map_size = MapSize(); |
|
33 |
||
34 |
_map_type_and_height = |
|
35 |
realloc(_map_type_and_height, map_size * sizeof(_map_type_and_height[0])); |
|
36 |
_map_owner = realloc(_map_owner, map_size * sizeof(_map_owner[0])); |
|
37 |
_map2 = realloc(_map2, map_size * sizeof(_map2[0])); |
|
38 |
_map3_lo = realloc(_map3_lo, map_size * sizeof(_map3_lo[0])); |
|
39 |
_map3_hi = realloc(_map3_hi, map_size * sizeof(_map3_hi[0])); |
|
40 |
_map5 = realloc(_map5, map_size * sizeof(_map5[0])); |
|
41 |
_map_extra_bits = |
|
42 |
realloc(_map_extra_bits, map_size * sizeof(_map_extra_bits[0] / 4)); |
|
43 |
||
44 |
// XXX TODO handle memory shortage more gracefully |
|
45 |
if (_map_type_and_height == NULL || |
|
46 |
_map_owner == NULL || |
|
47 |
_map2 == NULL || |
|
48 |
_map3_lo == NULL || |
|
49 |
_map3_hi == NULL || |
|
50 |
_map5 == NULL || |
|
51 |
_map_extra_bits == NULL) |
|
52 |
error("Failed to allocate memory for the map"); |
|
53 |
} |
|
900 | 54 |
|
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
|
55 |
|
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
|
56 |
#ifdef _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
|
57 |
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
|
58 |
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
|
59 |
{ |
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
|
60 |
int dx; |
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
|
61 |
int dy; |
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
|
62 |
uint x; |
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
|
63 |
uint 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
|
64 |
|
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
|
65 |
dx = add & MapMaxX(); |
957
d1dd9429e417
(svn r1449) -Fix: signed/unsigned error on windows
darkvater
parents:
955
diff
changeset
|
66 |
if (dx >= (int)MapSizeX() / 2) dx -= MapSizeX(); |
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
|
67 |
dy = (add - dx) / (int)MapSizeX(); |
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
|
68 |
|
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
|
69 |
x = TileX(tile) + dx; |
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
|
70 |
y = TileY(tile) + dy; |
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
|
71 |
|
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
|
72 |
if (x >= MapSizeX() || y >= MapSizeY()) { |
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
|
73 |
char buf[512]; |
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
|
74 |
|
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
|
75 |
sprintf(buf, "TILE_ADD(%s) when adding 0x%.4X and 0x%.4X failed", |
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
|
76 |
exp, tile, 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
|
77 |
#if !defined(_MSC_VER) |
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
|
78 |
fprintf(stderr, "%s:%d %s\n", file, line, buf); |
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
|
79 |
#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
|
80 |
_assert(buf, (char*)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
|
81 |
#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
|
82 |
} |
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
|
83 |
|
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
|
84 |
assert(TILE_XY(x,y) == TILE_MASK(tile + 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
|
85 |
|
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
|
86 |
return TILE_XY(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
|
87 |
} |
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
|
88 |
#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
|
89 |
|
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
|
90 |
|
1202
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
91 |
uint ScaleByMapSize(uint n) |
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
92 |
{ |
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
93 |
int shift = (int)MapLogX() - 8 + (int)MapLogY() - 8; |
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
94 |
|
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
95 |
if (shift < 0) |
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
96 |
return (n + (1 << -shift) - 1) >> -shift; |
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
97 |
else |
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
98 |
return n << shift; |
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
99 |
} |
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
100 |
|
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
101 |
|
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
102 |
uint ScaleByMapSize1D(uint n) |
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
103 |
{ |
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
104 |
int shift = ((int)MapLogX() - 8 + (int)MapLogY() - 8) / 2; |
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
105 |
|
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
106 |
if (shift < 0) |
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
107 |
return (n + (1 << -shift) - 1) >> -shift; |
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
108 |
else |
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
109 |
return n << shift; |
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
110 |
} |
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
111 |
|
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
957
diff
changeset
|
112 |
|
1247 | 113 |
// This function checks if we add addx/addy to tile, if we |
114 |
// do wrap around the edges. For example, tile = (10,2) and |
|
115 |
// addx = +3 and addy = -4. This function will now return |
|
116 |
// INVALID_TILE, because the y is wrapped. This is needed in |
|
117 |
// for example, farmland. When the tile is not wrapped, |
|
118 |
// the result will be tile + TILE_XY(addx, addy) |
|
119 |
uint TileAddWrap(TileIndex tile, int addx, int addy) |
|
120 |
{ |
|
121 |
uint x, y; |
|
122 |
x = TileX(tile) + addx; |
|
123 |
y = TileY(tile) + addy; |
|
124 |
||
125 |
// Are we about to wrap? |
|
126 |
if (x < MapMaxX() && y < MapMaxY()) |
|
127 |
return tile + TILE_XY(addx, addy); |
|
128 |
||
129 |
return INVALID_TILE; |
|
130 |
} |
|
131 |
||
132 |
const TileIndexDiffC _tileoffs_by_dir[] = { |
|
133 |
{-1, 0}, |
|
134 |
{ 0, 1}, |
|
135 |
{ 1, 0}, |
|
136 |
{ 0, -1} |
|
137 |
}; |
|
138 |
||
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
139 |
uint DistanceManhattan(TileIndex t0, TileIndex t1) |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
140 |
{ |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
141 |
return |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
142 |
abs(TileX(t0) - TileX(t1)) + |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
143 |
abs(TileY(t0) - TileY(t1)); |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
144 |
} |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
145 |
|
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
146 |
|
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
147 |
uint DistanceSquare(TileIndex t0, TileIndex t1) |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
148 |
{ |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
149 |
const int x = TileX(t0) - TileX(t1); |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
150 |
const int y = TileY(t0) - TileY(t1); |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
151 |
return x * x + y * y; |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
152 |
} |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
153 |
|
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
154 |
|
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
155 |
uint DistanceMax(TileIndex t0, TileIndex t1) |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
156 |
{ |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
157 |
const uint x = abs(TileX(t0) - TileX(t1)); |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
158 |
const uint y = abs(TileY(t0) - TileY(t1)); |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
159 |
return x > y ? x : y; |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
160 |
} |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
161 |
|
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
162 |
|
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
163 |
uint DistanceMaxPlusManhattan(TileIndex t0, TileIndex t1) |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
164 |
{ |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
165 |
const uint x = abs(TileX(t0) - TileX(t1)); |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
166 |
const uint y = abs(TileY(t0) - TileY(t1)); |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
167 |
return x > y ? 2 * x + y : 2 * y + x; |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
168 |
} |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
169 |
|
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
170 |
|
768d9bc95aaa
(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) |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
172 |
{ |
768d9bc95aaa
(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); |
768d9bc95aaa
(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); |
768d9bc95aaa
(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; |
768d9bc95aaa
(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; |
768d9bc95aaa
(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; |
768d9bc95aaa
(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; |
768d9bc95aaa
(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; |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
180 |
} |
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1244
diff
changeset
|
181 |