OpenTTD Source  1.11.2
industry_map.h
Go to the documentation of this file.
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 
10 #ifndef INDUSTRY_MAP_H
11 #define INDUSTRY_MAP_H
12 
13 #include "industrytype.h"
14 #include "water_map.h"
15 
16 
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,
55 };
56 
63 static inline IndustryID GetIndustryIndex(TileIndex t)
64 {
65  assert(IsTileType(t, MP_INDUSTRY));
66  return _m[t].m2;
67 }
68 
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 
88 static inline void SetIndustryCompleted(TileIndex tile)
89 {
90  assert(IsTileType(tile, MP_INDUSTRY));
91  SB(_m[tile].m1, 7, 1, 1);
92 }
93 
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 
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 
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 
137 static inline IndustryGfx GetIndustryGfx(TileIndex t)
138 {
139  assert(IsTileType(t, MP_INDUSTRY));
141 }
142 
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 
163 {
164  assert(IsTileType(tile, MP_INDUSTRY));
165  return GB(_m[tile].m1, 2, 2);
166 }
167 
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 
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 
199 static inline byte GetIndustryAnimationLoop(TileIndex tile)
200 {
201  assert(IsTileType(tile, MP_INDUSTRY));
202  return _m[tile].m4;
203 }
204 
211 static inline void SetIndustryAnimationLoop(TileIndex tile, byte count)
212 {
213  assert(IsTileType(tile, MP_INDUSTRY));
214  _m[tile].m4 = count;
215 }
216 
224 static inline byte GetIndustryRandomBits(TileIndex tile)
225 {
226  assert(IsTileType(tile, MP_INDUSTRY));
227  return _m[tile].m3;
228 }
229 
237 static inline void SetIndustryRandomBits(TileIndex tile, byte bits)
238 {
239  assert(IsTileType(tile, MP_INDUSTRY));
240  _m[tile].m3 = bits;
241 }
242 
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 
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 
278 static inline void MakeIndustry(TileIndex t, IndustryID index, IndustryGfx gfx, uint8 random, WaterClass wc)
279 {
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 */
GetIndustryType
IndustryType GetIndustryType(TileIndex tile)
Retrieve the type for this industry.
Definition: industry_cmd.cpp:104
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
SetIndustryGfx
static void SetIndustryGfx(TileIndex t, IndustryGfx gfx)
Set the industry graphics ID for the given industry tile.
Definition: industry_map.h:149
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
GetIndustryGfx
static IndustryGfx GetIndustryGfx(TileIndex t)
Get the industry graphics ID for the given industry tile.
Definition: industry_map.h:137
SetTileType
static void SetTileType(TileIndex tile, TileType type)
Set the type of a tile.
Definition: tile_map.h:131
SetIndustryConstructionStage
static void SetIndustryConstructionStage(TileIndex tile, byte value)
Sets the industry construction stage of the specified tile.
Definition: industry_map.h:112
IndustryGraphics
IndustryGraphics
The following enums are indices used to know what to draw for this industry tile.
Definition: industry_map.h:22
IsIndustryCompleted
static bool IsIndustryCompleted(TileIndex t)
Is this industry tile fully built?
Definition: industry_map.h:75
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
_me
TileExtended * _me
Extended Tiles of the map.
Definition: map.cpp:31
Tile::m2
uint16 m2
Primarily used for indices to towns, industries and stations.
Definition: map_type.h:20
WaterClass
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition: water_map.h:47
MP_INDUSTRY
@ MP_INDUSTRY
Part of an industry.
Definition: tile_type.h:54
SetIndustryRandomBits
static void SetIndustryRandomBits(TileIndex tile, byte bits)
Set the random bits for this tile.
Definition: industry_map.h:237
GFX_WATERTILE_SPECIALCHECK
@ GFX_WATERTILE_SPECIALCHECK
not really a tile, but rather a very special check
Definition: industry_map.h:54
Tile::m1
byte m1
Primarily used for ownership information.
Definition: map_type.h:21
ResetIndustryConstructionStage
static void ResetIndustryConstructionStage(TileIndex tile)
Reset the construction stage counter of the industry, as well as the completion bit.
Definition: industry_map.h:187
INDUSTRY_COMPLETED
static const int INDUSTRY_COMPLETED
final stage of industry construction.
Definition: industry_type.h:36
SetIndustryConstructionCounter
static void SetIndustryConstructionCounter(TileIndex tile, byte value)
Sets this industry tile's construction counter value.
Definition: industry_map.h:174
GetIndustryAnimationLoop
static byte GetIndustryAnimationLoop(TileIndex tile)
Get the animation loop number.
Definition: industry_map.h:199
SB
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.
Definition: bitmath_func.hpp:58
SetIndustryAnimationLoop
static void SetIndustryAnimationLoop(TileIndex tile, byte count)
Set the animation loop number.
Definition: industry_map.h:211
GetIndustryConstructionStage
static byte GetIndustryConstructionStage(TileIndex tile)
Returns the industry construction stage of the specified tile.
Definition: industry_map.h:100
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
water_map.h
Tile::m5
byte m5
General purpose.
Definition: map_type.h:24
GetIndustryIndex
static IndustryID GetIndustryIndex(TileIndex t)
Get the industry ID of the given tile.
Definition: industry_map.h:63
industrytype.h
GetIndustryTriggers
static byte GetIndustryTriggers(TileIndex tile)
Get the activated triggers bits for this industry tile Used for grf callbacks.
Definition: industry_map.h:250
SetIndustryCompleted
static void SetIndustryCompleted(TileIndex tile)
Set if the industry that owns the tile as under construction or not.
Definition: industry_map.h:88
TileExtended::m7
byte m7
Primarily used for newgrf support.
Definition: map_type.h:35
GetIndustryRandomBits
static byte GetIndustryRandomBits(TileIndex tile)
Get the random bits for this tile.
Definition: industry_map.h:224
GetIndustryConstructionCounter
static byte GetIndustryConstructionCounter(TileIndex tile)
Returns this industry tile's construction counter value.
Definition: industry_map.h:162
SetIndustryTriggers
static void SetIndustryTriggers(TileIndex tile, byte triggers)
Set the activated triggers bits for this industry tile Used for grf callbacks.
Definition: industry_map.h:264
SetWaterClass
static void SetWaterClass(TileIndex t, WaterClass wc)
Set the water class at a tile.
Definition: water_map.h:118
GetCleanIndustryGfx
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:125
MakeIndustry
static void MakeIndustry(TileIndex t, IndustryID index, IndustryGfx gfx, uint8 random, WaterClass wc)
Make the given tile an industry tile.
Definition: industry_map.h:278
Tile::m3
byte m3
General purpose.
Definition: map_type.h:22
Tile::m4
byte m4
General purpose.
Definition: map_type.h:23
_m
Tile * _m
Tiles of the map.
Definition: map.cpp:30
GetTranslatedIndustryTileID
static IndustryGfx GetTranslatedIndustryTileID(IndustryGfx gfx)
Do industry gfx ID translation for NewGRFs.
Definition: industrytype.h:194