Fix #10490: Allow ships to exit depots if another is not moving at the exit point...
[openttd-github.git] / src / object_map.h
blobae5e73d963f52fd02cde53ee249b7a10f20dba39
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 */
8 /** @file object_map.h Map accessors for object tiles. */
10 #ifndef OBJECT_MAP_H
11 #define OBJECT_MAP_H
13 #include "water_map.h"
14 #include "object_type.h"
16 ObjectType GetObjectType(Tile t);
18 /**
19 * Check whether the object on a tile is of a specific type.
20 * @param t Tile to test.
21 * @param type Type to test.
22 * @pre IsTileType(t, MP_OBJECT)
23 * @return True if type matches.
25 inline bool IsObjectType(Tile t, ObjectType type)
27 return GetObjectType(t) == type;
30 /**
31 * Check whether a tile is a object tile of a specific type.
32 * @param t Tile to test.
33 * @param type Type to test.
34 * @return True if type matches.
36 inline bool IsObjectTypeTile(Tile t, ObjectType type)
38 return IsTileType(t, MP_OBJECT) && GetObjectType(t) == type;
41 /**
42 * Get the index of which object this tile is attached to.
43 * @param t the tile
44 * @pre IsTileType(t, MP_OBJECT)
45 * @return The ObjectID of the object.
47 inline ObjectID GetObjectIndex(Tile t)
49 assert(IsTileType(t, MP_OBJECT));
50 return t.m2() | t.m5() << 16;
53 /**
54 * Get the random bits of this tile.
55 * @param t The tile to get the bits for.
56 * @pre IsTileType(t, MP_OBJECT)
57 * @return The random bits.
59 inline byte GetObjectRandomBits(Tile t)
61 assert(IsTileType(t, MP_OBJECT));
62 return t.m3();
66 /**
67 * Make an Object tile.
68 * @param t The tile to make and object tile.
69 * @param o The new owner of the tile.
70 * @param index Index to the object.
71 * @param wc Water class for this object.
72 * @param random Random data to store on the tile
74 inline void MakeObject(Tile t, Owner o, ObjectID index, WaterClass wc, byte random)
76 SetTileType(t, MP_OBJECT);
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;
87 #endif /* OBJECT_MAP_H */