1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
8 /** @file industry_map.h Accessors for industries */
9
10 #ifndef INDUSTRY_MAP_H
11 #define INDUSTRY_MAP_H
12
13 #include "industrytype.h"
14 #include "water_map.h"
15
16
17 /**
18 * The following enums are indices used to know what to draw for this industry tile.
19 * They all are pointing toward array _industry_draw_tile_data, in table/industry_land.h
20 * How to calculate the correct position ? GFXid << 2 | IndustryStage (0 to 3)
21 */
22 enum IndustryGraphics {
23 GFX_COAL_MINE_TOWER_NOT_ANIMATED = 0,
24 GFX_COAL_MINE_TOWER_ANIMATED = 1,
25 GFX_POWERPLANT_CHIMNEY = 8,
26 GFX_POWERPLANT_SPARKS = 10,
27 GFX_OILRIG_1 = 24,
28 GFX_OILRIG_2 = 25,
29 GFX_OILRIG_3 = 26,
30 GFX_OILRIG_4 = 27,
31 GFX_OILRIG_5 = 28,
32 GFX_OILWELL_NOT_ANIMATED = 29,
33 GFX_OILWELL_ANIMATED_1 = 30,
34 GFX_OILWELL_ANIMATED_2 = 31,
35 GFX_OILWELL_ANIMATED_3 = 32,
36 GFX_COPPER_MINE_TOWER_NOT_ANIMATED = 47,
37 GFX_COPPER_MINE_TOWER_ANIMATED = 48,
38 GFX_COPPER_MINE_CHIMNEY = 49,
39 GFX_GOLD_MINE_TOWER_NOT_ANIMATED = 79,
40 GFX_GOLD_MINE_TOWER_ANIMATED = 88,
41 GFX_TOY_FACTORY = 143,
42 GFX_PLASTIC_FOUNTAIN_ANIMATED_1 = 148,
43 GFX_PLASTIC_FOUNTAIN_ANIMATED_2 = 149,
44 GFX_PLASTIC_FOUNTAIN_ANIMATED_3 = 150,
45 GFX_PLASTIC_FOUNTAIN_ANIMATED_4 = 151,
46 GFX_PLASTIC_FOUNTAIN_ANIMATED_5 = 152,
47 GFX_PLASTIC_FOUNTAIN_ANIMATED_6 = 153,
48 GFX_PLASTIC_FOUNTAIN_ANIMATED_7 = 154,
49 GFX_PLASTIC_FOUNTAIN_ANIMATED_8 = 155,
50 GFX_BUBBLE_GENERATOR = 161,
51 GFX_BUBBLE_CATCHER = 162,
52 GFX_TOFFEE_QUARY = 165,
53 GFX_SUGAR_MINE_SIEVE = 174,
54 GFX_WATERTILE_SPECIALCHECK = 255, ///< not really a tile, but rather a very special check
55 };
56
57 /**
58 * Get the industry ID of the given tile
59 * @param t the tile to get the industry ID from
60 * @pre IsTileType(t, MP_INDUSTRY)
61 * @return the industry ID
62 */
GetIndustryIndex(TileIndex t)63 static inline IndustryID GetIndustryIndex(TileIndex t)
64 {
65 assert(IsTileType(t, MP_INDUSTRY));
66 return _m[t].m2;
67 }
68
69 /**
70 * Is this industry tile fully built?
71 * @param t the tile to analyze
72 * @pre IsTileType(t, MP_INDUSTRY)
73 * @return true if and only if the industry tile is fully built
74 */
IsIndustryCompleted(TileIndex t)75 static inline bool IsIndustryCompleted(TileIndex t)
76 {
77 assert(IsTileType(t, MP_INDUSTRY));
78 return HasBit(_m[t].m1, 7);
79 }
80
81 IndustryType GetIndustryType(TileIndex tile);
82
83 /**
84 * Set if the industry that owns the tile as under construction or not
85 * @param tile the tile to query
86 * @pre IsTileType(tile, MP_INDUSTRY)
87 */
SetIndustryCompleted(TileIndex tile)88 static inline void SetIndustryCompleted(TileIndex tile)
89 {
90 assert(IsTileType(tile, MP_INDUSTRY));
91 SB(_m[tile].m1, 7, 1, 1);
92 }
93
94 /**
95 * Returns the industry construction stage of the specified tile
96 * @param tile the tile to query
97 * @pre IsTileType(tile, MP_INDUSTRY)
98 * @return the construction stage
99 */
GetIndustryConstructionStage(TileIndex tile)100 static inline byte GetIndustryConstructionStage(TileIndex tile)
101 {
102 assert(IsTileType(tile, MP_INDUSTRY));
103 return IsIndustryCompleted(tile) ? (byte)INDUSTRY_COMPLETED : GB(_m[tile].m1, 0, 2);
104 }
105
106 /**
107 * Sets the industry construction stage of the specified tile
108 * @param tile the tile to query
109 * @param value the new construction stage
110 * @pre IsTileType(tile, MP_INDUSTRY)
111 */
SetIndustryConstructionStage(TileIndex tile,byte value)112 static inline void SetIndustryConstructionStage(TileIndex tile, byte value)
113 {
114 assert(IsTileType(tile, MP_INDUSTRY));
115 SB(_m[tile].m1, 0, 2, value);
116 }
117
118 /**
119 * Get the industry graphics ID for the given industry tile as
120 * stored in the without translation.
121 * @param t the tile to get the gfx for
122 * @pre IsTileType(t, MP_INDUSTRY)
123 * @return the gfx ID
124 */
GetCleanIndustryGfx(TileIndex t)125 static inline IndustryGfx GetCleanIndustryGfx(TileIndex t)
126 {
127 assert(IsTileType(t, MP_INDUSTRY));
128 return _m[t].m5 | (GB(_me[t].m6, 2, 1) << 8);
129 }
130
131 /**
132 * Get the industry graphics ID for the given industry tile
133 * @param t the tile to get the gfx for
134 * @pre IsTileType(t, MP_INDUSTRY)
135 * @return the gfx ID
136 */
GetIndustryGfx(TileIndex t)137 static inline IndustryGfx GetIndustryGfx(TileIndex t)
138 {
139 assert(IsTileType(t, MP_INDUSTRY));
140 return GetTranslatedIndustryTileID(GetCleanIndustryGfx(t));
141 }
142
143 /**
144 * Set the industry graphics ID for the given industry tile
145 * @param t the tile to set the gfx for
146 * @pre IsTileType(t, MP_INDUSTRY)
147 * @param gfx the graphics ID
148 */
SetIndustryGfx(TileIndex t,IndustryGfx gfx)149 static inline void SetIndustryGfx(TileIndex t, IndustryGfx gfx)
150 {
151 assert(IsTileType(t, MP_INDUSTRY));
152 _m[t].m5 = GB(gfx, 0, 8);
153 SB(_me[t].m6, 2, 1, GB(gfx, 8, 1));
154 }
155
156 /**
157 * Returns this industry tile's construction counter value
158 * @param tile the tile to query
159 * @pre IsTileType(tile, MP_INDUSTRY)
160 * @return the construction counter
161 */
GetIndustryConstructionCounter(TileIndex tile)162 static inline byte GetIndustryConstructionCounter(TileIndex tile)
163 {
164 assert(IsTileType(tile, MP_INDUSTRY));
165 return GB(_m[tile].m1, 2, 2);
166 }
167
168 /**
169 * Sets this industry tile's construction counter value
170 * @param tile the tile to query
171 * @param value the new value for the construction counter
172 * @pre IsTileType(tile, MP_INDUSTRY)
173 */
SetIndustryConstructionCounter(TileIndex tile,byte value)174 static inline void SetIndustryConstructionCounter(TileIndex tile, byte value)
175 {
176 assert(IsTileType(tile, MP_INDUSTRY));
177 SB(_m[tile].m1, 2, 2, value);
178 }
179
180 /**
181 * Reset the construction stage counter of the industry,
182 * as well as the completion bit.
183 * In fact, it is the same as restarting construction frmo ground up
184 * @param tile the tile to query
185 * @pre IsTileType(tile, MP_INDUSTRY)
186 */
ResetIndustryConstructionStage(TileIndex tile)187 static inline void ResetIndustryConstructionStage(TileIndex tile)
188 {
189 assert(IsTileType(tile, MP_INDUSTRY));
190 SB(_m[tile].m1, 0, 4, 0);
191 SB(_m[tile].m1, 7, 1, 0);
192 }
193
194 /**
195 * Get the animation loop number
196 * @param tile the tile to get the animation loop number of
197 * @pre IsTileType(tile, MP_INDUSTRY)
198 */
GetIndustryAnimationLoop(TileIndex tile)199 static inline byte GetIndustryAnimationLoop(TileIndex tile)
200 {
201 assert(IsTileType(tile, MP_INDUSTRY));
202 return _m[tile].m4;
203 }
204
205 /**
206 * Set the animation loop number
207 * @param tile the tile to set the animation loop number of
208 * @param count the new animation frame number
209 * @pre IsTileType(tile, MP_INDUSTRY)
210 */
SetIndustryAnimationLoop(TileIndex tile,byte count)211 static inline void SetIndustryAnimationLoop(TileIndex tile, byte count)
212 {
213 assert(IsTileType(tile, MP_INDUSTRY));
214 _m[tile].m4 = count;
215 }
216
217 /**
218 * Get the random bits for this tile.
219 * Used for grf callbacks
220 * @param tile TileIndex of the tile to query
221 * @pre IsTileType(tile, MP_INDUSTRY)
222 * @return requested bits
223 */
GetIndustryRandomBits(TileIndex tile)224 static inline byte GetIndustryRandomBits(TileIndex tile)
225 {
226 assert(IsTileType(tile, MP_INDUSTRY));
227 return _m[tile].m3;
228 }
229
230 /**
231 * Set the random bits for this tile.
232 * Used for grf callbacks
233 * @param tile TileIndex of the tile to query
234 * @param bits the random bits
235 * @pre IsTileType(tile, MP_INDUSTRY)
236 */
SetIndustryRandomBits(TileIndex tile,byte bits)237 static inline void SetIndustryRandomBits(TileIndex tile, byte bits)
238 {
239 assert(IsTileType(tile, MP_INDUSTRY));
240 _m[tile].m3 = bits;
241 }
242
243 /**
244 * Get the activated triggers bits for this industry tile
245 * Used for grf callbacks
246 * @param tile TileIndex of the tile to query
247 * @pre IsTileType(tile, MP_INDUSTRY)
248 * @return requested triggers
249 */
GetIndustryTriggers(TileIndex tile)250 static inline byte GetIndustryTriggers(TileIndex tile)
251 {
252 assert(IsTileType(tile, MP_INDUSTRY));
253 return GB(_me[tile].m6, 3, 3);
254 }
255
256
257 /**
258 * Set the activated triggers bits for this industry tile
259 * Used for grf callbacks
260 * @param tile TileIndex of the tile to query
261 * @param triggers the triggers to set
262 * @pre IsTileType(tile, MP_INDUSTRY)
263 */
SetIndustryTriggers(TileIndex tile,byte triggers)264 static inline void SetIndustryTriggers(TileIndex tile, byte triggers)
265 {
266 assert(IsTileType(tile, MP_INDUSTRY));
267 SB(_me[tile].m6, 3, 3, triggers);
268 }
269
270 /**
271 * Make the given tile an industry tile
272 * @param t the tile to make an industry tile
273 * @param index the industry this tile belongs to
274 * @param gfx the graphics to use for the tile
275 * @param random the random value
276 * @param wc the water class for this industry; only useful when build on water
277 */
MakeIndustry(TileIndex t,IndustryID index,IndustryGfx gfx,uint8 random,WaterClass wc)278 static inline void MakeIndustry(TileIndex t, IndustryID index, IndustryGfx gfx, uint8 random, WaterClass wc)
279 {
280 SetTileType(t, MP_INDUSTRY);
281 _m[t].m1 = 0;
282 _m[t].m2 = index;
283 SetIndustryRandomBits(t, random); // m3
284 _m[t].m4 = 0;
285 SetIndustryGfx(t, gfx); // m5, part of m6
286 SetIndustryTriggers(t, 0); // rest of m6
287 SetWaterClass(t, wc);
288 _me[t].m7 = 0;
289 }
290
291 #endif /* INDUSTRY_MAP_H */
292