OpenTTD Source: src/autoslope.h Source File

OpenTTD Source 15.0-RC2

autoslope.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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef AUTOSLOPE_H
11#define AUTOSLOPE_H
12
13#include "company_func.h"
14#include "depot_func.h"
15#include "tile_map.h"
16
31 inline bool AutoslopeCheckForEntranceEdge(TileIndex tile, int z_new, Slope tileh_new, DiagDirection entrance)
32{
33 if (GetTileMaxZ(tile) != z_new + GetSlopeMaxZ(tileh_new)) return false;
34 return ((tileh_new == SLOPE_FLAT) || CanBuildDepotByTileh(entrance, tileh_new));
35}
36
51 inline bool AutoslopeCheckForAxis(TileIndex tile, int z_new, Slope tileh_new, Axis axis)
52{
53 DiagDirection direction = AxisToDiagDir(axis);
54 return AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, direction) &&
55 AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, ReverseDiagDir(direction));
56}
57
65 inline bool AutoslopeEnabled()
66{
67 return (_settings_game.construction.autoslope &&
68 (_current_company < MAX_COMPANIES ||
69 (_current_company == OWNER_NONE && _game_mode == GM_EDITOR)));
70}
71
72#endif /* AUTOSLOPE_H */
AutoslopeCheckForAxis
bool AutoslopeCheckForAxis(TileIndex tile, int z_new, Slope tileh_new, Axis axis)
Autoslope check for tiles with something built along an axis.
Definition autoslope.h:51
AutoslopeCheckForEntranceEdge
bool AutoslopeCheckForEntranceEdge(TileIndex tile, int z_new, Slope tileh_new, DiagDirection entrance)
Autoslope check for tiles with an entrance on an edge.
Definition autoslope.h:31
AutoslopeEnabled
bool AutoslopeEnabled()
Tests if autoslope is enabled for _current_company.
Definition autoslope.h:65
_current_company
CompanyID _current_company
Company currently doing an action.
Definition company_cmd.cpp:56
company_func.h
Functions related to companies.
OWNER_NONE
static constexpr Owner OWNER_NONE
The tile has no ownership.
Definition company_type.h:26
depot_func.h
Functions related to depots.
CanBuildDepotByTileh
bool CanBuildDepotByTileh(DiagDirection direction, Slope tileh)
Find out if the slope of the tile is suitable to build a depot of given direction.
Definition depot_func.h:27
ReverseDiagDir
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Definition direction_func.h:118
AxisToDiagDir
DiagDirection AxisToDiagDir(Axis a)
Converts an Axis to a DiagDirection.
Definition direction_func.h:232
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition direction_type.h:123
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition direction_type.h:78
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
GetSlopeMaxZ
static constexpr int GetSlopeMaxZ(Slope s)
Returns the height of the highest corner of a slope relative to TileZ (= minimal height)
Definition slope_func.h:160
Slope
Slope
Enumeration for the slope-type.
Definition slope_type.h:48
SLOPE_FLAT
@ SLOPE_FLAT
a flat tile
Definition slope_type.h:49
ConstructionSettings::autoslope
bool autoslope
allow terraforming under things
Definition settings_type.h:412
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition settings_type.h:635
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
GetTileMaxZ
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
Definition tile_map.cpp:136
tile_map.h
Map writing/reading functions for tiles.