OpenTTD Source 20260218-master-g2123fca5ea
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef INDUSTRY_MAP_H
11#define INDUSTRY_MAP_H
12
13#include "industrytype.h"
14#include "water_map.h"
15
16
22enum IndustryGraphics : uint8_t {
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_QUARRY = 165,
53 GFX_SUGAR_MINE_SIEVE = 174,
55};
56
63inline IndustryID GetIndustryIndex(Tile t)
64{
66 return static_cast<IndustryID>(t.m2());
67}
68
76{
78 return HasBit(t.m1(), 7);
79}
80
81IndustryType GetIndustryType(Tile tile);
82
88inline void SetIndustryCompleted(Tile tile)
89{
90 assert(IsTileType(tile, TileType::Industry));
91 SetBit(tile.m1(), 7);
92}
93
101{
102 assert(IsTileType(tile, TileType::Industry));
103 return IsIndustryCompleted(tile) ? (uint8_t)INDUSTRY_COMPLETED : GB(tile.m1(), 0, 2);
104}
105
112inline void SetIndustryConstructionStage(Tile tile, uint8_t value)
113{
114 assert(IsTileType(tile, TileType::Industry));
115 SB(tile.m1(), 0, 2, value);
116}
117
125inline IndustryGfx GetCleanIndustryGfx(Tile t)
126{
127 assert(IsTileType(t, TileType::Industry));
128 return t.m5() | (GB(t.m6(), 2, 1) << 8);
129}
130
137inline IndustryGfx GetIndustryGfx(Tile t)
138{
139 assert(IsTileType(t, TileType::Industry));
141}
142
149inline void SetIndustryGfx(Tile t, IndustryGfx gfx)
150{
151 assert(IsTileType(t, TileType::Industry));
152 t.m5() = GB(gfx, 0, 8);
153 SB(t.m6(), 2, 1, GB(gfx, 8, 1));
154}
155
163{
164 assert(IsTileType(tile, TileType::Industry));
165 return GB(tile.m1(), 2, 2);
166}
167
174inline void SetIndustryConstructionCounter(Tile tile, uint8_t value)
175{
176 assert(IsTileType(tile, TileType::Industry));
177 SB(tile.m1(), 2, 2, value);
178}
179
188{
189 assert(IsTileType(tile, TileType::Industry));
190 SB(tile.m1(), 0, 4, 0);
191 SB(tile.m1(), 7, 1, 0);
192}
193
200inline uint8_t GetIndustryAnimationLoop(Tile tile)
201{
202 assert(IsTileType(tile, TileType::Industry));
203 return tile.m4();
204}
205
212inline void SetIndustryAnimationLoop(Tile tile, uint8_t count)
213{
214 assert(IsTileType(tile, TileType::Industry));
215 tile.m4() = count;
216}
217
225inline uint8_t GetIndustryRandomBits(Tile tile)
226{
227 assert(IsTileType(tile, TileType::Industry));
228 return tile.m3();
229}
230
238inline void SetIndustryRandomBits(Tile tile, uint8_t bits)
239{
240 assert(IsTileType(tile, TileType::Industry));
241 tile.m3() = bits;
242}
243
251inline IndustryRandomTriggers GetIndustryRandomTriggers(Tile tile)
252{
253 assert(IsTileType(tile, TileType::Industry));
254 return static_cast<IndustryRandomTriggers>(GB(tile.m6(), 3, 3));
255}
256
257
265inline void SetIndustryRandomTriggers(Tile tile, IndustryRandomTriggers triggers)
266{
267 assert(IsTileType(tile, TileType::Industry));
268 SB(tile.m6(), 3, 3, triggers.base());
269}
270
279inline void MakeIndustry(Tile t, IndustryID index, IndustryGfx gfx, uint8_t random, WaterClass wc)
280{
282 t.m1() = 0;
283 t.m2() = index.base();
284 SetIndustryRandomBits(t, random); // m3
285 t.m4() = 0;
286 SetIndustryGfx(t, gfx); // m5, part of m6
287 SetIndustryRandomTriggers(t, {}); // rest of m6
288 SetWaterClass(t, wc);
289 SB(t.m6(), 6, 2, 0);
290 t.m7() = 0;
291 t.m8() = 0;
292}
293
294#endif /* INDUSTRY_MAP_H */
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr Tstorage base() const noexcept
Retrieve the raw value behind this bit set.
Wrapper class to abstract away the way the tiles are stored.
Definition map_func.h:25
uint8_t & m5()
General purpose.
Definition map_func.h:156
uint8_t & m1()
Primarily used for ownership information.
Definition map_func.h:112
uint8_t & m4()
General purpose.
Definition map_func.h:145
uint8_t & m6()
General purpose.
Definition map_func.h:167
uint8_t & m7()
Primarily used for newgrf support.
Definition map_func.h:178
uint8_t & m3()
General purpose.
Definition map_func.h:134
uint16_t & m8()
General purpose.
Definition map_func.h:189
uint16_t & m2()
Primarily used for indices to towns, industries and stations.
Definition map_func.h:123
void SetIndustryCompleted(Tile tile)
Set if the industry that owns the tile as under construction or not.
IndustryGfx GetCleanIndustryGfx(Tile t)
Get the industry graphics ID for the given industry tile as stored in the without translation.
uint8_t GetIndustryRandomBits(Tile tile)
Get the random bits for this tile.
void SetIndustryGfx(Tile t, IndustryGfx gfx)
Set the industry graphics ID for the given industry tile.
void ResetIndustryConstructionStage(Tile tile)
Reset the construction stage counter of the industry, as well as the completion bit.
void SetIndustryConstructionCounter(Tile tile, uint8_t value)
Sets this industry tile's construction counter value.
IndustryGfx GetIndustryGfx(Tile t)
Get the industry graphics ID for the given industry tile.
bool IsIndustryCompleted(Tile t)
Is this industry tile fully built?
IndustryID GetIndustryIndex(Tile t)
Get the industry ID of the given tile.
void SetIndustryRandomBits(Tile tile, uint8_t bits)
Set the random bits for this tile.
uint8_t GetIndustryConstructionCounter(Tile tile)
Returns this industry tile's construction counter value.
void SetIndustryRandomTriggers(Tile tile, IndustryRandomTriggers triggers)
Set the activated triggers bits for this industry tile Used for grf callbacks.
void MakeIndustry(Tile t, IndustryID index, IndustryGfx gfx, uint8_t random, WaterClass wc)
Make the given tile an industry tile.
void SetIndustryAnimationLoop(Tile tile, uint8_t count)
Set the animation loop number.
IndustryRandomTriggers GetIndustryRandomTriggers(Tile tile)
Get the activated triggers bits for this industry tile Used for grf callbacks.
IndustryGraphics
The following enums are indices used to know what to draw for this industry tile.
@ GFX_WATERTILE_SPECIALCHECK
not really a tile, but rather a very special check
void SetIndustryConstructionStage(Tile tile, uint8_t value)
Sets the industry construction stage of the specified tile.
IndustryType GetIndustryType(Tile tile)
Retrieve the type for this industry.
uint8_t GetIndustryAnimationLoop(Tile tile)
Get the animation loop number.
uint8_t GetIndustryConstructionStage(Tile tile)
Returns the industry construction stage of the specified tile.
static const int INDUSTRY_COMPLETED
final stage of industry construction.
Industry type specs.
IndustryGfx GetTranslatedIndustryTileID(IndustryGfx gfx)
Do industry gfx ID translation for NewGRFs.
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
void SetTileType(Tile tile, TileType type)
Set the type of a tile.
Definition tile_map.h:131
@ Industry
Part of an industry.
Definition tile_type.h:57
Map accessors for water tiles.
void SetWaterClass(Tile t, WaterClass wc)
Set the water class at a tile.
Definition water_map.h:126
WaterClass
classes of water (for WaterTileType::Clear water tile type).
Definition water_map.h:39