src/autoslope.h
author richk
Wed, 16 Apr 2008 00:07:47 +0000
branchNewGRF_ports
changeset 10200 aba3af04cdbd
parent 6872 1c4a4a609f85
child 10242 52b4a9006029
permissions -rw-r--r--
(svn r12732) [NewGRF_ports] -Sync: with trunk r12657:12672.
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"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6870
diff changeset
     9
#include "settings_type.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6870
diff changeset
    10
#include "player_func.h"
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    11
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    12
/**
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    13
 * Autoslope check for tiles with an entrance on an edge.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    14
 * E.g. depots and non-drive-through-road-stops.
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
 * 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
    17
 *
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    18
 * @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
    19
 *
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    20
 * @param tile The tile.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    21
 * @param z_new New TileZ.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    22
 * @param tileh_new New TileSlope.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    23
 * @param entrance Entrance edge.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    24
 * @return true iff terraforming is allowed.
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
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
    27
{
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    28
	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
    29
	return ((tileh_new == SLOPE_FLAT) || CanBuildDepotByTileh(entrance, tileh_new));
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
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
 * Tests if autoslope is enabled for _current_player.
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
 * 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
    36
 *
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    37
 * @return true iff autoslope is enabled.
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
static inline bool AutoslopeEnabled()
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    40
{
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    41
	return (_patches.autoslope &&
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    42
	        ((IsValidPlayer(_current_player) && !_is_old_ai_player) ||
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    43
	         (_current_player == OWNER_NONE && _game_mode == GM_EDITOR)));
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    44
}
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    45
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
diff changeset
    46
#endif /* AUTOSLOPE_H */