author | maedhros |
Mon, 06 Aug 2007 12:54:03 +0000 | |
changeset 7417 | c0ddfb49c50b |
parent 7317 | e61af9d8a2b3 |
child 7546 | c4f9132d9f1e |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6201
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5596
diff
changeset
|
3 |
/** @file map.h */ |
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5596
diff
changeset
|
4 |
|
679
04ca2cd69420
(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 |
04ca2cd69420
(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 |
04ca2cd69420
(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" |
7317
e61af9d8a2b3
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
6571
diff
changeset
|
9 |
#include "direction.h" |
1210 | 10 |
|
2051 | 11 |
extern uint _map_tile_mask; |
6540
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
12 |
|
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
13 |
/** |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
14 |
* 'Wraps' the given tile to it is within the map. It does |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
15 |
* this by masking the 'high' bits of. |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
16 |
* @param x the tile to 'wrap' |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
17 |
*/ |
2051 | 18 |
|
19 |
#define TILE_MASK(x) ((x) & _map_tile_mask) |
|
6540
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
20 |
/** |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
21 |
* Asserts when the tile is outside of the map. |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
22 |
* @param x the tile to check |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
23 |
*/ |
1394
79cb56d80a3a
(svn r1898) Remove some unused macros from macros.h and move some others to more appropriate headers
tron
parents:
1330
diff
changeset
|
24 |
#define TILE_ASSERT(x) assert(TILE_MASK(x) == (x)); |
926
a6d140a6a4de
(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
|
25 |
|
6540
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
26 |
/** |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
27 |
* Data that is stored per tile. Also used TileExtended for this. |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
28 |
* Look at docs/landscape.html for the exact meaning of the members. |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
29 |
*/ |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
30 |
struct Tile { |
6540
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
31 |
byte type_height; ///< The type (bits 4..7) and height of the northern corner |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
32 |
byte m1; ///< Primarily used for ownership information |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
33 |
uint16 m2; ///< Primarily used for indices to towns, industries and stations |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
34 |
byte m3; ///< General purpose |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
35 |
byte m4; ///< General purpose |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
36 |
byte m5; ///< General purpose |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
37 |
byte m6; ///< Primarily used for bridges and rainforest/desert |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
38 |
}; |
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:
1981
diff
changeset
|
39 |
|
6540
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
40 |
/** |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
41 |
* Data that is stored per tile. Also used Tile for this. |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
42 |
* Look at docs/landscape.html for the exact meaning of the members. |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
43 |
*/ |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6248
diff
changeset
|
44 |
struct TileExtended { |
6540
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
45 |
byte m7; ///< Primarily used for newgrf support |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6248
diff
changeset
|
46 |
}; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6248
diff
changeset
|
47 |
|
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6248
diff
changeset
|
48 |
extern Tile *_m; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6248
diff
changeset
|
49 |
extern TileExtended *_me; |
1218 | 50 |
|
2051 | 51 |
void AllocateMap(uint size_x, uint size_y); |
52 |
||
6540
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
53 |
/** |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
54 |
* Logarithm of the map size along the X side. |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
55 |
* @note try to avoid using this one |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
56 |
* @return 2^"return value" == MapSizeX() |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
57 |
*/ |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
58 |
static inline uint MapLogX() |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
59 |
{ |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
60 |
extern uint _map_log_x; |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
61 |
return _map_log_x; |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
62 |
} |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
63 |
|
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
64 |
/** |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
65 |
* Get the size of the map along the X |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
66 |
* @return the number of tiles along the X of the map |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
67 |
*/ |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
68 |
static inline uint MapSizeX() |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
69 |
{ |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
70 |
extern uint _map_size_x; |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
71 |
return _map_size_x; |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
72 |
} |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
73 |
|
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
74 |
/** |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
75 |
* Get the size of the map along the Y |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
76 |
* @return the number of tiles along the Y of the map |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
77 |
*/ |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
78 |
static inline uint MapSizeY() |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
79 |
{ |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
80 |
extern uint _map_size_y; |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
81 |
return _map_size_y; |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
82 |
} |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
83 |
|
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
84 |
/** |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
85 |
* Get the size of the map |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
86 |
* @return the number of tiles of the map |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
87 |
*/ |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
88 |
static inline uint MapSize() |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
89 |
{ |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
90 |
extern uint _map_size; |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
91 |
return _map_size; |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
92 |
} |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
93 |
|
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
94 |
/** |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
95 |
* Gets the maximum X coordinate within the map, including MP_VOID |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
96 |
* @return the maximum X coordinate |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
97 |
*/ |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
98 |
static inline uint MapMaxX() |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
99 |
{ |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
100 |
return MapSizeX() - 1; |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
101 |
} |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
102 |
|
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
103 |
/** |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
104 |
* Gets the maximum X coordinate within the map, including MP_VOID |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
105 |
* @return the maximum X coordinate |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
106 |
*/ |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
107 |
static inline uint MapMaxY() |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
108 |
{ |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
109 |
return MapSizeY() - 1; |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
110 |
} |
689 | 111 |
|
6201
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5596
diff
changeset
|
112 |
/* Scale a number relative to the map size */ |
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1174
diff
changeset
|
113 |
uint ScaleByMapSize(uint); // Scale relative to the number of tiles |
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1174
diff
changeset
|
114 |
uint ScaleByMapSize1D(uint); // Scale relative to the circumference of the map |
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1174
diff
changeset
|
115 |
|
1174
6a5e747f3ba6
(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
|
116 |
typedef uint32 TileIndex; |
1981 | 117 |
typedef int32 TileIndexDiff; |
118 |
||
119 |
static inline TileIndex TileXY(uint x, uint y) |
|
120 |
{ |
|
2051 | 121 |
return (y * MapSizeX()) + x; |
1981 | 122 |
} |
123 |
||
124 |
static inline TileIndexDiff TileDiffXY(int x, int y) |
|
125 |
{ |
|
6201
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5596
diff
changeset
|
126 |
/* Multiplication gives much better optimization on MSVC than shifting. |
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5596
diff
changeset
|
127 |
* 0 << shift isn't optimized to 0 properly. |
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5596
diff
changeset
|
128 |
* Typically x and y are constants, and then this doesn't result |
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5596
diff
changeset
|
129 |
* in any actual multiplication in the assembly code.. */ |
2051 | 130 |
return (y * MapSizeX()) + x; |
1981 | 131 |
} |
1330
5d76a0522a11
(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
|
132 |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
133 |
static inline TileIndex TileVirtXY(uint x, uint y) |
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
134 |
{ |
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
135 |
return (y >> 4 << MapLogX()) + (x >> 4); |
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
136 |
} |
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
137 |
|
1330
5d76a0522a11
(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
|
138 |
|
1247 | 139 |
enum { |
6540
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
140 |
INVALID_TILE = (TileIndex)-1 ///< The very nice invalid tile marker |
1247 | 141 |
}; |
926
a6d140a6a4de
(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
|
142 |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1679
diff
changeset
|
143 |
enum { |
6201
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5596
diff
changeset
|
144 |
TILE_SIZE = 16, ///< Tiles are 16x16 "units" in size |
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5596
diff
changeset
|
145 |
TILE_PIXELS = 32, ///< a tile is 32x32 pixels |
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5596
diff
changeset
|
146 |
TILE_HEIGHT = 8, ///< The standard height-difference between tiles on two levels is 8 (z-diff 8) |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1679
diff
changeset
|
147 |
}; |
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1679
diff
changeset
|
148 |
|
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1679
diff
changeset
|
149 |
|
6540
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
150 |
/** |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
151 |
* Get the X component of a tile |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
152 |
* @param tile the tile to get the X component of |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
153 |
* @return the X component |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
154 |
*/ |
926
a6d140a6a4de
(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
|
155 |
static inline uint TileX(TileIndex tile) |
a6d140a6a4de
(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
|
156 |
{ |
a6d140a6a4de
(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
|
157 |
return tile & MapMaxX(); |
a6d140a6a4de
(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
|
158 |
} |
a6d140a6a4de
(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
|
159 |
|
6540
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
160 |
/** |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
161 |
* Get the Y component of a tile |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
162 |
* @param tile the tile to get the Y component of |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
163 |
* @return the Y component |
d30795308feb
(svn r9729) -Documentation: add some documentation in various places
rubidium
parents:
6491
diff
changeset
|
164 |
*/ |
926
a6d140a6a4de
(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
|
165 |
static inline uint TileY(TileIndex tile) |
a6d140a6a4de
(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
|
166 |
{ |
a6d140a6a4de
(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
|
167 |
return tile >> MapLogX(); |
a6d140a6a4de
(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
|
168 |
} |
a6d140a6a4de
(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
|
169 |
|
a6d140a6a4de
(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
|
170 |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
171 |
struct TileIndexDiffC { |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
172 |
int16 x; |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
173 |
int16 y; |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
174 |
}; |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
175 |
|
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
176 |
static inline TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc) |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
177 |
{ |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
178 |
return (tidc.y << MapLogX()) + tidc.x; |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
179 |
} |
900 | 180 |
|
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
|
181 |
|
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
|
182 |
#ifndef _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
|
183 |
#define TILE_ADD(x,y) ((x) + (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
|
184 |
#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
|
185 |
extern 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
|
186 |
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
|
187 |
#define TILE_ADD(x, y) (TileAdd((x), (y), #x " + " #y, __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
|
188 |
#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
|
189 |
|
1981 | 190 |
#define TILE_ADDXY(tile, x, y) TILE_ADD(tile, TileDiffXY(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
|
191 |
|
1247 | 192 |
uint TileAddWrap(TileIndex tile, int addx, int addy); |
193 |
||
7317
e61af9d8a2b3
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
6571
diff
changeset
|
194 |
static inline TileIndexDiffC TileIndexDiffCByDiagDir(DiagDirection dir) |
e61af9d8a2b3
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
6571
diff
changeset
|
195 |
{ |
e61af9d8a2b3
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
6571
diff
changeset
|
196 |
extern const TileIndexDiffC _tileoffs_by_diagdir[DIAGDIR_END]; |
4561 | 197 |
|
7317
e61af9d8a2b3
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
6571
diff
changeset
|
198 |
assert(IsValidDiagDirection(dir)); |
4561 | 199 |
return _tileoffs_by_diagdir[dir]; |
1247 | 200 |
} |
201 |
||
202 |
/* Returns tile + the diff given in diff. If the result tile would end up |
|
203 |
* outside of the map, INVALID_TILE is returned instead. |
|
204 |
*/ |
|
7317
e61af9d8a2b3
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
6571
diff
changeset
|
205 |
static inline TileIndex AddTileIndexDiffCWrap(TileIndex tile, TileIndexDiffC diff) |
e61af9d8a2b3
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
6571
diff
changeset
|
206 |
{ |
1247 | 207 |
int x = TileX(tile) + diff.x; |
208 |
int y = TileY(tile) + diff.y; |
|
209 |
if (x < 0 || y < 0 || x > (int)MapMaxX() || y > (int)MapMaxY()) |
|
210 |
return INVALID_TILE; |
|
211 |
else |
|
1981 | 212 |
return TileXY(x, y); |
1247 | 213 |
} |
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
|
214 |
|
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6540
diff
changeset
|
215 |
/** |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6540
diff
changeset
|
216 |
* Returns the diff between two tiles |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6540
diff
changeset
|
217 |
* |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6540
diff
changeset
|
218 |
* @param tile_a from tile |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6540
diff
changeset
|
219 |
* @param tile_b to tile |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6540
diff
changeset
|
220 |
* @return the difference between tila_a and tile_b |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6540
diff
changeset
|
221 |
*/ |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6540
diff
changeset
|
222 |
static inline TileIndexDiffC TileIndexToTileIndexDiffC(TileIndex tile_a, TileIndex tile_b) |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6540
diff
changeset
|
223 |
{ |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6540
diff
changeset
|
224 |
TileIndexDiffC difference; |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6540
diff
changeset
|
225 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6540
diff
changeset
|
226 |
difference.x = TileX(tile_a) - TileX(tile_b); |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6540
diff
changeset
|
227 |
difference.y = TileY(tile_a) - TileY(tile_b); |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6540
diff
changeset
|
228 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6540
diff
changeset
|
229 |
return difference; |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6540
diff
changeset
|
230 |
} |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6540
diff
changeset
|
231 |
|
6201
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5596
diff
changeset
|
232 |
/* Functions to calculate distances */ |
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5596
diff
changeset
|
233 |
uint DistanceManhattan(TileIndex, TileIndex); ///< also known as L1-Norm. Is the shortest distance one could go over diagonal tracks (or roads) |
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5596
diff
changeset
|
234 |
uint DistanceSquare(TileIndex, TileIndex); ///< euclidian- or L2-Norm squared |
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5596
diff
changeset
|
235 |
uint DistanceMax(TileIndex, TileIndex); ///< also known as L-Infinity-Norm |
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5596
diff
changeset
|
236 |
uint DistanceMaxPlusManhattan(TileIndex, TileIndex); ///< Max + Manhattan |
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
5596
diff
changeset
|
237 |
uint DistanceFromEdge(TileIndex); ///< shortest distance from any edge of the map |
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1218
diff
changeset
|
238 |
|
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1218
diff
changeset
|
239 |
|
6491
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6332
diff
changeset
|
240 |
#define BEGIN_TILE_LOOP(var, w, h, tile) \ |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
241 |
{ \ |
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
242 |
int h_cur = h; \ |
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
243 |
uint var = tile; \ |
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
244 |
do { \ |
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
245 |
int w_cur = w; \ |
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
246 |
do { |
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
247 |
|
6491
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6332
diff
changeset
|
248 |
#define END_TILE_LOOP(var, w, h, tile) \ |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
249 |
} while (++var, --w_cur != 0); \ |
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
250 |
} while (var += TileDiffXY(0, 1) - (w), --h_cur != 0); \ |
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
251 |
} |
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
252 |
|
7317
e61af9d8a2b3
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
6571
diff
changeset
|
253 |
static inline TileIndexDiff TileOffsByDiagDir(DiagDirection dir) |
4559
aa0c13e39840
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4344
diff
changeset
|
254 |
{ |
7317
e61af9d8a2b3
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
6571
diff
changeset
|
255 |
extern const TileIndexDiffC _tileoffs_by_diagdir[DIAGDIR_END]; |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2051
diff
changeset
|
256 |
|
7317
e61af9d8a2b3
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
6571
diff
changeset
|
257 |
assert(IsValidDiagDirection(dir)); |
4559
aa0c13e39840
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4344
diff
changeset
|
258 |
return ToTileIndexDiff(_tileoffs_by_diagdir[dir]); |
aa0c13e39840
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4344
diff
changeset
|
259 |
} |
aa0c13e39840
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4344
diff
changeset
|
260 |
|
7317
e61af9d8a2b3
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
6571
diff
changeset
|
261 |
static inline TileIndexDiff TileOffsByDir(Direction dir) |
900 | 262 |
{ |
7317
e61af9d8a2b3
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
6571
diff
changeset
|
263 |
extern const TileIndexDiffC _tileoffs_by_dir[DIR_END]; |
900 | 264 |
|
7317
e61af9d8a2b3
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
6571
diff
changeset
|
265 |
assert(IsValidDirection(dir)); |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
266 |
return ToTileIndexDiff(_tileoffs_by_dir[dir]); |
900 | 267 |
} |
268 |
||
5118
9640617e1abb
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
4849
diff
changeset
|
269 |
typedef bool TestTileOnSearchProc(TileIndex tile, uint32 data); |
9640617e1abb
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
4849
diff
changeset
|
270 |
bool CircularTileSearch(TileIndex tile, uint size, TestTileOnSearchProc proc, uint32 data); |
9640617e1abb
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
4849
diff
changeset
|
271 |
|
1677
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1433
diff
changeset
|
272 |
/* Approximation of the length of a straight track, relative to a diagonal |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1433
diff
changeset
|
273 |
* track (ie the size of a tile side). #defined instead of const so it can |
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1433
diff
changeset
|
274 |
* stay integer. (no runtime float operations) Is this needed? |
1679
9a654f6b85b9
(svn r2183) - Fix: Removed brackets from around STRAIGHT_TRACK_LENGTH, they caused preliminary rounding...
matthijs
parents:
1677
diff
changeset
|
275 |
* Watch out! There are _no_ brackets around here, to prevent intermediate |
9a654f6b85b9
(svn r2183) - Fix: Removed brackets from around STRAIGHT_TRACK_LENGTH, they caused preliminary rounding...
matthijs
parents:
1677
diff
changeset
|
276 |
* rounding! Be careful when using this! |
1677
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1433
diff
changeset
|
277 |
* This value should be sqrt(2)/2 ~ 0.7071 */ |
1679
9a654f6b85b9
(svn r2183) - Fix: Removed brackets from around STRAIGHT_TRACK_LENGTH, they caused preliminary rounding...
matthijs
parents:
1677
diff
changeset
|
278 |
#define STRAIGHT_TRACK_LENGTH 7071/10000 |
1677
d534f0c8c845
(svn r2181) - Add: DistanceTrack() to calculate the distance over optimally laid out tracks.
matthijs
parents:
1433
diff
changeset
|
279 |
|
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2403
diff
changeset
|
280 |
#endif /* MAP_H */ |