src/autoslope.h
author rubidium
Sat, 06 Oct 2007 21:16:00 +0000
branchNewGRF_ports
changeset 6870 ca3fd1fbe311
child 6872 1c4a4a609f85
permissions -rw-r--r--
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
     1
/* $Id$ */
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
     2
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
     3
/** @file autoslope.h */
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
     4
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
     5
#ifndef AUTOSLOPE_H
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
     6
#define AUTOSLOPE_H
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
     7
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
     8
#include "depot.h"
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
     9
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    10
/**
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    11
 * Autoslope check for tiles with an entrance on an edge.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    12
 * E.g. depots and non-drive-through-road-stops.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    13
 *
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    14
 * The test succeeds if the slope is not steep and at least one corner of the entrance edge is on the TileMaxZ() level.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    15
 *
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    16
 * @note The test does not check if autoslope is enabled at all.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    17
 *
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    18
 * @param tile The tile.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    19
 * @param z_new New TileZ.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    20
 * @param tileh_new New TileSlope.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    21
 * @param entrance Entrance edge.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    22
 * @return true iff terraforming is allowed.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    23
 */
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    24
static inline bool AutoslopeCheckForEntranceEdge(TileIndex tile, uint z_new, Slope tileh_new, DiagDirection entrance)
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    25
{
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    26
	if (IsSteepSlope(tileh_new) || (GetTileMaxZ(tile) != z_new + GetSlopeMaxZ(tileh_new))) return false;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    27
	return ((tileh_new == SLOPE_FLAT) || CanBuildDepotByTileh(entrance, tileh_new));
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    28
}
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    29
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    30
/**
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    31
 * Tests if autoslope is enabled for _current_player.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    32
 *
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    33
 * Autoslope is disabled for town/industry construction and old ai players.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    34
 *
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    35
 * @return true iff autoslope is enabled.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    36
 */
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    37
static inline bool AutoslopeEnabled()
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    38
{
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    39
	return (_patches.autoslope &&
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    40
	        ((IsValidPlayer(_current_player) && !_is_old_ai_player) ||
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    41
	         (_current_player == OWNER_NONE && _game_mode == GM_EDITOR)));
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    42
}
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    43
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    44
#endif /* AUTOSLOPE_H */