(svn r28004) -Update from Eints:
[openttd.git] / src / object_map.h
blob1aaf9843453e8a4e6d3ef8312b88bcf233d860c2
1 /* $Id$ */
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 */
10 /** @file object_map.h Map accessors for object tiles. */
12 #ifndef OBJECT_MAP_H
13 #define OBJECT_MAP_H
15 #include "water_map.h"
16 #include "object_type.h"
18 ObjectType GetObjectType(TileIndex t);
20 /**
21 * Check whether the object on a tile is of a specific type.
22 * @param t Tile to test.
23 * @param type Type to test.
24 * @pre IsTileType(t, MP_OBJECT)
25 * @return True if type matches.
27 static inline bool IsObjectType(TileIndex t, ObjectType type)
29 return GetObjectType(t) == type;
32 /**
33 * Check whether a tile is a object tile of a specific type.
34 * @param t Tile to test.
35 * @param type Type to test.
36 * @return True if type matches.
38 static inline bool IsObjectTypeTile(TileIndex t, ObjectType type)
40 return IsTileType(t, MP_OBJECT) && GetObjectType(t) == type;
43 /**
44 * Get the index of which object this tile is attached to.
45 * @param t the tile
46 * @pre IsTileType(t, MP_OBJECT)
47 * @return The ObjectID of the object.
49 static inline ObjectID GetObjectIndex(TileIndex t)
51 assert(IsTileType(t, MP_OBJECT));
52 return _m[t].m2 | _m[t].m5 << 16;
55 /**
56 * Get the random bits of this tile.
57 * @param t The tile to get the bits for.
58 * @pre IsTileType(t, MP_OBJECT)
59 * @return The random bits.
61 static inline byte GetObjectRandomBits(TileIndex t)
63 assert(IsTileType(t, MP_OBJECT));
64 return _m[t].m3;
68 /**
69 * Make an Object tile.
70 * @param t The tile to make and object tile.
71 * @param o The new owner of the tile.
72 * @param index Index to the object.
73 * @param wc Water class for this object.
74 * @param random Random data to store on the tile
76 static inline void MakeObject(TileIndex t, Owner o, ObjectID index, WaterClass wc, byte random)
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;
89 #endif /* OBJECT_MAP_H */