src/slope.h
author rubidium
Sat, 20 Oct 2007 16:50:48 +0000
changeset 7764 e594296e90f6
parent 7703 6178606d419a
child 7770 320d260ff1a1
permissions -rw-r--r--
(svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
     1
/* $Id$ */
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
     2
7309
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
     3
/** @file slope.h Definitions of a slope.
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
     4
 * This file defines the enumeration and helper functions for handling
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
     5
 * the slope info of a tile.
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
     6
 */
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6248
diff changeset
     7
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
     8
#ifndef SLOPE_H
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
     9
#define SLOPE_H
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
    10
7309
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    11
/**
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    12
 * Enumeration of tile corners
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    13
 */
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    14
enum Corner {
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    15
	CORNER_W = 0,
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    16
	CORNER_S = 1,
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    17
	CORNER_E = 2,
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    18
	CORNER_N = 3,
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    19
	CORNER_END
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    20
};
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    21
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    22
/**
7309
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    23
 * Enumeration for the slope-type.
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    24
 *
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    25
 * This enumeration use the chars N,E,S,W corresponding the
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    26
 * direction north, east, south and west. The top corner of a tile
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    27
 * is the north-part of the tile. The whole slope is encoded with
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    28
 * 5 bits, 4 bits for each corner and 1 bit for a steep-flag.
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    29
 *
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    30
 * For halftile slopes an extra 3 bits are used to represent this
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    31
 * properly; 1 bit for a halftile-flag and 2 bits to encode which
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    32
 * extra side (corner) is leveled when the slope of the first 5
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    33
 * bits is applied. This means that there can only be one leveled
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    34
 * slope for steep slopes, which is logical because two leveled
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    35
 * slopes would mean that it is not a steep slope as halftile
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    36
 * slopes only span one height level.
7309
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    37
 */
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 5475
diff changeset
    38
enum Slope {
7309
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    39
	SLOPE_FLAT     = 0x00,                                  ///< a flat tile
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    40
	SLOPE_W        = 0x01,                                  ///< the west corner of the tile is raised
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    41
	SLOPE_S        = 0x02,                                  ///< the south corner of the tile is raised
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    42
	SLOPE_E        = 0x04,                                  ///< the east corner of the tile is raised
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    43
	SLOPE_N        = 0x08,                                  ///< the north corner of the tile is raised
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    44
	SLOPE_STEEP    = 0x10,                                  ///< indicates the slope is steep
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    45
	SLOPE_NW       = SLOPE_N | SLOPE_W,                     ///< north and west corner are raised
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    46
	SLOPE_SW       = SLOPE_S | SLOPE_W,                     ///< south and west corner are raised
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    47
	SLOPE_SE       = SLOPE_S | SLOPE_E,                     ///< south and east corner are raised
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    48
	SLOPE_NE       = SLOPE_N | SLOPE_E,                     ///< north and east corner are raised
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    49
	SLOPE_EW       = SLOPE_E | SLOPE_W,                     ///< east and west corner are raised
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    50
	SLOPE_NS       = SLOPE_N | SLOPE_S,                     ///< north and south corner are raised
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    51
	SLOPE_ELEVATED = SLOPE_N | SLOPE_E | SLOPE_S | SLOPE_W, ///< all corner are raised, similar to SLOPE_FLAT
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    52
	SLOPE_NWS      = SLOPE_N | SLOPE_W | SLOPE_S,           ///< north, west and south corner are raised
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    53
	SLOPE_WSE      = SLOPE_W | SLOPE_S | SLOPE_E,           ///< west, south and east corner are raised
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    54
	SLOPE_SEN      = SLOPE_S | SLOPE_E | SLOPE_N,           ///< south, east and north corner are raised
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    55
	SLOPE_ENW      = SLOPE_E | SLOPE_N | SLOPE_W,           ///< east, north and west corner are raised
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    56
	SLOPE_STEEP_W  = SLOPE_STEEP | SLOPE_NWS,               ///< a steep slope falling to east (from west)
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    57
	SLOPE_STEEP_S  = SLOPE_STEEP | SLOPE_WSE,               ///< a steep slope falling to north (from south)
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    58
	SLOPE_STEEP_E  = SLOPE_STEEP | SLOPE_SEN,               ///< a steep slope falling to west (from east)
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    59
	SLOPE_STEEP_N  = SLOPE_STEEP | SLOPE_ENW,               ///< a steep slope falling to south (from north)
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
    60
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    61
	SLOPE_HALFTILE = 0x20,                                  ///< one halftile is leveled (non continuous slope)
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    62
	SLOPE_HALFTILE_MASK = 0xE0,                             ///< three bits used for halftile slopes
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    63
	SLOPE_HALFTILE_W = SLOPE_HALFTILE | (CORNER_W << 6),    ///< the west halftile is leveled (non continuous slope)
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    64
	SLOPE_HALFTILE_S = SLOPE_HALFTILE | (CORNER_S << 6),    ///< the south halftile is leveled (non continuous slope)
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    65
	SLOPE_HALFTILE_E = SLOPE_HALFTILE | (CORNER_E << 6),    ///< the east halftile is leveled (non continuous slope)
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    66
	SLOPE_HALFTILE_N = SLOPE_HALFTILE | (CORNER_N << 6),    ///< the north halftile is leveled (non continuous slope)
7678
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
    67
};
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
    68
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
    69
/**
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
    70
 * Rangecheck for Corner enumeration.
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
    71
 *
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
    72
 * @param corner A #Corner.
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
    73
 * @return true iff corner is in a valid range.
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
    74
 */
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
    75
static inline bool IsValidCorner(Corner corner)
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
    76
{
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
    77
	return IS_INT_INSIDE(corner, 0, CORNER_END);
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
    78
}
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
    79
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
    80
/**
7309
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    81
 * Checks if a slope is steep.
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    82
 *
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    83
 * @param s The given #Slope.
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    84
 * @return True if the slope is steep, else false.
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    85
 */
3636
a36cc46e754d (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)
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
    87
{
a36cc46e754d (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;
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
    89
}
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
    90
7309
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
    91
/**
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    92
 * Checks for non-continuous slope on halftile foundations.
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    93
 *
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    94
 * @param s The given #Slope.
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    95
 * @return True if the slope is non-continuous, else false.
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    96
 */
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    97
static inline bool IsHalftileSlope(Slope s)
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    98
{
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
    99
	return (s & SLOPE_HALFTILE) != 0;
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   100
}
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   101
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   102
/**
7309
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
   103
 * Return the complement of a slope.
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
   104
 *
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
   105
 * This method returns the complement of a slope. The complement of a
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
   106
 * slope is a slope with raised corner which aren't raised in the given
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
   107
 * slope.
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
   108
 *
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   109
 * @pre The slope must neither be steep nor a halftile slope.
7309
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
   110
 * @param s The #Slope to get the complement.
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
   111
 * @return a complement Slope of the given slope.
223e01a82942 (svn r10661) -Documentation: documented slope.h (Progman)
truelight
parents: 6420
diff changeset
   112
 */
3636
a36cc46e754d (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)
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
   114
{
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   115
	assert(!IsSteepSlope(s) && !IsHalftileSlope(s));
3636
a36cc46e754d (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);
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
   117
}
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
diff changeset
   118
7335
141c6b86ec1f (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: 7309
diff changeset
   119
/**
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
   120
 * Tests if a slope has a highest corner (i.e. one corner raised or a steep slope).
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
   121
 *
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   122
 * Note: A halftile slope is ignored.
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   123
 *
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
   124
 * @param s The #Slope.
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
   125
 * @return  true iff the slope has a highest corner.
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
   126
 */
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
   127
static inline bool HasSlopeHighestCorner(Slope s)
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
   128
{
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   129
	s = (Slope)(s & ~SLOPE_HALFTILE_MASK);
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
   130
	return IsSteepSlope(s) || (s == SLOPE_W) || (s == SLOPE_S) || (s == SLOPE_E) || (s == SLOPE_N);
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
   131
}
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
   132
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
   133
/**
7335
141c6b86ec1f (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: 7309
diff changeset
   134
 * Returns the highest corner of a slope (one corner raised or a steep slope).
141c6b86ec1f (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: 7309
diff changeset
   135
 *
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   136
 * @pre      The slope must be a slope with one corner raised or a steep slope. A halftile slope is ignored.
7335
141c6b86ec1f (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: 7309
diff changeset
   137
 * @param s  The #Slope.
7678
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   138
 * @return   Highest corner.
7335
141c6b86ec1f (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: 7309
diff changeset
   139
 */
7678
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   140
static inline Corner GetHighestSlopeCorner(Slope s)
7335
141c6b86ec1f (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: 7309
diff changeset
   141
{
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   142
	switch (s & ~SLOPE_HALFTILE_MASK) {
7335
141c6b86ec1f (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: 7309
diff changeset
   143
		case SLOPE_W:
7678
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   144
		case SLOPE_STEEP_W: return CORNER_W;
7335
141c6b86ec1f (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: 7309
diff changeset
   145
		case SLOPE_S:
7678
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   146
		case SLOPE_STEEP_S: return CORNER_S;
7335
141c6b86ec1f (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: 7309
diff changeset
   147
		case SLOPE_E:
7678
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   148
		case SLOPE_STEEP_E: return CORNER_E;
7335
141c6b86ec1f (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: 7309
diff changeset
   149
		case SLOPE_N:
7678
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   150
		case SLOPE_STEEP_N: return CORNER_N;
7335
141c6b86ec1f (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: 7309
diff changeset
   151
		default: NOT_REACHED();
141c6b86ec1f (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: 7309
diff changeset
   152
	}
141c6b86ec1f (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: 7309
diff changeset
   153
}
141c6b86ec1f (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: 7309
diff changeset
   154
7582
80c8517b08d1 (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: 7335
diff changeset
   155
/**
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   156
 * Returns the leveled halftile of a halftile slope.
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   157
 *
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   158
 * @pre     The slope must be a halftile slope.
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   159
 * @param s The #Slope.
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   160
 * @return  The corner of the leveled halftile.
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   161
 */
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   162
static inline Corner GetHalftileSlopeCorner(Slope s)
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   163
{
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   164
	assert(IsHalftileSlope(s));
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   165
	return (Corner)((s >> 6) & 3);
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   166
}
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   167
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   168
/**
7582
80c8517b08d1 (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: 7335
diff changeset
   169
 * Returns the height of the highest corner of a slope relative to TileZ (= minimal height)
80c8517b08d1 (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: 7335
diff changeset
   170
 *
80c8517b08d1 (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: 7335
diff changeset
   171
 * @param s The #Slope.
80c8517b08d1 (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: 7335
diff changeset
   172
 * @return Relative height of highest corner.
80c8517b08d1 (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: 7335
diff changeset
   173
 */
80c8517b08d1 (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: 7335
diff changeset
   174
static inline uint GetSlopeMaxZ(Slope s)
80c8517b08d1 (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: 7335
diff changeset
   175
{
80c8517b08d1 (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: 7335
diff changeset
   176
	if (s == SLOPE_FLAT) return 0;
80c8517b08d1 (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: 7335
diff changeset
   177
	if (IsSteepSlope(s)) return 2 * TILE_HEIGHT;
80c8517b08d1 (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: 7335
diff changeset
   178
	return TILE_HEIGHT;
80c8517b08d1 (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: 7335
diff changeset
   179
}
80c8517b08d1 (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: 7335
diff changeset
   180
7678
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   181
/**
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   182
 * Returns the opposite corner.
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   183
 *
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   184
 * @param corner A #Corner.
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   185
 * @return The opposite corner to "corner".
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   186
 */
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   187
static inline Corner OppositeCorner(Corner corner)
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   188
{
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   189
	return (Corner)(corner ^ 2);
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   190
}
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   191
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   192
/**
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   193
 * Returns the slope with a specific corner raised.
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   194
 *
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   195
 * @param corner The #Corner.
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   196
 * @return The #Slope with corner "corner" raised.
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   197
 */
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   198
static inline Slope SlopeWithOneCornerRaised(Corner corner)
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   199
{
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
   200
	assert(IsValidCorner(corner));
7678
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   201
	return (Slope)(1 << corner);
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   202
}
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   203
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   204
/**
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   205
 * Returns the slope with all except one corner raised.
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   206
 *
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   207
 * @param corner The #Corner.
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   208
 * @return The #Slope with all corners but "corner" raised.
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   209
 */
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   210
static inline Slope SlopeWithThreeCornersRaised(Corner corner)
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   211
{
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   212
	return ComplementSlope(SlopeWithOneCornerRaised(corner));
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   213
}
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7582
diff changeset
   214
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   215
/**
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   216
 * Adds a halftile slope to a slope.
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   217
 *
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   218
 * @param s #Slope without a halftile slope.
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   219
 * @param corner The #Corner of the halftile.
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   220
 * @return The #Slope s with the halftile slope added.
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   221
 */
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   222
static inline Slope HalftileSlope(Slope s, Corner corner)
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   223
{
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   224
	assert(IsValidCorner(corner));
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   225
	return (Slope)(s | SLOPE_HALFTILE | (corner << 6));
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   226
}
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7703
diff changeset
   227
7335
141c6b86ec1f (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: 7309
diff changeset
   228
141c6b86ec1f (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: 7309
diff changeset
   229
/**
141c6b86ec1f (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: 7309
diff changeset
   230
 * Enumeration for Foundations.
141c6b86ec1f (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: 7309
diff changeset
   231
 */
141c6b86ec1f (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: 7309
diff changeset
   232
enum Foundation {
141c6b86ec1f (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: 7309
diff changeset
   233
	FOUNDATION_NONE,             ///< The tile has no foundation, the slope remains unchanged.
141c6b86ec1f (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: 7309
diff changeset
   234
	FOUNDATION_LEVELED,          ///< The tile is leveled up to a flat slope.
141c6b86ec1f (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: 7309
diff changeset
   235
	FOUNDATION_INCLINED_X,       ///< The tile has an along X-axis inclined foundation.
141c6b86ec1f (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: 7309
diff changeset
   236
	FOUNDATION_INCLINED_Y,       ///< The tile has an along Y-axis inclined foundation.
141c6b86ec1f (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: 7309
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.
141c6b86ec1f (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: 7309
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.
7703
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
   239
6178606d419a (svn r11237) -Codechange: reduce code duplication between GetRailFoundation() and CheckRailSlope(). Patch by frosch.
rubidium
parents: 7678
diff changeset
   240
	FOUNDATION_INVALID = 0xFF    ///< Used inside "rail_cmd.cpp" to indicate invalid slope/track combination.
7335
141c6b86ec1f (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: 7309
diff changeset
   241
};
141c6b86ec1f (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: 7309
diff changeset
   242
141c6b86ec1f (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: 7309
diff changeset
   243
/**
141c6b86ec1f (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: 7309
diff changeset
   244
 * Tests for FOUNDATION_NONE.
141c6b86ec1f (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: 7309
diff changeset
   245
 *
141c6b86ec1f (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: 7309
diff changeset
   246
 * @param f  Maybe a #Foundation.
141c6b86ec1f (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: 7309
diff changeset
   247
 * @return   true iff f is a foundation.
141c6b86ec1f (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: 7309
diff changeset
   248
 */
141c6b86ec1f (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: 7309
diff changeset
   249
static inline bool IsFoundation(Foundation f)
141c6b86ec1f (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: 7309
diff changeset
   250
{
141c6b86ec1f (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: 7309
diff changeset
   251
	return f != FOUNDATION_NONE;
141c6b86ec1f (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: 7309
diff changeset
   252
}
141c6b86ec1f (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: 7309
diff changeset
   253
141c6b86ec1f (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: 7309
diff changeset
   254
/**
141c6b86ec1f (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: 7309
diff changeset
   255
 * Tests if the foundation is a leveled foundation.
141c6b86ec1f (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: 7309
diff changeset
   256
 *
141c6b86ec1f (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: 7309
diff changeset
   257
 * @param f  The #Foundation.
141c6b86ec1f (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: 7309
diff changeset
   258
 * @return   true iff f is a leveled foundation.
141c6b86ec1f (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: 7309
diff changeset
   259
 */
141c6b86ec1f (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: 7309
diff changeset
   260
static inline bool IsLeveledFoundation(Foundation f)
141c6b86ec1f (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: 7309
diff changeset
   261
{
141c6b86ec1f (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: 7309
diff changeset
   262
	return f == FOUNDATION_LEVELED;
141c6b86ec1f (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: 7309
diff changeset
   263
}
141c6b86ec1f (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: 7309
diff changeset
   264
141c6b86ec1f (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: 7309
diff changeset
   265
/**
141c6b86ec1f (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: 7309
diff changeset
   266
 * Tests if the foundation is an inclined foundation.
141c6b86ec1f (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: 7309
diff changeset
   267
 *
141c6b86ec1f (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: 7309
diff changeset
   268
 * @param f  The #Foundation.
141c6b86ec1f (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: 7309
diff changeset
   269
 * @return   true iff f is an inclined foundation.
141c6b86ec1f (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: 7309
diff changeset
   270
 */
141c6b86ec1f (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: 7309
diff changeset
   271
static inline bool IsInclinedFoundation(Foundation f)
141c6b86ec1f (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: 7309
diff changeset
   272
{
141c6b86ec1f (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: 7309
diff changeset
   273
	return (f == FOUNDATION_INCLINED_X) || (f == FOUNDATION_INCLINED_Y);
141c6b86ec1f (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: 7309
diff changeset
   274
}
141c6b86ec1f (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: 7309
diff changeset
   275
141c6b86ec1f (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: 7309
diff changeset
   276
/**
141c6b86ec1f (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: 7309
diff changeset
   277
 * Returns the foundation needed to flatten a slope.
141c6b86ec1f (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: 7309
diff changeset
   278
 * The returned foundation is either FOUNDATION_NONE if the tile was already flat, or FOUNDATION_LEVELED.
141c6b86ec1f (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: 7309
diff changeset
   279
 *
141c6b86ec1f (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: 7309
diff changeset
   280
 * @pre      The slope must not be steep.
141c6b86ec1f (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: 7309
diff changeset
   281
 * @param s  The current #Slope.
141c6b86ec1f (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: 7309
diff changeset
   282
 * @return   The needed #Foundation.
141c6b86ec1f (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: 7309
diff changeset
   283
 */
141c6b86ec1f (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: 7309
diff changeset
   284
static inline Foundation FlatteningFoundation(Slope s)
141c6b86ec1f (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: 7309
diff changeset
   285
{
141c6b86ec1f (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: 7309
diff changeset
   286
	assert(!IsSteepSlope(s));
141c6b86ec1f (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: 7309
diff changeset
   287
	return (s == SLOPE_FLAT ? FOUNDATION_NONE : FOUNDATION_LEVELED);
141c6b86ec1f (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: 7309
diff changeset
   288
}
141c6b86ec1f (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: 7309
diff changeset
   289
141c6b86ec1f (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: 7309
diff changeset
   290
/**
141c6b86ec1f (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: 7309
diff changeset
   291
 * Returns the along a specific axis inclined foundation.
141c6b86ec1f (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: 7309
diff changeset
   292
 *
141c6b86ec1f (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: 7309
diff changeset
   293
 * @param axis  The #Axis.
141c6b86ec1f (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: 7309
diff changeset
   294
 * @return      The needed #Foundation.
141c6b86ec1f (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: 7309
diff changeset
   295
 */
141c6b86ec1f (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: 7309
diff changeset
   296
static inline Foundation InclinedFoundation(Axis axis)
141c6b86ec1f (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: 7309
diff changeset
   297
{
141c6b86ec1f (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: 7309
diff changeset
   298
	return (axis == AXIS_X ? FOUNDATION_INCLINED_X : FOUNDATION_INCLINED_Y);
141c6b86ec1f (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: 7309
diff changeset
   299
}
141c6b86ec1f (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: 7309
diff changeset
   300
4666
172a0cdf28a6 (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 */