OpenTTD Source: src/object_map.h Source File

OpenTTD Source 15.0-beta1

object_map.h
Go to the documentation of this file.
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 */
7
10#ifndef OBJECT_MAP_H
11#define OBJECT_MAP_H
12
13#include "water_map.h"
14#include "object_type.h"
15
16 ObjectType GetObjectType(Tile t);
17
25 inline bool IsObjectType(Tile t, ObjectType type)
26{
27 return GetObjectType(t) == type;
28}
29
36 inline bool IsObjectTypeTile(Tile t, ObjectType type)
37{
38 return IsTileType(t, MP_OBJECT) && GetObjectType(t) == type;
39}
40
47 inline ObjectID GetObjectIndex(Tile t)
48{
49 assert(IsTileType(t, MP_OBJECT));
50 return t.m2() | t.m5() << 16;
51}
52
59 inline uint8_t GetObjectRandomBits(Tile t)
60{
61 assert(IsTileType(t, MP_OBJECT));
62 return t.m3();
63}
64
65
74 inline void MakeObject(Tile t, Owner o, ObjectID index, WaterClass wc, uint8_t random)
75{
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;
85}
86
87#endif /* OBJECT_MAP_H */
SB
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
Definition bitmath_func.hpp:58
Tile
Wrapper class to abstract away the way the tiles are stored.
Definition map_func.h:25
Tile::m2
debug_inline uint16_t & m2()
Primarily used for indices to towns, industries and stations.
Definition map_func.h:125
Tile::m7
debug_inline uint8_t & m7()
Primarily used for newgrf support.
Definition map_func.h:185
Tile::m4
debug_inline uint8_t & m4()
General purpose.
Definition map_func.h:149
Tile::m6
debug_inline uint8_t & m6()
General purpose.
Definition map_func.h:173
Tile::m3
debug_inline uint8_t & m3()
General purpose.
Definition map_func.h:137
Tile::m5
debug_inline uint8_t & m5()
General purpose.
Definition map_func.h:161
Owner
Owner
Enum for all companies/owners.
Definition company_type.h:18
MakeObject
void MakeObject(Tile t, Owner o, ObjectID index, WaterClass wc, uint8_t random)
Make an Object tile.
Definition object_map.h:74
IsObjectTypeTile
bool IsObjectTypeTile(Tile t, ObjectType type)
Check whether a tile is a object tile of a specific type.
Definition object_map.h:36
GetObjectRandomBits
uint8_t GetObjectRandomBits(Tile t)
Get the random bits of this tile.
Definition object_map.h:59
GetObjectType
ObjectType GetObjectType(Tile t)
Gets the ObjectType of the given object tile.
Definition object_cmd.cpp:66
IsObjectType
bool IsObjectType(Tile t, ObjectType type)
Check whether the object on a tile is of a specific type.
Definition object_map.h:25
GetObjectIndex
ObjectID GetObjectIndex(Tile t)
Get the index of which object this tile is attached to.
Definition object_map.h:47
object_type.h
Types related to object tiles.
ObjectType
uint16_t ObjectType
Types of objects.
Definition object_type.h:14
ObjectID
uint32_t ObjectID
Unique identifier for an object.
Definition object_type.h:28
SetTileType
void SetTileType(Tile tile, TileType type)
Set the type of a tile.
Definition tile_map.h:131
SetTileOwner
void SetTileOwner(Tile tile, Owner owner)
Sets the owner of a tile.
Definition tile_map.h:198
IsTileType
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
MP_OBJECT
@ MP_OBJECT
Contains objects such as transmitters and owned land.
Definition tile_type.h:58
water_map.h
Map accessors for water tiles.
SetWaterClass
void SetWaterClass(Tile t, WaterClass wc)
Set the water class at a tile.
Definition water_map.h:124
WaterClass
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition water_map.h:39