author | celestar |
Fri, 31 Mar 2006 08:18:14 +0000 | |
changeset 3382 | c9c8d85aa632 |
parent 3369 | 00c2ca209a89 |
child 3447 | d136931464f7 |
permissions | -rw-r--r-- |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
1 |
/* $Id$ */ |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
2 |
|
3145
349b745dfbf4
(svn r3765) Fix some naming glitches in r3763 and add missing svn properties
tron
parents:
3144
diff
changeset
|
3 |
#ifndef CLEAR_MAP_H |
349b745dfbf4
(svn r3765) Fix some naming glitches in r3763 and add missing svn properties
tron
parents:
3144
diff
changeset
|
4 |
#define CLEAR_MAP_H |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
5 |
|
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
6 |
#include "macros.h" |
3076
9584f34a83dc
(svn r3665) Add a function to turn a tile into a clear tile
tron
parents:
2979
diff
changeset
|
7 |
#include "tile.h" |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
8 |
|
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
9 |
/* ground type, m5 bits 2...4 |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
10 |
* valid densities (bits 0...1) in comments after the enum |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
11 |
*/ |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
12 |
typedef enum ClearGround { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
13 |
CL_GRASS = 0, // 0-3 |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
14 |
CL_ROUGH = 1, // 3 |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
15 |
CL_ROCKS = 2, // 3 |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
16 |
CL_FIELDS = 3, // 3 |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
17 |
CL_SNOW = 4, // 0-3 |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
18 |
CL_DESERT = 5 // 1,3 |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
19 |
} ClearGround; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
20 |
|
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
21 |
|
3369
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
22 |
static inline ClearGround GetClearGround(TileIndex t) |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
23 |
{ |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
24 |
assert(IsTileType(t, MP_CLEAR)); |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
25 |
return GB(_m[t].m5, 2, 3); |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
26 |
} |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
27 |
|
3369
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
28 |
static inline bool IsClearGround(TileIndex t, ClearGround ct) |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
29 |
{ |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
30 |
return GetClearGround(t) == ct; |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
31 |
} |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
32 |
|
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
33 |
|
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
34 |
static inline uint GetClearDensity(TileIndex t) |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
35 |
{ |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
36 |
assert(IsTileType(t, MP_CLEAR)); |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
37 |
return GB(_m[t].m5, 0, 2); |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
38 |
} |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
39 |
|
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
40 |
static inline void AddClearDensity(TileIndex t, int d) |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
41 |
{ |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
42 |
assert(IsTileType(t, MP_CLEAR)); // XXX incomplete |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
43 |
_m[t].m5 += d; |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
44 |
} |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
45 |
|
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
46 |
|
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
47 |
static inline uint GetClearCounter(TileIndex t) |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
48 |
{ |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
49 |
assert(IsTileType(t, MP_CLEAR)); |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
50 |
return GB(_m[t].m5, 5, 3); |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
51 |
} |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
52 |
|
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
53 |
static inline void AddClearCounter(TileIndex t, int c) |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
54 |
{ |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
55 |
assert(IsTileType(t, MP_CLEAR)); // XXX incomplete |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
56 |
_m[t].m5 += c << 5; |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
57 |
} |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
58 |
|
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
59 |
static inline void SetClearCounter(TileIndex t, uint c) |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
60 |
{ |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
61 |
assert(IsTileType(t, MP_CLEAR)); // XXX incomplete |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
62 |
SB(_m[t].m5, 5, 3, c); |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
63 |
} |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
64 |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
65 |
|
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
66 |
/* Sets type and density in one go, also sets the counter to 0 */ |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
67 |
static inline void SetClearGroundDensity(TileIndex t, ClearGround type, uint density) |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
68 |
{ |
3369
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
69 |
assert(IsTileType(t, MP_CLEAR)); // XXX incomplete |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
70 |
_m[t].m5 = 0 << 5 | type << 2 | density; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
71 |
} |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
72 |
|
3369
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
73 |
|
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
74 |
static inline uint GetFieldType(TileIndex t) |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
75 |
{ |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
76 |
assert(GetClearGround(t) == CL_FIELDS); |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
77 |
return GB(_m[t].m3, 0, 4); |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
78 |
} |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
79 |
|
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
80 |
static inline void SetFieldType(TileIndex t, uint f) |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
81 |
{ |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
82 |
assert(GetClearGround(t) == CL_FIELDS); // XXX incomplete |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
83 |
SB(_m[t].m3, 0, 4, f); |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
84 |
} |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
85 |
|
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
86 |
|
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
87 |
/* Is used by tree tiles, too */ |
3369
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
88 |
static inline uint GetFenceSE(TileIndex t) |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
89 |
{ |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
90 |
assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
91 |
return GB(_m[t].m4, 2, 3); |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
92 |
} |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
93 |
|
3369
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
94 |
static inline void SetFenceSE(TileIndex t, uint h) |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
95 |
{ |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
96 |
assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); // XXX incomplete |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
97 |
SB(_m[t].m4, 2, 3, h); |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
98 |
} |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
99 |
|
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
100 |
static inline uint GetFenceSW(TileIndex t) |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
101 |
{ |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
102 |
assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
103 |
return GB(_m[t].m4, 5, 3); |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
104 |
} |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
105 |
|
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
106 |
static inline void SetFenceSW(TileIndex t, uint h) |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
107 |
{ |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
108 |
assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); // XXX incomplete |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
109 |
SB(_m[t].m4, 5, 3, h); |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
110 |
} |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
111 |
|
3076
9584f34a83dc
(svn r3665) Add a function to turn a tile into a clear tile
tron
parents:
2979
diff
changeset
|
112 |
|
9584f34a83dc
(svn r3665) Add a function to turn a tile into a clear tile
tron
parents:
2979
diff
changeset
|
113 |
static inline void MakeClear(TileIndex t, ClearGround g, uint density) |
9584f34a83dc
(svn r3665) Add a function to turn a tile into a clear tile
tron
parents:
2979
diff
changeset
|
114 |
{ |
9584f34a83dc
(svn r3665) Add a function to turn a tile into a clear tile
tron
parents:
2979
diff
changeset
|
115 |
SetTileType(t, MP_CLEAR); |
9584f34a83dc
(svn r3665) Add a function to turn a tile into a clear tile
tron
parents:
2979
diff
changeset
|
116 |
SetTileOwner(t, OWNER_NONE); |
9584f34a83dc
(svn r3665) Add a function to turn a tile into a clear tile
tron
parents:
2979
diff
changeset
|
117 |
_m[t].m2 = 0; |
9584f34a83dc
(svn r3665) Add a function to turn a tile into a clear tile
tron
parents:
2979
diff
changeset
|
118 |
_m[t].m3 = 0; |
9584f34a83dc
(svn r3665) Add a function to turn a tile into a clear tile
tron
parents:
2979
diff
changeset
|
119 |
_m[t].m4 = 0 << 5 | 0 << 2; |
3291 | 120 |
SetClearGroundDensity(t, g, density); |
121 |
} |
|
122 |
||
123 |
||
124 |
static inline void MakeField(TileIndex t, uint field_type) |
|
125 |
{ |
|
126 |
SetTileType(t, MP_CLEAR); |
|
127 |
SetTileOwner(t, OWNER_NONE); |
|
128 |
_m[t].m2 = 0; |
|
129 |
_m[t].m3 = field_type; |
|
130 |
_m[t].m4 = 0 << 5 | 0 << 2; |
|
131 |
SetClearGroundDensity(t, CL_FIELDS, 3); |
|
3076
9584f34a83dc
(svn r3665) Add a function to turn a tile into a clear tile
tron
parents:
2979
diff
changeset
|
132 |
} |
9584f34a83dc
(svn r3665) Add a function to turn a tile into a clear tile
tron
parents:
2979
diff
changeset
|
133 |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff
changeset
|
134 |
#endif |