2009-08-21 21:21:05 +01: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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 16:11:33 +01:00
|
|
|
/** @file autoslope.h Functions related to autoslope. */
|
2007-09-14 23:35:39 +01:00
|
|
|
|
|
|
|
#ifndef AUTOSLOPE_H
|
|
|
|
#define AUTOSLOPE_H
|
|
|
|
|
2008-09-30 21:51:04 +01:00
|
|
|
#include "company_func.h"
|
2008-04-17 20:10:30 +01:00
|
|
|
#include "depot_func.h"
|
2010-01-15 16:41:15 +00:00
|
|
|
#include "tile_map.h"
|
2007-09-14 23:35:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Autoslope check for tiles with an entrance on an edge.
|
2024-10-22 22:25:07 +01:00
|
|
|
* E.g. depots and bay road-stops.
|
2007-09-14 23:35:39 +01:00
|
|
|
*
|
|
|
|
* The test succeeds if the slope is not steep and at least one corner of the entrance edge is on the TileMaxZ() level.
|
|
|
|
*
|
|
|
|
* @note The test does not check if autoslope is enabled at all.
|
|
|
|
*
|
|
|
|
* @param tile The tile.
|
|
|
|
* @param z_new New TileZ.
|
|
|
|
* @param tileh_new New TileSlope.
|
|
|
|
* @param entrance Entrance edge.
|
|
|
|
* @return true iff terraforming is allowed.
|
|
|
|
*/
|
2024-01-06 11:19:27 +00:00
|
|
|
inline bool AutoslopeCheckForEntranceEdge(TileIndex tile, int z_new, Slope tileh_new, DiagDirection entrance)
|
2007-09-14 23:35:39 +01:00
|
|
|
{
|
2011-11-04 10:30:10 +00:00
|
|
|
if (GetTileMaxZ(tile) != z_new + GetSlopeMaxZ(tileh_new)) return false;
|
2007-09-14 23:35:39 +01:00
|
|
|
return ((tileh_new == SLOPE_FLAT) || CanBuildDepotByTileh(entrance, tileh_new));
|
|
|
|
}
|
|
|
|
|
2024-10-22 22:25:07 +01:00
|
|
|
/**
|
|
|
|
* Autoslope check for tiles with something built along an axis.
|
|
|
|
* E.g. railway stations and drive through road stops.
|
|
|
|
*
|
|
|
|
* The test succeeds if the slope is not steep and at least one corner at either of the entrance edges is on the TileMaxZ() level.
|
|
|
|
*
|
|
|
|
* @note The test does not check if autoslope is enabled at all.
|
|
|
|
*
|
|
|
|
* @param tile The tile.
|
|
|
|
* @param z_new New TileZ.
|
|
|
|
* @param tileh_new New TileSlope.
|
|
|
|
* @param axis The axis.
|
|
|
|
* @return true iff terraforming is allowed.
|
|
|
|
*/
|
|
|
|
inline bool AutoslopeCheckForAxis(TileIndex tile, int z_new, Slope tileh_new, Axis axis)
|
|
|
|
{
|
|
|
|
DiagDirection direction = AxisToDiagDir(axis);
|
|
|
|
return AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, direction) &&
|
|
|
|
AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, ReverseDiagDir(direction));
|
|
|
|
}
|
|
|
|
|
2007-09-14 23:35:39 +01:00
|
|
|
/**
|
2008-09-30 21:39:50 +01:00
|
|
|
* Tests if autoslope is enabled for _current_company.
|
2007-09-14 23:35:39 +01:00
|
|
|
*
|
2009-01-12 17:11:45 +00:00
|
|
|
* Autoslope is disabled for town/industry construction.
|
2007-09-14 23:35:39 +01:00
|
|
|
*
|
|
|
|
* @return true iff autoslope is enabled.
|
|
|
|
*/
|
2024-01-06 11:19:27 +00:00
|
|
|
inline bool AutoslopeEnabled()
|
2007-09-14 23:35:39 +01:00
|
|
|
{
|
2008-05-29 16:13:28 +01:00
|
|
|
return (_settings_game.construction.autoslope &&
|
2009-01-12 17:11:45 +00:00
|
|
|
(_current_company < MAX_COMPANIES ||
|
2008-09-30 21:39:50 +01:00
|
|
|
(_current_company == OWNER_NONE && _game_mode == GM_EDITOR)));
|
2007-09-14 23:35:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* AUTOSLOPE_H */
|