src/slope.h
author rubidium
Sat, 20 Oct 2007 17:11:02 +0000
changeset 8261 ed2ea3ac3edc
parent 8260 c7d75cebe3f6
child 8266 48fa6a084b98
permissions -rw-r--r--
(svn r11314) -Fix [FS#1356]: stop following a vehicle when you sell/destroyed it.
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,
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    19
	CORNER_END
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8199
diff changeset
    20
};
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
/**
7805
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    23
 * Enumeration for the slope-type.
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    24
 *
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    25
 * This enumeration use the chars N,E,S,W corresponding the
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    26
 * 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
    27
 * 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
    28
 * 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
    29
 *
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
 * 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
    31
 * 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
    32
 * 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
    33
 * 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
    34
 * 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
    35
 * 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
    36
 * slopes only span one height level.
7805
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    37
 */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 5726
diff changeset
    38
enum Slope {
7805
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    39
	SLOPE_FLAT     = 0x00,                                  ///< a flat tile
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    40
	SLOPE_W        = 0x01,                                  ///< the west corner of the tile is raised
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    41
	SLOPE_S        = 0x02,                                  ///< the south corner of the tile is raised
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    42
	SLOPE_E        = 0x04,                                  ///< the east corner of the tile is raised
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    43
	SLOPE_N        = 0x08,                                  ///< the north corner of the tile is raised
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    44
	SLOPE_STEEP    = 0x10,                                  ///< indicates the slope is steep
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    45
	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
    46
	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
    47
	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
    48
	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
    49
	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
    50
	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
    51
	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
    52
	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
    53
	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
    54
	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
    55
	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
    56
	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
    57
	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
    58
	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
    59
	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
    60
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
    61
	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
    62
	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
    63
	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
    64
	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
    65
	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
    66
	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
    67
};
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
/**
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
    70
 * Rangecheck for Corner enumeration.
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
    71
 *
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
    72
 * @param corner A #Corner.
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
    73
 * @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
    74
 */
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
    75
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
    76
{
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
    77
	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
    78
}
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
/**
7805
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    81
 * Checks if a slope is steep.
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    82
 *
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    83
 * @param s The given #Slope.
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    84
 * @return True if the slope is steep, else false.
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    85
 */
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
    86
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
    87
{
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
    88
	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
    89
}
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
    90
7805
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
    91
/**
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
    92
 * 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
    93
 *
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
 * @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
    95
 * @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
    96
 */
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
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
    98
{
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
	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
   100
}
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
/**
7805
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
   103
 * Return the complement of a slope.
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
   104
 *
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
   105
 * 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
   106
 * 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
   107
 * slope.
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
   108
 *
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
   109
 * @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
   110
 * @param s The #Slope to get the complement.
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
   111
 * @return a complement Slope of the given slope.
d6b7546a25b1 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6916
diff changeset
   112
 */
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
   113
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
   114
{
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
   115
	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
   116
	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
   117
}
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
   118
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
   119
/**
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
   120
 * 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
   121
 *
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
   122
 * 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
   123
 *
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
   124
 * @param s The #Slope.
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
   125
 * @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
   126
 */
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
   127
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
   128
{
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
   129
	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
   130
	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
   131
}
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
/**
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
   134
 * 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
   135
 *
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
   136
 * @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
   137
 * @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
   138
 * @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
   139
 */
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
   140
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
   141
{
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
   142
	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
   143
		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
   144
		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
   145
		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
   146
		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
   147
		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
   148
		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
   149
		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
   150
		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
   151
		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
   152
	}
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
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
   155
/**
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
   156
 * 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
   157
 *
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
 * @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
   159
 * @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
   160
 * @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
   161
 */
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
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
   163
{
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
	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
   165
	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
   166
}
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
/**
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
   169
 * 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
   170
 *
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
 * @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
   172
 * @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
   173
 */
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
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
   175
{
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
	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
   177
	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
   178
	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
   179
}
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
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
   181
/**
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
 * 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
   183
 *
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
 * @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
   185
 * @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
   186
 */
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
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
   188
{
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
	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
   190
}
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
 * 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
   194
 *
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
 * @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
   196
 * @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
   197
 */
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
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
   199
{
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
   200
	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
   201
	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
   202
}
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
 * 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
   206
 *
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
 * @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
   208
 * @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
   209
 */
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
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
   211
{
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
	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
   213
}
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
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
   215
/**
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
 * 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
   217
 *
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
 * @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
   219
 * @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
   220
 * @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
   221
 */
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
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
   223
{
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
	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
   225
	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
   226
}
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
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
   228
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
 * 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
   231
 */
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
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
   233
	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
   234
	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
   235
	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
   236
	FOUNDATION_INCLINED_Y,       ///< The tile has an along Y-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_STEEP_LOWER,      ///< The tile has a steep slope. The lowerst corner is raised by a foundation to allow building railroad on the lower halftile.
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
   238
	FOUNDATION_STEEP_HIGHER,     ///< The tile has a steep slope. Three corners are raised by a foundation to allow building railroad on the higher halftile.
8199
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
   239
00ee9637c0a0 (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 8174
diff changeset
   240
	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
   241
};
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
   242
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
   243
/**
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
   244
 * 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
   245
 *
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
   246
 * @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
   247
 * @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
   248
 */
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
   249
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
   250
{
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
   251
	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
   252
}
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
   253
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
 * 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
   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
 * @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
   258
 * @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
   259
 */
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
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
   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
	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
   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
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
 * 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
   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
 * @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
   269
 * @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
   270
 */
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
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
   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
	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
   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
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
 * 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
   278
 * 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
   279
 *
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
 * @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
   281
 * @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
   282
 * @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
   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 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
   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
	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
   287
	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
   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
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
   290
/**
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
   291
 * 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
   292
 *
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
   293
 * @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
   294
 * @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
   295
 */
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
   296
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
   297
{
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
   298
	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
   299
}
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
   300
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
   301
#endif /* SLOPE_H */