Update readme and changelog for v1.26.0
[openttd-joker.git] / src / industry_map.h
blob374a91ccc0f455b1d39573a05345a0b2a89cea1f
1 /* $Id: industry_map.h 24900 2013-01-08 22:46:42Z planetmaker $ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
10 /** @file industry_map.h Accessors for industries */
12 #ifndef INDUSTRY_MAP_H
13 #define INDUSTRY_MAP_H
15 #include "industrytype.h"
16 #include "water_map.h"
19 /**
20 * The following enums are indices used to know what to draw for this industry tile.
21 * They all are pointing toward array _industry_draw_tile_data, in table/industry_land.h
22 * How to calculate the correct position ? GFXid << 2 | IndustryStage (0 to 3)
24 enum IndustryGraphics {
25 GFX_COAL_MINE_TOWER_NOT_ANIMATED = 0,
26 GFX_COAL_MINE_TOWER_ANIMATED = 1,
27 GFX_POWERPLANT_CHIMNEY = 8,
28 GFX_POWERPLANT_SPARKS = 10,
29 GFX_OILRIG_1 = 24,
30 GFX_OILRIG_2 = 25,
31 GFX_OILRIG_3 = 26,
32 GFX_OILRIG_4 = 27,
33 GFX_OILRIG_5 = 28,
34 GFX_OILWELL_NOT_ANIMATED = 29,
35 GFX_OILWELL_ANIMATED_1 = 30,
36 GFX_OILWELL_ANIMATED_2 = 31,
37 GFX_OILWELL_ANIMATED_3 = 32,
38 GFX_COPPER_MINE_TOWER_NOT_ANIMATED = 47,
39 GFX_COPPER_MINE_TOWER_ANIMATED = 48,
40 GFX_COPPER_MINE_CHIMNEY = 49,
41 GFX_GOLD_MINE_TOWER_NOT_ANIMATED = 79,
42 GFX_GOLD_MINE_TOWER_ANIMATED = 88,
43 GFX_TOY_FACTORY = 143,
44 GFX_PLASTIC_FOUNTAIN_ANIMATED_1 = 148,
45 GFX_PLASTIC_FOUNTAIN_ANIMATED_2 = 149,
46 GFX_PLASTIC_FOUNTAIN_ANIMATED_3 = 150,
47 GFX_PLASTIC_FOUNTAIN_ANIMATED_4 = 151,
48 GFX_PLASTIC_FOUNTAIN_ANIMATED_5 = 152,
49 GFX_PLASTIC_FOUNTAIN_ANIMATED_6 = 153,
50 GFX_PLASTIC_FOUNTAIN_ANIMATED_7 = 154,
51 GFX_PLASTIC_FOUNTAIN_ANIMATED_8 = 155,
52 GFX_BUBBLE_GENERATOR = 161,
53 GFX_BUBBLE_CATCHER = 162,
54 GFX_TOFFEE_QUARY = 165,
55 GFX_SUGAR_MINE_SIEVE = 174,
56 GFX_WATERTILE_SPECIALCHECK = 255, ///< not really a tile, but rather a very special check
59 /**
60 * Get the industry ID of the given tile
61 * @param t the tile to get the industry ID from
62 * @pre IsTileType(t, MP_INDUSTRY)
63 * @return the industry ID
65 static inline IndustryID GetIndustryIndex(TileIndex t)
67 assert(IsTileType(t, MP_INDUSTRY));
68 return _m[t].m2;
71 /**
72 * Is this industry tile fully built?
73 * @param t the tile to analyze
74 * @pre IsTileType(t, MP_INDUSTRY)
75 * @return true if and only if the industry tile is fully built
77 static inline bool IsIndustryCompleted(TileIndex t)
79 assert(IsTileType(t, MP_INDUSTRY));
80 return HasBit(_m[t].m1, 7);
83 IndustryType GetIndustryType(TileIndex tile);
85 /**
86 * Set if the industry that owns the tile as under construction or not
87 * @param tile the tile to query
88 * @pre IsTileType(tile, MP_INDUSTRY)
90 static inline void SetIndustryCompleted(TileIndex tile)
92 assert(IsTileType(tile, MP_INDUSTRY));
93 SB(_m[tile].m1, 7, 1, 1);
96 /**
97 * Returns the industry construction stage of the specified tile
98 * @param tile the tile to query
99 * @pre IsTileType(tile, MP_INDUSTRY)
100 * @return the construction stage
102 static inline byte GetIndustryConstructionStage(TileIndex tile)
104 assert(IsTileType(tile, MP_INDUSTRY));
105 return IsIndustryCompleted(tile) ? (byte)INDUSTRY_COMPLETED : GB(_m[tile].m1, 0, 2);
109 * Sets the industry construction stage of the specified tile
110 * @param tile the tile to query
111 * @param value the new construction stage
112 * @pre IsTileType(tile, MP_INDUSTRY)
114 static inline void SetIndustryConstructionStage(TileIndex tile, byte value)
116 assert(IsTileType(tile, MP_INDUSTRY));
117 SB(_m[tile].m1, 0, 2, value);
121 * Get the industry graphics ID for the given industry tile as
122 * stored in the without translation.
123 * @param t the tile to get the gfx for
124 * @pre IsTileType(t, MP_INDUSTRY)
125 * @return the gfx ID
127 static inline IndustryGfx GetCleanIndustryGfx(TileIndex t)
129 assert(IsTileType(t, MP_INDUSTRY));
130 return _m[t].m5 | (GB(_me[t].m6, 2, 1) << 8);
134 * Get the industry graphics ID for the given industry tile
135 * @param t the tile to get the gfx for
136 * @pre IsTileType(t, MP_INDUSTRY)
137 * @return the gfx ID
139 static inline IndustryGfx GetIndustryGfx(TileIndex t)
141 assert(IsTileType(t, MP_INDUSTRY));
142 return GetTranslatedIndustryTileID(GetCleanIndustryGfx(t));
146 * Set the industry graphics ID for the given industry tile
147 * @param t the tile to set the gfx for
148 * @pre IsTileType(t, MP_INDUSTRY)
149 * @param gfx the graphics ID
151 static inline void SetIndustryGfx(TileIndex t, IndustryGfx gfx)
153 assert(IsTileType(t, MP_INDUSTRY));
154 _m[t].m5 = GB(gfx, 0, 8);
155 SB(_me[t].m6, 2, 1, GB(gfx, 8, 1));
159 * Returns this industry tile's construction counter value
160 * @param tile the tile to query
161 * @pre IsTileType(tile, MP_INDUSTRY)
162 * @return the construction counter
164 static inline byte GetIndustryConstructionCounter(TileIndex tile)
166 assert(IsTileType(tile, MP_INDUSTRY));
167 return GB(_m[tile].m1, 2, 2);
171 * Sets this industry tile's construction counter value
172 * @param tile the tile to query
173 * @param value the new value for the construction counter
174 * @pre IsTileType(tile, MP_INDUSTRY)
176 static inline void SetIndustryConstructionCounter(TileIndex tile, byte value)
178 assert(IsTileType(tile, MP_INDUSTRY));
179 SB(_m[tile].m1, 2, 2, value);
183 * Reset the construction stage counter of the industry,
184 * as well as the completion bit.
185 * In fact, it is the same as restarting construction frmo ground up
186 * @param tile the tile to query
187 * @pre IsTileType(tile, MP_INDUSTRY)
189 static inline void ResetIndustryConstructionStage(TileIndex tile)
191 assert(IsTileType(tile, MP_INDUSTRY));
192 SB(_m[tile].m1, 0, 4, 0);
193 SB(_m[tile].m1, 7, 1, 0);
197 * Get the animation loop number
198 * @param tile the tile to get the animation loop number of
199 * @pre IsTileType(tile, MP_INDUSTRY)
201 static inline byte GetIndustryAnimationLoop(TileIndex tile)
203 assert(IsTileType(tile, MP_INDUSTRY));
204 return _m[tile].m4;
208 * Set the animation loop number
209 * @param tile the tile to set the animation loop number of
210 * @param count the new animation frame number
211 * @pre IsTileType(tile, MP_INDUSTRY)
213 static inline void SetIndustryAnimationLoop(TileIndex tile, byte count)
215 assert(IsTileType(tile, MP_INDUSTRY));
216 _m[tile].m4 = count;
220 * Get the random bits for this tile.
221 * Used for grf callbacks
222 * @param tile TileIndex of the tile to query
223 * @pre IsTileType(tile, MP_INDUSTRY)
224 * @return requested bits
226 static inline byte GetIndustryRandomBits(TileIndex tile)
228 assert(IsTileType(tile, MP_INDUSTRY));
229 return _m[tile].m3;
233 * Set the random bits for this tile.
234 * Used for grf callbacks
235 * @param tile TileIndex of the tile to query
236 * @param bits the random bits
237 * @pre IsTileType(tile, MP_INDUSTRY)
239 static inline void SetIndustryRandomBits(TileIndex tile, byte bits)
241 assert(IsTileType(tile, MP_INDUSTRY));
242 _m[tile].m3 = bits;
246 * Get the activated triggers bits for this industry tile
247 * Used for grf callbacks
248 * @param tile TileIndex of the tile to query
249 * @pre IsTileType(tile, MP_INDUSTRY)
250 * @return requested triggers
252 static inline byte GetIndustryTriggers(TileIndex tile)
254 assert(IsTileType(tile, MP_INDUSTRY));
255 return GB(_me[tile].m6, 3, 3);
260 * Set the activated triggers bits for this industry tile
261 * Used for grf callbacks
262 * @param tile TileIndex of the tile to query
263 * @param triggers the triggers to set
264 * @pre IsTileType(tile, MP_INDUSTRY)
266 static inline void SetIndustryTriggers(TileIndex tile, byte triggers)
268 assert(IsTileType(tile, MP_INDUSTRY));
269 SB(_me[tile].m6, 3, 3, triggers);
273 * Make the given tile an industry tile
274 * @param t the tile to make an industry tile
275 * @param index the industry this tile belongs to
276 * @param gfx the graphics to use for the tile
277 * @param random the random value
278 * @param wc the water class for this industry; only useful when build on water
280 static inline void MakeIndustry(TileIndex t, IndustryID index, IndustryGfx gfx, uint8 random, WaterClass wc)
282 SetTileType(t, MP_INDUSTRY);
283 _m[t].m1 = 0;
284 _m[t].m2 = index;
285 SetIndustryRandomBits(t, random); // m3
286 _m[t].m4 = 0;
287 SetIndustryGfx(t, gfx); // m5, part of m6
288 SetIndustryTriggers(t, 0); // rest of m6
289 SetWaterClass(t, wc);
290 _me[t].m7 = 0;
293 #endif /* INDUSTRY_MAP_H */