src/slope.h
branchNewGRF_ports
changeset 6870 ca3fd1fbe311
parent 6743 cabfaa4a0295
child 6871 5a9dc001e1ad
equal deleted inserted replaced
6869:76282d3b748d 6870:ca3fd1fbe311
    39 	SLOPE_STEEP_E  = SLOPE_STEEP | SLOPE_SEN,               ///< a steep slope falling to west (from east)
    39 	SLOPE_STEEP_E  = SLOPE_STEEP | SLOPE_SEN,               ///< a steep slope falling to west (from east)
    40 	SLOPE_STEEP_N  = SLOPE_STEEP | SLOPE_ENW                ///< a steep slope falling to south (from north)
    40 	SLOPE_STEEP_N  = SLOPE_STEEP | SLOPE_ENW                ///< a steep slope falling to south (from north)
    41 };
    41 };
    42 
    42 
    43 /**
    43 /**
       
    44  * Enumeration of tile corners
       
    45  */
       
    46 enum Corner {
       
    47 	CORNER_W = 0,
       
    48 	CORNER_S = 1,
       
    49 	CORNER_E = 2,
       
    50 	CORNER_N = 3,
       
    51 };
       
    52 
       
    53 /**
    44  * Checks if a slope is steep.
    54  * Checks if a slope is steep.
    45  *
    55  *
    46  * @param s The given #Slope.
    56  * @param s The given #Slope.
    47  * @return True if the slope is steep, else false.
    57  * @return True if the slope is steep, else false.
    48  */
    58  */
    71 /**
    81 /**
    72  * Returns the highest corner of a slope (one corner raised or a steep slope).
    82  * Returns the highest corner of a slope (one corner raised or a steep slope).
    73  *
    83  *
    74  * @pre      The slope must be a slope with one corner raised or a steep slope.
    84  * @pre      The slope must be a slope with one corner raised or a steep slope.
    75  * @param s  The #Slope.
    85  * @param s  The #Slope.
    76  * @return   Number of the highest corner. (0 west, 1 south, 2 east, 3 north)
    86  * @return   Highest corner.
    77  */
    87  */
    78 static inline byte GetHighestSlopeCorner(Slope s)
    88 static inline Corner GetHighestSlopeCorner(Slope s)
    79 {
    89 {
    80 	switch (s) {
    90 	switch (s) {
    81 		case SLOPE_W:
    91 		case SLOPE_W:
    82 		case SLOPE_STEEP_W: return 0;
    92 		case SLOPE_STEEP_W: return CORNER_W;
    83 		case SLOPE_S:
    93 		case SLOPE_S:
    84 		case SLOPE_STEEP_S: return 1;
    94 		case SLOPE_STEEP_S: return CORNER_S;
    85 		case SLOPE_E:
    95 		case SLOPE_E:
    86 		case SLOPE_STEEP_E: return 2;
    96 		case SLOPE_STEEP_E: return CORNER_E;
    87 		case SLOPE_N:
    97 		case SLOPE_N:
    88 		case SLOPE_STEEP_N: return 3;
    98 		case SLOPE_STEEP_N: return CORNER_N;
    89 		default: NOT_REACHED();
    99 		default: NOT_REACHED();
    90 	}
   100 	}
       
   101 }
       
   102 
       
   103 /**
       
   104  * Returns the height of the highest corner of a slope relative to TileZ (= minimal height)
       
   105  *
       
   106  * @param s The #Slope.
       
   107  * @return Relative height of highest corner.
       
   108  */
       
   109 static inline uint GetSlopeMaxZ(Slope s)
       
   110 {
       
   111 	if (s == SLOPE_FLAT) return 0;
       
   112 	if (IsSteepSlope(s)) return 2 * TILE_HEIGHT;
       
   113 	return TILE_HEIGHT;
       
   114 }
       
   115 
       
   116 /**
       
   117  * Returns the opposite corner.
       
   118  *
       
   119  * @param corner A #Corner.
       
   120  * @return The opposite corner to "corner".
       
   121  */
       
   122 static inline Corner OppositeCorner(Corner corner)
       
   123 {
       
   124 	return (Corner)(corner ^ 2);
       
   125 }
       
   126 
       
   127 /**
       
   128  * Returns the slope with a specific corner raised.
       
   129  *
       
   130  * @param corner The #Corner.
       
   131  * @return The #Slope with corner "corner" raised.
       
   132  */
       
   133 static inline Slope SlopeWithOneCornerRaised(Corner corner)
       
   134 {
       
   135 	assert(IS_INT_INSIDE(corner, 0, 4));
       
   136 	return (Slope)(1 << corner);
       
   137 }
       
   138 
       
   139 /**
       
   140  * Returns the slope with all except one corner raised.
       
   141  *
       
   142  * @param corner The #Corner.
       
   143  * @return The #Slope with all corners but "corner" raised.
       
   144  */
       
   145 static inline Slope SlopeWithThreeCornersRaised(Corner corner)
       
   146 {
       
   147 	return ComplementSlope(SlopeWithOneCornerRaised(corner));
    91 }
   148 }
    92 
   149 
    93 
   150 
    94 /**
   151 /**
    95  * Enumeration for Foundations.
   152  * Enumeration for Foundations.