2009-08-21 22:21:05 +02:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2010-08-08 12:59:30 +02:00
|
|
|
/** @file object_map.h Map accessors for object tiles. */
|
2007-04-04 06:08:47 +02:00
|
|
|
|
2010-08-08 12:59:30 +02:00
|
|
|
#ifndef OBJECT_MAP_H
|
|
|
|
#define OBJECT_MAP_H
|
2006-09-28 20:42:35 +02:00
|
|
|
|
2010-08-11 16:14:06 +02:00
|
|
|
#include "water_map.h"
|
2010-08-08 12:59:30 +02:00
|
|
|
#include "object_type.h"
|
2006-03-23 21:47:56 +01:00
|
|
|
|
2023-01-21 16:40:28 +01:00
|
|
|
ObjectType GetObjectType(Tile t);
|
2006-03-23 21:47:56 +01:00
|
|
|
|
2010-08-13 14:45:26 +02:00
|
|
|
/**
|
2013-10-12 18:30:22 +02:00
|
|
|
* Check whether the object on a tile is of a specific type.
|
|
|
|
* @param t Tile to test.
|
|
|
|
* @param type Type to test.
|
2010-08-08 12:59:30 +02:00
|
|
|
* @pre IsTileType(t, MP_OBJECT)
|
2013-10-12 18:30:22 +02:00
|
|
|
* @return True if type matches.
|
2007-04-18 20:20:31 +02:00
|
|
|
*/
|
2024-01-06 12:19:27 +01:00
|
|
|
inline bool IsObjectType(Tile t, ObjectType type)
|
2006-03-23 21:47:56 +01:00
|
|
|
{
|
2013-10-12 18:30:22 +02:00
|
|
|
return GetObjectType(t) == type;
|
2006-03-23 21:47:56 +01:00
|
|
|
}
|
|
|
|
|
2007-04-18 20:20:31 +02:00
|
|
|
/**
|
2013-10-12 18:30:22 +02:00
|
|
|
* Check whether a tile is a object tile of a specific type.
|
|
|
|
* @param t Tile to test.
|
|
|
|
* @param type Type to test.
|
|
|
|
* @return True if type matches.
|
2007-04-18 20:20:31 +02:00
|
|
|
*/
|
2024-01-06 12:19:27 +01:00
|
|
|
inline bool IsObjectTypeTile(Tile t, ObjectType type)
|
2006-03-23 21:47:56 +01:00
|
|
|
{
|
2013-10-12 18:30:22 +02:00
|
|
|
return IsTileType(t, MP_OBJECT) && GetObjectType(t) == type;
|
2006-03-23 21:47:56 +01:00
|
|
|
}
|
|
|
|
|
2007-04-18 20:20:31 +02:00
|
|
|
/**
|
2013-10-12 18:30:22 +02:00
|
|
|
* Get the index of which object this tile is attached to.
|
|
|
|
* @param t the tile
|
2010-08-08 12:59:30 +02:00
|
|
|
* @pre IsTileType(t, MP_OBJECT)
|
2013-10-12 18:30:22 +02:00
|
|
|
* @return The ObjectID of the object.
|
2007-04-18 20:20:31 +02:00
|
|
|
*/
|
2024-01-06 12:19:27 +01:00
|
|
|
inline ObjectID GetObjectIndex(Tile t)
|
2007-03-08 15:34:32 +01:00
|
|
|
{
|
2010-08-08 12:59:30 +02:00
|
|
|
assert(IsTileType(t, MP_OBJECT));
|
2023-01-21 16:40:28 +01:00
|
|
|
return t.m2() | t.m5() << 16;
|
2007-03-08 15:34:32 +01:00
|
|
|
}
|
|
|
|
|
2010-08-28 00:26:21 +02:00
|
|
|
/**
|
|
|
|
* Get the random bits of this tile.
|
|
|
|
* @param t The tile to get the bits for.
|
|
|
|
* @pre IsTileType(t, MP_OBJECT)
|
|
|
|
* @return The random bits.
|
|
|
|
*/
|
2024-01-06 12:19:27 +01:00
|
|
|
inline byte GetObjectRandomBits(Tile t)
|
2010-08-28 00:26:21 +02:00
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_OBJECT));
|
2023-01-21 16:40:28 +01:00
|
|
|
return t.m3();
|
2010-08-28 00:26:21 +02:00
|
|
|
}
|
|
|
|
|
2006-03-31 11:09:26 +02:00
|
|
|
|
2007-04-18 20:20:31 +02:00
|
|
|
/**
|
2010-08-08 12:59:30 +02:00
|
|
|
* Make an Object tile.
|
|
|
|
* @param t The tile to make and object tile.
|
2010-08-03 10:09:45 +02:00
|
|
|
* @param o The new owner of the tile.
|
2010-08-13 14:45:26 +02:00
|
|
|
* @param index Index to the object.
|
2013-01-08 23:46:42 +01:00
|
|
|
* @param wc Water class for this object.
|
2010-08-28 00:26:21 +02:00
|
|
|
* @param random Random data to store on the tile
|
2007-04-18 20:20:31 +02:00
|
|
|
*/
|
2024-01-06 12:19:27 +01:00
|
|
|
inline void MakeObject(Tile t, Owner o, ObjectID index, WaterClass wc, byte random)
|
2006-03-23 21:47:56 +01:00
|
|
|
{
|
2010-08-08 12:59:30 +02:00
|
|
|
SetTileType(t, MP_OBJECT);
|
2006-03-23 21:47:56 +01:00
|
|
|
SetTileOwner(t, o);
|
2010-08-11 16:14:06 +02:00
|
|
|
SetWaterClass(t, wc);
|
2023-01-21 16:40:28 +01:00
|
|
|
t.m2() = index;
|
|
|
|
t.m3() = random;
|
|
|
|
t.m4() = 0;
|
|
|
|
t.m5() = index >> 16;
|
|
|
|
SB(t.m6(), 2, 4, 0);
|
|
|
|
t.m7() = 0;
|
2006-03-23 21:47:56 +01:00
|
|
|
}
|
|
|
|
|
2010-08-08 12:59:30 +02:00
|
|
|
#endif /* OBJECT_MAP_H */
|