summaryrefslogtreecommitdiff
path: root/rail_cmd.c
diff options
context:
space:
mode:
authorcelestar <celestar@openttd.org>2005-07-16 23:47:37 +0000
committercelestar <celestar@openttd.org>2005-07-16 23:47:37 +0000
commit9ca761b06534ed191b0624a6c7049db296997a73 (patch)
treeb32b3e56573203f32982f2fc2b3966529a6d1857 /rail_cmd.c
parent64f6839816221873b9a5327fe038533a7d3b8a98 (diff)
downloadopenttd-9ca761b06534ed191b0624a6c7049db296997a73.tar.xz
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
(i.e. spans two height levels) and use it throughout the code. -Codechange: Add CanBuildDepotByTileh to find if a tile is suitable to build a depot on it. Wraps some bitmagic which seems quite unreadable at first glance
Diffstat (limited to 'rail_cmd.c')
-rw-r--r--rail_cmd.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/rail_cmd.c b/rail_cmd.c
index 082d1a633..825a357e8 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -217,7 +217,7 @@ uint GetRailFoundation(uint tileh, uint bits)
static uint32 CheckRailSlope(uint tileh, TrackBits rail_bits, TrackBits existing, TileIndex tile)
{
// never allow building on top of steep tiles
- if (!(tileh & 0x10)) {
+ if (!IsSteepTileh(tileh)) {
rail_bits |= existing;
// don't allow building on the lower side of a coast
@@ -634,7 +634,10 @@ int32 CmdRemoveRailroadTrack(int x, int y, uint32 flags, uint32 p1, uint32 p2)
/** Build a train depot
* @param x,y position of the train depot
* @param p1 rail type
- * @param p2 depot direction (0 through 3), where 0 is NW, 1 is NE, etc.
+ * @param p2 depot direction (0 through 3), where 0 is NE, 1 is SE, 2 is SW, 3 is NW
+ *
+ * @todo When checking for the tile slope,
+ * distingush between "Flat land required" and "land sloped in wrong direction"
*/
int32 CmdBuildTrainDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
@@ -650,8 +653,23 @@ int32 CmdBuildTrainDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (!ValParamRailtype(p1) || p2 > 3) return CMD_ERROR;
tileh = GetTileSlope(tile, NULL);
- if (tileh != 0) {
- if ((!_patches.ainew_active && _is_ai_player) || !_patches.build_on_slopes || (tileh & 0x10 || !((0x4C >> p2) & tileh) ))
+
+ /* Prohibit construction if
+ The tile is non-flat AND
+ 1) The AI is "old-school"
+ 2) build-on-slopes is disabled
+ 3) the tile is steep i.e. spans two height levels
+ 4) the exit points in the wrong direction
+
+ */
+
+ if (tileh != 0 && (
+ (!_patches.ainew_active && _is_ai_player) ||
+ !_patches.build_on_slopes ||
+ IsSteepTileh(tileh) ||
+ !CanBuildDepotByTileh(p2, tileh)
+ )
+ ) {
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
}