OpenTTD

object_map.h
Go to the documentation of this file.
1 /* $Id: object_map.h 26878 2014-09-21 11:23:33Z rubidium $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #ifndef OBJECT_MAP_H
13 #define OBJECT_MAP_H
14
15 #include "water_map.h"
16 #include "object_type.h"
17
18 ObjectType GetObjectType(TileIndex t);
19
27 static inline bool IsObjectType(TileIndex t, ObjectType type)
28 {
29 return GetObjectType(t) == type;
30 }
31
38 static inline bool IsObjectTypeTile(TileIndex t, ObjectType type)
39 {
40 return IsTileType(t, MP_OBJECT) && GetObjectType(t) == type;
41 }
42
49 static inline ObjectID GetObjectIndex(TileIndex t)
50 {
51 assert(IsTileType(t, MP_OBJECT));
52 return _m[t].m2 | _m[t].m5 << 16;
53 }
54
61 static inline byte GetObjectRandomBits(TileIndex t)
62 {
63 assert(IsTileType(t, MP_OBJECT));
64 return _m[t].m3;
65 }
66
67
76 static inline void MakeObject(TileIndex t, Owner o, ObjectID index, WaterClass wc, byte random)
77 {
78 SetTileType(t, MP_OBJECT);
79 SetTileOwner(t, o);
80 SetWaterClass(t, wc);
81 _m[t].m2 = index;
82 _m[t].m3 = random;
83 _m[t].m4 = 0;
84 _m[t].m5 = index >> 16;
85 SB(_me[t].m6, 2, 4, 0);
86 _me[t].m7 = 0;
87 }
88
89 #endif /* OBJECT_MAP_H */
SetTileOwner
static void SetTileOwner(TileIndex tile, Owner owner)
Sets the owner of a tile.
Definition: tile_map.h:191
TileExtended::m7
byte m7
Primarily used for newgrf support.
Definition: map_type.h:37
Tile::m2
uint16 m2
Primarily used for indices to towns, industries and stations.
Definition: map_type.h:22
GetObjectRandomBits
static byte GetObjectRandomBits(TileIndex t)
Get the random bits of this tile.
Definition: object_map.h:61
_m
Tile * _m
Tiles of the map.
Definition: map.cpp:32
MP_OBJECT
Contains objects such as transmitters and owned land.
Definition: tile_type.h:53
SetWaterClass
static void SetWaterClass(TileIndex t, WaterClass wc)
Set the water class at a tile.
Definition: water_map.h:118
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:60
IsObjectType
static bool IsObjectType(TileIndex t, ObjectType type)
Check whether the object on a tile is of a specific type.
Definition: object_map.h:27
object_type.h
Types related to object tiles.
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
Definition: tile_map.h:143
WaterClass
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition: water_map.h:49
water_map.h
Map accessors for water tiles.
_me
TileExtended * _me
Extended Tiles of the map.
Definition: map.cpp:33
Tile::m5
byte m5
General purpose.
Definition: map_type.h:26
ObjectType
uint16 ObjectType
Types of objects.
Definition: object_type.h:16
ObjectID
uint32 ObjectID
Unique identifier for an object.
Definition: object_type.h:31
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
SetTileType
static void SetTileType(TileIndex tile, TileType type)
Set the type of a tile.
Definition: tile_map.h:124
GetObjectIndex
static ObjectID GetObjectIndex(TileIndex t)
Get the index of which object this tile is attached to.
Definition: object_map.h:49
GetObjectType
ObjectType GetObjectType(TileIndex t)
Gets the ObjectType of the given object tile.
Definition: object_cmd.cpp:63
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:20
Tile::m3
byte m3
General purpose.
Definition: map_type.h:24
MakeObject
static void MakeObject(TileIndex t, Owner o, ObjectID index, WaterClass wc, byte random)
Make an Object tile.
Definition: object_map.h:76
IsObjectTypeTile
static bool IsObjectTypeTile(TileIndex t, ObjectType type)
Check whether a tile is a object tile of a specific type.
Definition: object_map.h:38
Tile::m4
byte m4
General purpose.
Definition: map_type.h:25