author | miham |
Wed, 13 Dec 2006 18:47:59 +0000 | |
changeset 5331 | f581ed3807ef |
parent 4666 | 850b5b6e4bac |
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 { |
3447 | 13 |
CLEAR_GRASS = 0, // 0-3 |
14 |
CLEAR_ROUGH = 1, // 3 |
|
15 |
CLEAR_ROCKS = 2, // 3 |
|
16 |
CLEAR_FIELDS = 3, // 3 |
|
17 |
CLEAR_SNOW = 4, // 0-3 |
|
18 |
CLEAR_DESERT = 5 // 1,3 |
|
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
|
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 |
{ |
3447 | 76 |
assert(GetClearGround(t) == CLEAR_FIELDS); |
3369
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 |
{ |
3447 | 82 |
assert(GetClearGround(t) == CLEAR_FIELDS); // XXX incomplete |
3369
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 |
|
4328
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
3516
diff
changeset
|
86 |
static inline uint16 GetIndustryIndexOfField(TileIndex t) |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
3516
diff
changeset
|
87 |
{ |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
3516
diff
changeset
|
88 |
assert(GetClearGround(t) == CLEAR_FIELDS); |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
3516
diff
changeset
|
89 |
return _m[t].m2; |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
3516
diff
changeset
|
90 |
} |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
3516
diff
changeset
|
91 |
|
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
3516
diff
changeset
|
92 |
static inline void SetIndustryIndexOfField(TileIndex t, uint16 i) |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
3516
diff
changeset
|
93 |
{ |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
3516
diff
changeset
|
94 |
assert(GetClearGround(t) == CLEAR_FIELDS); |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
3516
diff
changeset
|
95 |
_m[t].m2 = i; |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
3516
diff
changeset
|
96 |
} |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
97 |
|
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
98 |
/* Is used by tree tiles, too */ |
3369
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
99 |
static inline uint GetFenceSE(TileIndex t) |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
100 |
{ |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
101 |
assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
102 |
return GB(_m[t].m4, 2, 3); |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
103 |
} |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
104 |
|
3369
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
105 |
static inline void SetFenceSE(TileIndex t, uint h) |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
106 |
{ |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
107 |
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
|
108 |
SB(_m[t].m4, 2, 3, h); |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
109 |
} |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
110 |
|
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
111 |
static inline uint GetFenceSW(TileIndex t) |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
112 |
{ |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
113 |
assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
114 |
return GB(_m[t].m4, 5, 3); |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
115 |
} |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
116 |
|
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
117 |
static inline void SetFenceSW(TileIndex t, uint h) |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
118 |
{ |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
119 |
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
|
120 |
SB(_m[t].m4, 5, 3, h); |
00c2ca209a89
(svn r4166) Sprinkle several map accessors with assert()s
tron
parents:
3291
diff
changeset
|
121 |
} |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
122 |
|
3076
9584f34a83dc
(svn r3665) Add a function to turn a tile into a clear tile
tron
parents:
2979
diff
changeset
|
123 |
|
9584f34a83dc
(svn r3665) Add a function to turn a tile into a clear tile
tron
parents:
2979
diff
changeset
|
124 |
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
|
125 |
{ |
9584f34a83dc
(svn r3665) Add a function to turn a tile into a clear tile
tron
parents:
2979
diff
changeset
|
126 |
SetTileType(t, MP_CLEAR); |
9584f34a83dc
(svn r3665) Add a function to turn a tile into a clear tile
tron
parents:
2979
diff
changeset
|
127 |
SetTileOwner(t, OWNER_NONE); |
9584f34a83dc
(svn r3665) Add a function to turn a tile into a clear tile
tron
parents:
2979
diff
changeset
|
128 |
_m[t].m2 = 0; |
9584f34a83dc
(svn r3665) Add a function to turn a tile into a clear tile
tron
parents:
2979
diff
changeset
|
129 |
_m[t].m3 = 0; |
9584f34a83dc
(svn r3665) Add a function to turn a tile into a clear tile
tron
parents:
2979
diff
changeset
|
130 |
_m[t].m4 = 0 << 5 | 0 << 2; |
3291 | 131 |
SetClearGroundDensity(t, g, density); |
132 |
} |
|
133 |
||
134 |
||
4328
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
3516
diff
changeset
|
135 |
static inline void MakeField(TileIndex t, uint field_type, uint16 industry) |
3291 | 136 |
{ |
137 |
SetTileType(t, MP_CLEAR); |
|
138 |
SetTileOwner(t, OWNER_NONE); |
|
4328
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
3516
diff
changeset
|
139 |
_m[t].m2 = industry; |
3291 | 140 |
_m[t].m3 = field_type; |
141 |
_m[t].m4 = 0 << 5 | 0 << 2; |
|
3447 | 142 |
SetClearGroundDensity(t, CLEAR_FIELDS, 3); |
3076
9584f34a83dc
(svn r3665) Add a function to turn a tile into a clear tile
tron
parents:
2979
diff
changeset
|
143 |
} |
9584f34a83dc
(svn r3665) Add a function to turn a tile into a clear tile
tron
parents:
2979
diff
changeset
|
144 |
|
4666
850b5b6e4bac
(svn r6560) - Codechange: Minor fix; add missing #include guards and comments, and correct svn properties on bmp.[ch]
peter1138
parents:
4328
diff
changeset
|
145 |
#endif /* CLEAR_MAP_H */ |