OpenTTD
industry_map.h
Go to the documentation of this file.
1 /* $Id: industry_map.h 26878 2014-09-21 11:23:33Z rubidium $ */
2 
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  */
9 
12 #ifndef INDUSTRY_MAP_H
13 #define INDUSTRY_MAP_H
14 
15 #include "industrytype.h"
16 #include "water_map.h"
17 
18 
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,
57 };
58 
65 static inline IndustryID GetIndustryIndex(TileIndex t)
66 {
67  assert(IsTileType(t, MP_INDUSTRY));
68  return _m[t].m2;
69 }
70 
77 static inline bool IsIndustryCompleted(TileIndex t)
78 {
79  assert(IsTileType(t, MP_INDUSTRY));
80  return HasBit(_m[t].m1, 7);
81 }
82 
83 IndustryType GetIndustryType(TileIndex tile);
84 
90 static inline void SetIndustryCompleted(TileIndex tile)
91 {
92  assert(IsTileType(tile, MP_INDUSTRY));
93  SB(_m[tile].m1, 7, 1, 1);
94 }
95 
102 static inline byte GetIndustryConstructionStage(TileIndex tile)
103 {
104  assert(IsTileType(tile, MP_INDUSTRY));
105  return IsIndustryCompleted(tile) ? (byte)INDUSTRY_COMPLETED : GB(_m[tile].m1, 0, 2);
106 }
107 
114 static inline void SetIndustryConstructionStage(TileIndex tile, byte value)
115 {
116  assert(IsTileType(tile, MP_INDUSTRY));
117  SB(_m[tile].m1, 0, 2, value);
118 }
119 
127 static inline IndustryGfx GetCleanIndustryGfx(TileIndex t)
128 {
129  assert(IsTileType(t, MP_INDUSTRY));
130  return _m[t].m5 | (GB(_me[t].m6, 2, 1) << 8);
131 }
132 
139 static inline IndustryGfx GetIndustryGfx(TileIndex t)
140 {
141  assert(IsTileType(t, MP_INDUSTRY));
143 }
144 
151 static inline void SetIndustryGfx(TileIndex t, IndustryGfx gfx)
152 {
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));
156 }
157 
165 {
166  assert(IsTileType(tile, MP_INDUSTRY));
167  return GB(_m[tile].m1, 2, 2);
168 }
169 
176 static inline void SetIndustryConstructionCounter(TileIndex tile, byte value)
177 {
178  assert(IsTileType(tile, MP_INDUSTRY));
179  SB(_m[tile].m1, 2, 2, value);
180 }
181 
190 {
191  assert(IsTileType(tile, MP_INDUSTRY));
192  SB(_m[tile].m1, 0, 4, 0);
193  SB(_m[tile].m1, 7, 1, 0);
194 }
195 
201 static inline byte GetIndustryAnimationLoop(TileIndex tile)
202 {
203  assert(IsTileType(tile, MP_INDUSTRY));
204  return _m[tile].m4;
205 }
206 
213 static inline void SetIndustryAnimationLoop(TileIndex tile, byte count)
214 {
215  assert(IsTileType(tile, MP_INDUSTRY));
216  _m[tile].m4 = count;
217 }
218 
226 static inline byte GetIndustryRandomBits(TileIndex tile)
227 {
228  assert(IsTileType(tile, MP_INDUSTRY));
229  return _m[tile].m3;
230 }
231 
239 static inline void SetIndustryRandomBits(TileIndex tile, byte bits)
240 {
241  assert(IsTileType(tile, MP_INDUSTRY));
242  _m[tile].m3 = bits;
243 }
244 
252 static inline byte GetIndustryTriggers(TileIndex tile)
253 {
254  assert(IsTileType(tile, MP_INDUSTRY));
255  return GB(_me[tile].m6, 3, 3);
256 }
257 
258 
266 static inline void SetIndustryTriggers(TileIndex tile, byte triggers)
267 {
268  assert(IsTileType(tile, MP_INDUSTRY));
269  SB(_me[tile].m6, 3, 3, triggers);
270 }
271 
280 static inline void MakeIndustry(TileIndex t, IndustryID index, IndustryGfx gfx, uint8 random, WaterClass wc)
281 {
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;
291 }
292 
293 #endif /* INDUSTRY_MAP_H */
static void SetIndustryGfx(TileIndex t, IndustryGfx gfx)
Set the industry graphics ID for the given industry tile.
Definition: industry_map.h:151
static IndustryGfx GetCleanIndustryGfx(TileIndex t)
Get the industry graphics ID for the given industry tile as stored in the without translation...
Definition: industry_map.h:127
Part of an industry.
Definition: tile_type.h:51
byte m7
Primarily used for newgrf support.
Definition: map_type.h:37
uint16 m2
Primarily used for indices to towns, industries and stations.
Definition: map_type.h:22
static IndustryGfx GetIndustryGfx(TileIndex t)
Get the industry graphics ID for the given industry tile.
Definition: industry_map.h:139
Tile * _m
Tiles of the map.
Definition: map.cpp:32
Industry type specs.
static byte GetIndustryAnimationLoop(TileIndex tile)
Get the animation loop number.
Definition: industry_map.h:201
static void ResetIndustryConstructionStage(TileIndex tile)
Reset the construction stage counter of the industry, as well as the completion bit.
Definition: industry_map.h:189
static const int INDUSTRY_COMPLETED
final stage of industry construction.
Definition: industry_type.h:38
static void SetWaterClass(TileIndex t, WaterClass wc)
Set the water class at a tile.
Definition: water_map.h:118
static void SetIndustryRandomBits(TileIndex tile, byte bits)
Set the random bits for this tile.
Definition: industry_map.h:239
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
byte m1
Primarily used for ownership information.
Definition: map_type.h:23
not really a tile, but rather a very special check
Definition: industry_map.h:56
static bool IsIndustryCompleted(TileIndex t)
Is this industry tile fully built?
Definition: industry_map.h:77
IndustryGraphics
The following enums are indices used to know what to draw for this industry tile. ...
Definition: industry_map.h:24
static IndustryGfx GetTranslatedIndustryTileID(IndustryGfx gfx)
Do industry gfx ID translation for NewGRFs.
Definition: industrytype.h:186
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
Definition: tile_map.h:143
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition: water_map.h:49
static byte GetIndustryConstructionStage(TileIndex tile)
Returns the industry construction stage of the specified tile.
Definition: industry_map.h:102
static void SetIndustryConstructionCounter(TileIndex tile, byte value)
Sets this industry tile&#39;s construction counter value.
Definition: industry_map.h:176
Map accessors for water tiles.
static void SetIndustryAnimationLoop(TileIndex tile, byte count)
Set the animation loop number.
Definition: industry_map.h:213
TileExtended * _me
Extended Tiles of the map.
Definition: map.cpp:33
byte m5
General purpose.
Definition: map_type.h:26
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
static IndustryID GetIndustryIndex(TileIndex t)
Get the industry ID of the given tile.
Definition: industry_map.h:65
static void SetIndustryCompleted(TileIndex tile)
Set if the industry that owns the tile as under construction or not.
Definition: industry_map.h:90
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
static void SetTileType(TileIndex tile, TileType type)
Set the type of a tile.
Definition: tile_map.h:124
static byte GetIndustryRandomBits(TileIndex tile)
Get the random bits for this tile.
Definition: industry_map.h:226
static void SetIndustryTriggers(TileIndex tile, byte triggers)
Set the activated triggers bits for this industry tile Used for grf callbacks.
Definition: industry_map.h:266
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static byte GetIndustryTriggers(TileIndex tile)
Get the activated triggers bits for this industry tile Used for grf callbacks.
Definition: industry_map.h:252
static void MakeIndustry(TileIndex t, IndustryID index, IndustryGfx gfx, uint8 random, WaterClass wc)
Make the given tile an industry tile.
Definition: industry_map.h:280
byte m3
General purpose.
Definition: map_type.h:24
static void SetIndustryConstructionStage(TileIndex tile, byte value)
Sets the industry construction stage of the specified tile.
Definition: industry_map.h:114
IndustryType GetIndustryType(TileIndex tile)
Retrieve the type for this industry.
static byte GetIndustryConstructionCounter(TileIndex tile)
Returns this industry tile&#39;s construction counter value.
Definition: industry_map.h:164
byte m4
General purpose.
Definition: map_type.h:25