OpenTTD Source  20241108-master-g80f628063a
object_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 OBJECT_MAP_H
11 #define OBJECT_MAP_H
12 
13 #include "water_map.h"
14 #include "object_type.h"
15 
17 
25 inline bool IsObjectType(Tile t, ObjectType type)
26 {
27  return GetObjectType(t) == type;
28 }
29 
36 inline bool IsObjectTypeTile(Tile t, ObjectType type)
37 {
38  return IsTileType(t, MP_OBJECT) && GetObjectType(t) == type;
39 }
40 
48 {
49  assert(IsTileType(t, MP_OBJECT));
50  return t.m2() | t.m5() << 16;
51 }
52 
59 inline uint8_t GetObjectRandomBits(Tile t)
60 {
61  assert(IsTileType(t, MP_OBJECT));
62  return t.m3();
63 }
64 
65 
74 inline void MakeObject(Tile t, Owner o, ObjectID index, WaterClass wc, uint8_t random)
75 {
77  SetTileOwner(t, o);
78  SetWaterClass(t, wc);
79  t.m2() = index;
80  t.m3() = random;
81  t.m4() = 0;
82  t.m5() = index >> 16;
83  SB(t.m6(), 2, 4, 0);
84  t.m7() = 0;
85 }
86 
87 #endif /* OBJECT_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.
Wrapper class to abstract away the way the tiles are stored.
Definition: map_func.h:25
debug_inline uint8_t & m7()
Primarily used for newgrf support.
Definition: map_func.h:185
debug_inline uint8_t & m5()
General purpose.
Definition: map_func.h:161
debug_inline uint8_t & m4()
General purpose.
Definition: map_func.h:149
debug_inline uint16_t & m2()
Primarily used for indices to towns, industries and stations.
Definition: map_func.h:125
debug_inline uint8_t & m6()
General purpose.
Definition: map_func.h:173
debug_inline uint8_t & m3()
General purpose.
Definition: map_func.h:137
Owner
Enum for all companies/owners.
Definition: company_type.h:18
void MakeObject(Tile t, Owner o, ObjectID index, WaterClass wc, uint8_t random)
Make an Object tile.
Definition: object_map.h:74
bool IsObjectTypeTile(Tile t, ObjectType type)
Check whether a tile is a object tile of a specific type.
Definition: object_map.h:36
uint8_t GetObjectRandomBits(Tile t)
Get the random bits of this tile.
Definition: object_map.h:59
ObjectType GetObjectType(Tile t)
Gets the ObjectType of the given object tile.
Definition: object_cmd.cpp:66
bool IsObjectType(Tile t, ObjectType type)
Check whether the object on a tile is of a specific type.
Definition: object_map.h:25
ObjectID GetObjectIndex(Tile t)
Get the index of which object this tile is attached to.
Definition: object_map.h:47
Types related to object tiles.
uint16_t ObjectType
Types of objects.
Definition: object_type.h:14
uint32_t ObjectID
Unique identifier for an object.
Definition: object_type.h:28
void SetTileType(Tile tile, TileType type)
Set the type of a tile.
Definition: tile_map.h:131
void SetTileOwner(Tile tile, Owner owner)
Sets the owner of a tile.
Definition: tile_map.h:198
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
@ MP_OBJECT
Contains objects such as transmitters and owned land.
Definition: tile_type.h:58
Map accessors for water tiles.
void SetWaterClass(Tile t, WaterClass wc)
Set the water class at a tile.
Definition: water_map.h:124
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition: water_map.h:39