OpenTTD Source: src/object_map.h Source File

OpenTTD Source 13.1

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
16 ObjectType GetObjectType(TileIndex t);
17
25 static inline bool IsObjectType(TileIndex t, ObjectType type)
26 {
27 return GetObjectType(t) == type;
28 }
29
36 static inline bool IsObjectTypeTile(TileIndex t, ObjectType type)
37 {
38 return IsTileType(t, MP_OBJECT) && GetObjectType(t) == type;
39 }
40
47 static inline ObjectID GetObjectIndex(TileIndex t)
48 {
49 assert(IsTileType(t, MP_OBJECT));
50 return _m[t].m2 | _m[t].m5 << 16;
51 }
52
59 static inline byte GetObjectRandomBits(TileIndex t)
60 {
61 assert(IsTileType(t, MP_OBJECT));
62 return _m[t].m3;
63 }
64
65
74 static inline void MakeObject(TileIndex t, Owner o, ObjectID index, WaterClass wc, byte random)
75 {
76 SetTileType(t, MP_OBJECT);
77 SetTileOwner(t, o);
78 SetWaterClass(t, wc);
79 _m[t].m2 = index;
80 _m[t].m3 = random;
81 _m[t].m4 = 0;
82 _m[t].m5 = index >> 16;
83 SB(_me[t].m6, 2, 4, 0);
84 _me[t].m7 = 0;
85 }
86
87 #endif /* OBJECT_MAP_H */
SetTileType
static void SetTileType(TileIndex tile, TileType type)
Set the type of a tile.
Definition: tile_map.h:131
GetObjectType
ObjectType GetObjectType(TileIndex t)
Gets the ObjectType of the given object tile.
Definition: object_cmd.cpp:64
_me
TileExtended * _me
Extended Tiles of the map.
Definition: map.cpp:31
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
Tile::m2
uint16 m2
Primarily used for indices to towns, industries and stations.
Definition: map_type.h:20
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
WaterClass
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition: water_map.h:47
ObjectType
uint16 ObjectType
Types of objects.
Definition: object_type.h:14
MP_OBJECT
@ MP_OBJECT
Contains objects such as transmitters and owned land.
Definition: tile_type.h:58
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
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
IsObjectTypeTile
static bool IsObjectTypeTile(TileIndex t, ObjectType type)
Check whether a tile is a object tile of a specific type.
Definition: object_map.h:36
MakeObject
static void MakeObject(TileIndex t, Owner o, ObjectID index, WaterClass wc, byte random)
Make an Object tile.
Definition: object_map.h:74
ObjectID
uint32 ObjectID
Unique identifier for an object.
Definition: object_type.h:29
GetObjectRandomBits
static byte GetObjectRandomBits(TileIndex t)
Get the random bits of this tile.
Definition: object_map.h:59
TileExtended::m7
byte m7
Primarily used for newgrf support.
Definition: map_type.h:35
GetObjectIndex
static ObjectID GetObjectIndex(TileIndex t)
Get the index of which object this tile is attached to.
Definition: object_map.h:47
SetTileOwner
static void SetTileOwner(TileIndex tile, Owner owner)
Sets the owner of a tile.
Definition: tile_map.h:198
SetWaterClass
static void SetWaterClass(TileIndex t, WaterClass wc)
Set the water class at a tile.
Definition: water_map.h:129
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
IsObjectType
static bool IsObjectType(TileIndex t, ObjectType type)
Check whether the object on a tile is of a specific type.
Definition: object_map.h:25
object_type.h