src/slope.h
author skidd13
Tue, 20 Nov 2007 14:11:19 +0000
changeset 8428 f8300c908bd9
parent 8266 48fa6a084b98
child 8450 dce58137301f
permissions -rw-r--r--
(svn r11485) -Codechange: Remove the doubled function ToggleBitT and rename the remaining to fit with the naming style
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
     1
/* $Id$ */
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
     2
7805
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
     3
/** @file slope.h Definitions of a slope.
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
     4
 * This file defines the enumeration and helper functions for handling
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
     5
 * the slope info of a tile.
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
     6
 */
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
     7
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
     8
#ifndef SLOPE_H
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
     9
#define SLOPE_H
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
    10
7805
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    11
/**
8260
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    12
 * Enumeration of tile corners
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    13
 */
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    14
enum Corner {
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    15
	CORNER_W = 0,
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    16
	CORNER_S = 1,
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    17
	CORNER_E = 2,
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    18
	CORNER_N = 3,
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
    19
	CORNER_END,
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
    20
	CORNER_INVALID = 0xFF
8260
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    21
};
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    22
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    23
/**
7805
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    24
 * Enumeration for the slope-type.
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    25
 *
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    26
 * This enumeration use the chars N,E,S,W corresponding the
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    27
 * direction north, east, south and west. The top corner of a tile
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    28
 * is the north-part of the tile. The whole slope is encoded with
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    29
 * 5 bits, 4 bits for each corner and 1 bit for a steep-flag.
8260
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    30
 *
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    31
 * For halftile slopes an extra 3 bits are used to represent this
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    32
 * properly; 1 bit for a halftile-flag and 2 bits to encode which
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    33
 * extra side (corner) is leveled when the slope of the first 5
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    34
 * bits is applied. This means that there can only be one leveled
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    35
 * slope for steep slopes, which is logical because two leveled
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    36
 * slopes would mean that it is not a steep slope as halftile
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    37
 * slopes only span one height level.
7805
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    38
 */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 5726
diff changeset
    39
enum Slope {
7805
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    40
	SLOPE_FLAT     = 0x00,                                  ///< a flat tile
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    41
	SLOPE_W        = 0x01,                                  ///< the west corner of the tile is raised
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    42
	SLOPE_S        = 0x02,                                  ///< the south corner of the tile is raised
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    43
	SLOPE_E        = 0x04,                                  ///< the east corner of the tile is raised
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    44
	SLOPE_N        = 0x08,                                  ///< the north corner of the tile is raised
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    45
	SLOPE_STEEP    = 0x10,                                  ///< indicates the slope is steep
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    46
	SLOPE_NW       = SLOPE_N | SLOPE_W,                     ///< north and west corner are raised
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    47
	SLOPE_SW       = SLOPE_S | SLOPE_W,                     ///< south and west corner are raised
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    48
	SLOPE_SE       = SLOPE_S | SLOPE_E,                     ///< south and east corner are raised
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    49
	SLOPE_NE       = SLOPE_N | SLOPE_E,                     ///< north and east corner are raised
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    50
	SLOPE_EW       = SLOPE_E | SLOPE_W,                     ///< east and west corner are raised
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    51
	SLOPE_NS       = SLOPE_N | SLOPE_S,                     ///< north and south corner are raised
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    52
	SLOPE_ELEVATED = SLOPE_N | SLOPE_E | SLOPE_S | SLOPE_W, ///< all corner are raised, similar to SLOPE_FLAT
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    53
	SLOPE_NWS      = SLOPE_N | SLOPE_W | SLOPE_S,           ///< north, west and south corner are raised
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    54
	SLOPE_WSE      = SLOPE_W | SLOPE_S | SLOPE_E,           ///< west, south and east corner are raised
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    55
	SLOPE_SEN      = SLOPE_S | SLOPE_E | SLOPE_N,           ///< south, east and north corner are raised
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    56
	SLOPE_ENW      = SLOPE_E | SLOPE_N | SLOPE_W,           ///< east, north and west corner are raised
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    57
	SLOPE_STEEP_W  = SLOPE_STEEP | SLOPE_NWS,               ///< a steep slope falling to east (from west)
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    58
	SLOPE_STEEP_S  = SLOPE_STEEP | SLOPE_WSE,               ///< a steep slope falling to north (from south)
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    59
	SLOPE_STEEP_E  = SLOPE_STEEP | SLOPE_SEN,               ///< a steep slope falling to west (from east)
8260
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    60
	SLOPE_STEEP_N  = SLOPE_STEEP | SLOPE_ENW,               ///< a steep slope falling to south (from north)
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
    61
8260
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    62
	SLOPE_HALFTILE = 0x20,                                  ///< one halftile is leveled (non continuous slope)
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    63
	SLOPE_HALFTILE_MASK = 0xE0,                             ///< three bits used for halftile slopes
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    64
	SLOPE_HALFTILE_W = SLOPE_HALFTILE | (CORNER_W << 6),    ///< the west halftile is leveled (non continuous slope)
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    65
	SLOPE_HALFTILE_S = SLOPE_HALFTILE | (CORNER_S << 6),    ///< the south halftile is leveled (non continuous slope)
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    66
	SLOPE_HALFTILE_E = SLOPE_HALFTILE | (CORNER_E << 6),    ///< the east halftile is leveled (non continuous slope)
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    67
	SLOPE_HALFTILE_N = SLOPE_HALFTILE | (CORNER_N << 6),    ///< the north halftile is leveled (non continuous slope)
8174
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
    68
};
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
    69
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
    70
/**
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
    71
 * Rangecheck for Corner enumeration.
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
    72
 *
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
    73
 * @param corner A #Corner.
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
    74
 * @return true iff corner is in a valid range.
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
    75
 */
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
    76
static inline bool IsValidCorner(Corner corner)
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
    77
{
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
    78
	return IS_INT_INSIDE(corner, 0, CORNER_END);
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
    79
}
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
    80
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
    81
/**
7805
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    82
 * Checks if a slope is steep.
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    83
 *
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    84
 * @param s The given #Slope.
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    85
 * @return True if the slope is steep, else false.
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    86
 */
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
    87
static inline bool IsSteepSlope(Slope s)
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
    88
{
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
    89
	return (s & SLOPE_STEEP) != 0;
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
    90
}
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
    91
7805
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    92
/**
8260
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    93
 * Checks for non-continuous slope on halftile foundations.
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    94
 *
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    95
 * @param s The given #Slope.
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    96
 * @return True if the slope is non-continuous, else false.
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    97
 */
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    98
static inline bool IsHalftileSlope(Slope s)
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    99
{
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   100
	return (s & SLOPE_HALFTILE) != 0;
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   101
}
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   102
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   103
/**
7805
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
   104
 * Return the complement of a slope.
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
   105
 *
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
   106
 * This method returns the complement of a slope. The complement of a
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
   107
 * slope is a slope with raised corner which aren't raised in the given
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
   108
 * slope.
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
   109
 *
8260
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   110
 * @pre The slope must neither be steep nor a halftile slope.
7805
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
   111
 * @param s The #Slope to get the complement.
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
   112
 * @return a complement Slope of the given slope.
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
   113
 */
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
   114
static inline Slope ComplementSlope(Slope s)
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
   115
{
8260
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   116
	assert(!IsSteepSlope(s) && !IsHalftileSlope(s));
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
   117
	return (Slope)(0xF ^ s);
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
   118
}
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
   119
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   120
/**
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
   121
 * Tests if a slope has a highest corner (i.e. one corner raised or a steep slope).
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
   122
 *
8260
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   123
 * Note: A halftile slope is ignored.
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   124
 *
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
   125
 * @param s The #Slope.
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
   126
 * @return  true iff the slope has a highest corner.
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
   127
 */
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
   128
static inline bool HasSlopeHighestCorner(Slope s)
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
   129
{
8260
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   130
	s = (Slope)(s & ~SLOPE_HALFTILE_MASK);
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
   131
	return IsSteepSlope(s) || (s == SLOPE_W) || (s == SLOPE_S) || (s == SLOPE_E) || (s == SLOPE_N);
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
   132
}
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
   133
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
   134
/**
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   135
 * Returns the highest corner of a slope (one corner raised or a steep slope).
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   136
 *
8260
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   137
 * @pre      The slope must be a slope with one corner raised or a steep slope. A halftile slope is ignored.
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   138
 * @param s  The #Slope.
8174
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   139
 * @return   Highest corner.
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   140
 */
8174
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   141
static inline Corner GetHighestSlopeCorner(Slope s)
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   142
{
8260
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   143
	switch (s & ~SLOPE_HALFTILE_MASK) {
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   144
		case SLOPE_W:
8174
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   145
		case SLOPE_STEEP_W: return CORNER_W;
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   146
		case SLOPE_S:
8174
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   147
		case SLOPE_STEEP_S: return CORNER_S;
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   148
		case SLOPE_E:
8174
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   149
		case SLOPE_STEEP_E: return CORNER_E;
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   150
		case SLOPE_N:
8174
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   151
		case SLOPE_STEEP_N: return CORNER_N;
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   152
		default: NOT_REACHED();
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   153
	}
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   154
}
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   155
8078
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7831
diff changeset
   156
/**
8260
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   157
 * Returns the leveled halftile of a halftile slope.
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   158
 *
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   159
 * @pre     The slope must be a halftile slope.
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   160
 * @param s The #Slope.
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   161
 * @return  The corner of the leveled halftile.
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   162
 */
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   163
static inline Corner GetHalftileSlopeCorner(Slope s)
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   164
{
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   165
	assert(IsHalftileSlope(s));
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   166
	return (Corner)((s >> 6) & 3);
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   167
}
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   168
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   169
/**
8078
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7831
diff changeset
   170
 * Returns the height of the highest corner of a slope relative to TileZ (= minimal height)
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7831
diff changeset
   171
 *
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7831
diff changeset
   172
 * @param s The #Slope.
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7831
diff changeset
   173
 * @return Relative height of highest corner.
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7831
diff changeset
   174
 */
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7831
diff changeset
   175
static inline uint GetSlopeMaxZ(Slope s)
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7831
diff changeset
   176
{
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7831
diff changeset
   177
	if (s == SLOPE_FLAT) return 0;
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7831
diff changeset
   178
	if (IsSteepSlope(s)) return 2 * TILE_HEIGHT;
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7831
diff changeset
   179
	return TILE_HEIGHT;
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7831
diff changeset
   180
}
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7831
diff changeset
   181
8174
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   182
/**
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   183
 * Returns the opposite corner.
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   184
 *
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   185
 * @param corner A #Corner.
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   186
 * @return The opposite corner to "corner".
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   187
 */
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   188
static inline Corner OppositeCorner(Corner corner)
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   189
{
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   190
	return (Corner)(corner ^ 2);
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   191
}
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   192
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   193
/**
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   194
 * Returns the slope with a specific corner raised.
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   195
 *
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   196
 * @param corner The #Corner.
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   197
 * @return The #Slope with corner "corner" raised.
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   198
 */
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   199
static inline Slope SlopeWithOneCornerRaised(Corner corner)
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   200
{
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
   201
	assert(IsValidCorner(corner));
8174
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   202
	return (Slope)(1 << corner);
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   203
}
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   204
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   205
/**
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   206
 * Returns the slope with all except one corner raised.
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   207
 *
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   208
 * @param corner The #Corner.
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   209
 * @return The #Slope with all corners but "corner" raised.
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   210
 */
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   211
static inline Slope SlopeWithThreeCornersRaised(Corner corner)
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   212
{
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   213
	return ComplementSlope(SlopeWithOneCornerRaised(corner));
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   214
}
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 8078
diff changeset
   215
8260
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   216
/**
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   217
 * Adds a halftile slope to a slope.
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   218
 *
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   219
 * @param s #Slope without a halftile slope.
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   220
 * @param corner The #Corner of the halftile.
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   221
 * @return The #Slope s with the halftile slope added.
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   222
 */
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   223
static inline Slope HalftileSlope(Slope s, Corner corner)
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   224
{
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   225
	assert(IsValidCorner(corner));
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   226
	return (Slope)(s | SLOPE_HALFTILE | (corner << 6));
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   227
}
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
   228
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   229
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   230
/**
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   231
 * Enumeration for Foundations.
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   232
 */
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   233
enum Foundation {
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   234
	FOUNDATION_NONE,             ///< The tile has no foundation, the slope remains unchanged.
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   235
	FOUNDATION_LEVELED,          ///< The tile is leveled up to a flat slope.
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   236
	FOUNDATION_INCLINED_X,       ///< The tile has an along X-axis inclined foundation.
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   237
	FOUNDATION_INCLINED_Y,       ///< The tile has an along Y-axis inclined foundation.
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   238
	FOUNDATION_STEEP_LOWER,      ///< The tile has a steep slope. The lowest corner is raised by a foundation to allow building railroad on the lower halftile.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   239
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   240
/* Halftile foundations */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   241
	FOUNDATION_STEEP_BOTH,       ///< The tile has a steep slope. The lowest corner is raised by a foundation and the upper halftile is leveled.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   242
	FOUNDATION_HALFTILE_W,       ///< Level west halftile non-continuously.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   243
	FOUNDATION_HALFTILE_S,       ///< Level south halftile non-continuously.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   244
	FOUNDATION_HALFTILE_E,       ///< Level east halftile non-continuously.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   245
	FOUNDATION_HALFTILE_N,       ///< Level north halftile non-continuously.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   246
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   247
/* Special anti-zig-zag foundations for single horizontal/vertical track */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   248
	FOUNDATION_RAIL_W,           ///< Foundation for TRACK_BIT_LEFT, but not a leveled foundation.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   249
	FOUNDATION_RAIL_S,           ///< Foundation for TRACK_BIT_LOWER, but not a leveled foundation.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   250
	FOUNDATION_RAIL_E,           ///< Foundation for TRACK_BIT_RIGHT, but not a leveled foundation.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   251
	FOUNDATION_RAIL_N,           ///< Foundation for TRACK_BIT_UPPER, but not a leveled foundation.
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
   252
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
   253
	FOUNDATION_INVALID = 0xFF    ///< Used inside "rail_cmd.cpp" to indicate invalid slope/track combination.
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   254
};
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   255
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   256
/**
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   257
 * Tests for FOUNDATION_NONE.
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   258
 *
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   259
 * @param f  Maybe a #Foundation.
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   260
 * @return   true iff f is a foundation.
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   261
 */
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   262
static inline bool IsFoundation(Foundation f)
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   263
{
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   264
	return f != FOUNDATION_NONE;
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   265
}
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   266
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   267
/**
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   268
 * Tests if the foundation is a leveled foundation.
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   269
 *
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   270
 * @param f  The #Foundation.
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   271
 * @return   true iff f is a leveled foundation.
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   272
 */
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   273
static inline bool IsLeveledFoundation(Foundation f)
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   274
{
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   275
	return f == FOUNDATION_LEVELED;
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   276
}
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   277
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   278
/**
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   279
 * Tests if the foundation is an inclined foundation.
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   280
 *
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   281
 * @param f  The #Foundation.
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   282
 * @return   true iff f is an inclined foundation.
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   283
 */
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   284
static inline bool IsInclinedFoundation(Foundation f)
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   285
{
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   286
	return (f == FOUNDATION_INCLINED_X) || (f == FOUNDATION_INCLINED_Y);
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   287
}
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   288
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   289
/**
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   290
 * Tests if a foundation is a non-continuous foundation, i.e. halftile-foundation or FOUNDATION_STEEP_BOTH.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   291
 *
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   292
 * @param f  The #Foundation.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   293
 * @return   true iff f is a non-continuous foundation
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   294
 */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   295
static inline bool IsNonContinuousFoundation(Foundation f)
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   296
{
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   297
	return IS_INT_INSIDE(f, FOUNDATION_STEEP_BOTH, FOUNDATION_HALFTILE_N + 1);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   298
}
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   299
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   300
/**
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   301
 * Returns the halftile corner of a halftile-foundation
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   302
 *
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   303
 * @pre f != FOUNDATION_STEEP_BOTH
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   304
 *
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   305
 * @param f  The #Foundation.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   306
 * @return   The #Corner with track.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   307
 */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   308
static inline Corner GetHalftileFoundationCorner(Foundation f)
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   309
{
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   310
	assert(IS_INT_INSIDE(f, FOUNDATION_HALFTILE_W, FOUNDATION_HALFTILE_N + 1));
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   311
	return (Corner)(f - FOUNDATION_HALFTILE_W);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   312
}
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   313
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   314
/**
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   315
 * Tests if a foundation is a special rail foundation for single horizontal/vertical track.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   316
 *
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   317
 * @param f  The #Foundation.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   318
 * @return   true iff f is a special rail foundation for single horizontal/vertical track.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   319
 */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   320
static inline bool IsSpecialRailFoundation(Foundation f)
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   321
{
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   322
	return IS_INT_INSIDE(f, FOUNDATION_RAIL_W, FOUNDATION_RAIL_N + 1);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   323
}
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   324
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   325
/**
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   326
 * Returns the track corner of a special rail foundation
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   327
 *
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   328
 * @param f  The #Foundation.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   329
 * @return   The #Corner with track.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   330
 */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   331
static inline Corner GetRailFoundationCorner(Foundation f)
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   332
{
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   333
	assert(IsSpecialRailFoundation(f));
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   334
	return (Corner)(f - FOUNDATION_RAIL_W);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   335
}
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   336
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   337
/**
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   338
 * Returns the foundation needed to flatten a slope.
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   339
 * The returned foundation is either FOUNDATION_NONE if the tile was already flat, or FOUNDATION_LEVELED.
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   340
 *
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   341
 * @pre      The slope must not be steep.
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   342
 * @param s  The current #Slope.
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   343
 * @return   The needed #Foundation.
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   344
 */
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   345
static inline Foundation FlatteningFoundation(Slope s)
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   346
{
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   347
	assert(!IsSteepSlope(s));
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   348
	return (s == SLOPE_FLAT ? FOUNDATION_NONE : FOUNDATION_LEVELED);
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   349
}
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   350
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   351
/**
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   352
 * Returns the along a specific axis inclined foundation.
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   353
 *
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   354
 * @param axis  The #Axis.
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   355
 * @return      The needed #Foundation.
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   356
 */
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   357
static inline Foundation InclinedFoundation(Axis axis)
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   358
{
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   359
	return (axis == AXIS_X ? FOUNDATION_INCLINED_X : FOUNDATION_INCLINED_Y);
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   360
}
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7805
diff changeset
   361
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   362
/**
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   363
 * Returns the halftile foundation for single horizontal/vertical track.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   364
 *
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   365
 * @param corner The #Corner with the track.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   366
 * @return       The wanted #Foundation.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   367
 */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   368
static inline Foundation HalftileFoundation(Corner corner)
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   369
{
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   370
	assert(IsValidCorner(corner));
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   371
	return (Foundation)(FOUNDATION_HALFTILE_W + corner);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   372
}
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   373
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   374
/**
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   375
 * Returns the special rail foundation for single horizontal/vertical track.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   376
 *
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   377
 * @param corner The #Corner with the track.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   378
 * @return       The wanted #Foundation.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   379
 */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   380
static inline Foundation SpecialRailFoundation(Corner corner)
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   381
{
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   382
	assert(IsValidCorner(corner));
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   383
	return (Foundation)(FOUNDATION_RAIL_W + corner);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   384
}
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8260
diff changeset
   385
4666
850b5b6e4bac (svn r6560) - Codechange: Minor fix; add missing #include guards and comments, and correct svn properties on bmp.[ch]
peter1138
parents: 4344
diff changeset
   386
#endif /* SLOPE_H */