OpenTTD Source 20241224-master-gf74b0cf984
tunnel_map.cpp
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#include "stdafx.h"
11#include "tunnelbridge_map.h"
12
13#include "safeguards.h"
14
15
23{
26 int z = GetTileZ(tile);
27
28 dir = ReverseDiagDir(dir);
29 do {
30 tile += delta;
31 } while (
32 !IsTunnelTile(tile) ||
33 GetTunnelBridgeDirection(tile) != dir ||
34 GetTileZ(tile) != z
35 );
36
37 return tile;
38}
39
40
49{
51 int height;
52
53 do {
54 tile -= delta;
55 if (!IsValidTile(tile)) return false;
56 height = GetTileZ(tile);
57 } while (z < height);
58
59 return z == height && IsTunnelTile(tile) && GetTunnelBridgeDirection(tile) == dir;
60}
61
68bool IsTunnelInWay(TileIndex tile, int z)
69{
70 return IsTunnelInWayDir(tile, z, (TileX(tile) > (Map::MaxX() / 2)) ? DIAGDIR_NE : DIAGDIR_SW) ||
71 IsTunnelInWayDir(tile, z, (TileY(tile) > (Map::MaxY() / 2)) ? DIAGDIR_NW : DIAGDIR_SE);
72}
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
DiagDirection
Enumeration for diagonal directions.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
@ DIAGDIR_NW
Northwest.
@ DIAGDIR_SE
Southeast.
@ DIAGDIR_SW
Southwest.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:425
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:415
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition map_func.h:567
int32_t TileIndexDiff
An offset value between two tiles.
Definition map_type.h:23
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition map_func.h:306
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition map_func.h:297
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
Definition tile_map.cpp:116
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition tile_map.h:161
bool IsTunnelInWay(TileIndex tile, int z)
Is there a tunnel in the way in any direction?
bool IsTunnelInWayDir(TileIndex tile, int z, DiagDirection dir)
Is there a tunnel in the way in the given direction?
TileIndex GetOtherTunnelEnd(TileIndex tile)
Gets the other end of the tunnel.
bool IsTunnelTile(Tile t)
Is this a tunnel (entrance)?
Definition tunnel_map.h:34
Functions that have tunnels and bridges in common.
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.