OpenTTD Source 20260820-master-g39da062c0c
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
23inline IndustryID GetIndustryIndex(Tile t)
24{
26 return static_cast<IndustryID>(t.m2());
27}
28
36{
38 return HasBit(t.m1(), 7);
39}
40
41IndustryType GetIndustryType(Tile tile);
42
48inline void SetIndustryCompleted(Tile tile)
49{
50 assert(IsTileType(tile, TileType::Industry));
51 SetBit(tile.m1(), 7);
52}
53
61{
62 assert(IsTileType(tile, TileType::Industry));
63 return IsIndustryCompleted(tile) ? (uint8_t)INDUSTRY_COMPLETED : GB(tile.m1(), 0, 2);
64}
65
72inline void SetIndustryConstructionStage(Tile tile, uint8_t value)
73{
74 assert(IsTileType(tile, TileType::Industry));
75 SB(tile.m1(), 0, 2, value);
76}
77
85inline IndustryGfx GetCleanIndustryGfx(Tile t)
86{
88 return t.m5() | (GB(t.m6(), 2, 1) << 8);
89}
90
97inline IndustryGfx GetIndustryGfx(Tile t)
98{
101}
102
109inline void SetIndustryGfx(Tile t, IndustryGfx gfx)
110{
111 assert(IsTileType(t, TileType::Industry));
112 t.m5() = GB(gfx, 0, 8);
113 SB(t.m6(), 2, 1, GB(gfx, 8, 1));
114}
115
123{
124 assert(IsTileType(tile, TileType::Industry));
125 return GB(tile.m1(), 2, 2);
126}
127
134inline void SetIndustryConstructionCounter(Tile tile, uint8_t value)
135{
136 assert(IsTileType(tile, TileType::Industry));
137 SB(tile.m1(), 2, 2, value);
138}
139
148{
149 assert(IsTileType(tile, TileType::Industry));
150 SB(tile.m1(), 0, 4, 0);
151 SB(tile.m1(), 7, 1, 0);
152}
153
160inline uint8_t GetIndustryAnimationLoop(Tile tile)
161{
162 assert(IsTileType(tile, TileType::Industry));
163 return tile.m4();
164}
165
172inline void SetIndustryAnimationLoop(Tile tile, uint8_t count)
173{
174 assert(IsTileType(tile, TileType::Industry));
175 tile.m4() = count;
176}
177
185inline uint8_t GetIndustryRandomBits(Tile tile)
186{
187 assert(IsTileType(tile, TileType::Industry));
188 return tile.m3();
189}
190
198inline void SetIndustryRandomBits(Tile tile, uint8_t bits)
199{
200 assert(IsTileType(tile, TileType::Industry));
201 tile.m3() = bits;
202}
203
212{
213 assert(IsTileType(tile, TileType::Industry));
214 return static_cast<IndustryRandomTriggers>(GB(tile.m6(), 3, 3));
215}
216
217
226{
227 assert(IsTileType(tile, TileType::Industry));
228 SB(tile.m6(), 3, 3, triggers.base());
229}
230
239inline void MakeIndustry(Tile t, IndustryID index, IndustryGfx gfx, uint8_t random, WaterClass wc)
240{
242 t.m1() = 0;
243 t.m2() = index.base();
244 SetIndustryRandomBits(t, random); // m3
245 t.m4() = 0;
246 SetIndustryGfx(t, gfx); // m5, part of m6
247 SetIndustryRandomTriggers(t, {}); // rest of m6
248 SetWaterClass(t, wc);
249 SB(t.m6(), 6, 2, 0);
250 t.m7() = 0;
251 t.m8() = 0;
252}
253
254#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.
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.
EnumBitSet< IndustryRandomTrigger, uint8_t > IndustryRandomTriggers
Bitset of IndustryRandomTrigger elements.
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