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 
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 
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 {
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 */
static void SetTileOwner(TileIndex tile, Owner owner)
Sets the owner of a tile.
Definition: tile_map.h:191
byte m7
Primarily used for newgrf support.
Definition: map_type.h:37
uint16 m2
Primarily used for indices to towns, industries and stations.
Definition: map_type.h:22
static byte GetObjectRandomBits(TileIndex t)
Get the random bits of this tile.
Definition: object_map.h:61
Tile * _m
Tiles of the map.
Definition: map.cpp:32
Contains objects such as transmitters and owned land.
Definition: tile_type.h:53
static void SetWaterClass(TileIndex t, WaterClass wc)
Set the water class at a tile.
Definition: water_map.h:118
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.
static bool IsObjectType(TileIndex t, ObjectType type)
Check whether the object on a tile is of a specific type.
Definition: object_map.h:27
Types related to object tiles.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
Definition: tile_map.h:143
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition: water_map.h:49
Map accessors for water tiles.
TileExtended * _me
Extended Tiles of the map.
Definition: map.cpp:33
byte m5
General purpose.
Definition: map_type.h:26
uint16 ObjectType
Types of objects.
Definition: object_type.h:16
uint32 ObjectID
Unique identifier for an object.
Definition: object_type.h:31
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
static void SetTileType(TileIndex tile, TileType type)
Set the type of a tile.
Definition: tile_map.h:124
static ObjectID GetObjectIndex(TileIndex t)
Get the index of which object this tile is attached to.
Definition: object_map.h:49
ObjectType GetObjectType(TileIndex t)
Gets the ObjectType of the given object tile.
Definition: object_cmd.cpp:63
Owner
Enum for all companies/owners.
Definition: company_type.h:20
byte m3
General purpose.
Definition: map_type.h:24
static void MakeObject(TileIndex t, Owner o, ObjectID index, WaterClass wc, byte random)
Make an Object tile.
Definition: object_map.h:76
static bool IsObjectTypeTile(TileIndex t, ObjectType type)
Check whether a tile is a object tile of a specific type.
Definition: object_map.h:38
byte m4
General purpose.
Definition: map_type.h:25