src/slope.h
changeset 7770 320d260ff1a1
parent 7764 e594296e90f6
child 7954 57b51c69c072
equal deleted inserted replaced
7769:f072d6bb8b99 7770:320d260ff1a1
    14 enum Corner {
    14 enum Corner {
    15 	CORNER_W = 0,
    15 	CORNER_W = 0,
    16 	CORNER_S = 1,
    16 	CORNER_S = 1,
    17 	CORNER_E = 2,
    17 	CORNER_E = 2,
    18 	CORNER_N = 3,
    18 	CORNER_N = 3,
    19 	CORNER_END
    19 	CORNER_END,
       
    20 	CORNER_INVALID = 0xFF
    20 };
    21 };
    21 
    22 
    22 /**
    23 /**
    23  * Enumeration for the slope-type.
    24  * Enumeration for the slope-type.
    24  *
    25  *
   232 enum Foundation {
   233 enum Foundation {
   233 	FOUNDATION_NONE,             ///< The tile has no foundation, the slope remains unchanged.
   234 	FOUNDATION_NONE,             ///< The tile has no foundation, the slope remains unchanged.
   234 	FOUNDATION_LEVELED,          ///< The tile is leveled up to a flat slope.
   235 	FOUNDATION_LEVELED,          ///< The tile is leveled up to a flat slope.
   235 	FOUNDATION_INCLINED_X,       ///< The tile has an along X-axis inclined foundation.
   236 	FOUNDATION_INCLINED_X,       ///< The tile has an along X-axis inclined foundation.
   236 	FOUNDATION_INCLINED_Y,       ///< The tile has an along Y-axis inclined foundation.
   237 	FOUNDATION_INCLINED_Y,       ///< The tile has an along Y-axis inclined foundation.
   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.
   238 	FOUNDATION_STEEP_LOWER,      ///< The tile has a steep slope. The lowest corner is raised by a foundation to allow building railroad on the lower halftile.
   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.
   239 
       
   240 /* Halftile foundations */
       
   241 	FOUNDATION_STEEP_BOTH,       ///< The tile has a steep slope. The lowest corner is raised by a foundation and the upper halftile is leveled.
       
   242 	FOUNDATION_HALFTILE_W,       ///< Level west halftile non-continuously.
       
   243 	FOUNDATION_HALFTILE_S,       ///< Level south halftile non-continuously.
       
   244 	FOUNDATION_HALFTILE_E,       ///< Level east halftile non-continuously.
       
   245 	FOUNDATION_HALFTILE_N,       ///< Level north halftile non-continuously.
       
   246 
       
   247 /* Special anti-zig-zag foundations for single horizontal/vertical track */
       
   248 	FOUNDATION_RAIL_W,           ///< Foundation for TRACK_BIT_LEFT, but not a leveled foundation.
       
   249 	FOUNDATION_RAIL_S,           ///< Foundation for TRACK_BIT_LOWER, but not a leveled foundation.
       
   250 	FOUNDATION_RAIL_E,           ///< Foundation for TRACK_BIT_RIGHT, but not a leveled foundation.
       
   251 	FOUNDATION_RAIL_N,           ///< Foundation for TRACK_BIT_UPPER, but not a leveled foundation.
   239 
   252 
   240 	FOUNDATION_INVALID = 0xFF    ///< Used inside "rail_cmd.cpp" to indicate invalid slope/track combination.
   253 	FOUNDATION_INVALID = 0xFF    ///< Used inside "rail_cmd.cpp" to indicate invalid slope/track combination.
   241 };
   254 };
   242 
   255 
   243 /**
   256 /**
   269  * @return   true iff f is an inclined foundation.
   282  * @return   true iff f is an inclined foundation.
   270  */
   283  */
   271 static inline bool IsInclinedFoundation(Foundation f)
   284 static inline bool IsInclinedFoundation(Foundation f)
   272 {
   285 {
   273 	return (f == FOUNDATION_INCLINED_X) || (f == FOUNDATION_INCLINED_Y);
   286 	return (f == FOUNDATION_INCLINED_X) || (f == FOUNDATION_INCLINED_Y);
       
   287 }
       
   288 
       
   289 /**
       
   290  * Tests if a foundation is a non-continuous foundation, i.e. halftile-foundation or FOUNDATION_STEEP_BOTH.
       
   291  *
       
   292  * @param f  The #Foundation.
       
   293  * @return   true iff f is a non-continuous foundation
       
   294  */
       
   295 static inline bool IsNonContinuousFoundation(Foundation f)
       
   296 {
       
   297 	return IS_INT_INSIDE(f, FOUNDATION_STEEP_BOTH, FOUNDATION_HALFTILE_N + 1);
       
   298 }
       
   299 
       
   300 /**
       
   301  * Returns the halftile corner of a halftile-foundation
       
   302  *
       
   303  * @pre f != FOUNDATION_STEEP_BOTH
       
   304  *
       
   305  * @param f  The #Foundation.
       
   306  * @return   The #Corner with track.
       
   307  */
       
   308 static inline Corner GetHalftileFoundationCorner(Foundation f)
       
   309 {
       
   310 	assert(IS_INT_INSIDE(f, FOUNDATION_HALFTILE_W, FOUNDATION_HALFTILE_N + 1));
       
   311 	return (Corner)(f - FOUNDATION_HALFTILE_W);
       
   312 }
       
   313 
       
   314 /**
       
   315  * Tests if a foundation is a special rail foundation for single horizontal/vertical track.
       
   316  *
       
   317  * @param f  The #Foundation.
       
   318  * @return   true iff f is a special rail foundation for single horizontal/vertical track.
       
   319  */
       
   320 static inline bool IsSpecialRailFoundation(Foundation f)
       
   321 {
       
   322 	return IS_INT_INSIDE(f, FOUNDATION_RAIL_W, FOUNDATION_RAIL_N + 1);
       
   323 }
       
   324 
       
   325 /**
       
   326  * Returns the track corner of a special rail foundation
       
   327  *
       
   328  * @param f  The #Foundation.
       
   329  * @return   The #Corner with track.
       
   330  */
       
   331 static inline Corner GetRailFoundationCorner(Foundation f)
       
   332 {
       
   333 	assert(IsSpecialRailFoundation(f));
       
   334 	return (Corner)(f - FOUNDATION_RAIL_W);
   274 }
   335 }
   275 
   336 
   276 /**
   337 /**
   277  * Returns the foundation needed to flatten a slope.
   338  * Returns the foundation needed to flatten a slope.
   278  * The returned foundation is either FOUNDATION_NONE if the tile was already flat, or FOUNDATION_LEVELED.
   339  * The returned foundation is either FOUNDATION_NONE if the tile was already flat, or FOUNDATION_LEVELED.
   296 static inline Foundation InclinedFoundation(Axis axis)
   357 static inline Foundation InclinedFoundation(Axis axis)
   297 {
   358 {
   298 	return (axis == AXIS_X ? FOUNDATION_INCLINED_X : FOUNDATION_INCLINED_Y);
   359 	return (axis == AXIS_X ? FOUNDATION_INCLINED_X : FOUNDATION_INCLINED_Y);
   299 }
   360 }
   300 
   361 
       
   362 /**
       
   363  * Returns the halftile foundation for single horizontal/vertical track.
       
   364  *
       
   365  * @param corner The #Corner with the track.
       
   366  * @return       The wanted #Foundation.
       
   367  */
       
   368 static inline Foundation HalftileFoundation(Corner corner)
       
   369 {
       
   370 	assert(IsValidCorner(corner));
       
   371 	return (Foundation)(FOUNDATION_HALFTILE_W + corner);
       
   372 }
       
   373 
       
   374 /**
       
   375  * Returns the special rail foundation for single horizontal/vertical track.
       
   376  *
       
   377  * @param corner The #Corner with the track.
       
   378  * @return       The wanted #Foundation.
       
   379  */
       
   380 static inline Foundation SpecialRailFoundation(Corner corner)
       
   381 {
       
   382 	assert(IsValidCorner(corner));
       
   383 	return (Foundation)(FOUNDATION_RAIL_W + corner);
       
   384 }
       
   385 
   301 #endif /* SLOPE_H */
   386 #endif /* SLOPE_H */