MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / CheckRailSlope

Function CheckRailSlope

src/rail_cmd.cpp:389–406  ·  view source on GitHub ↗

* Tests if a track can be build on a tile. * * @param tileh Tile slope. * @param rail_bits Tracks to build. * @param existing Tracks already built. * @param tile Tile (used for water test) * @return Error message or cost for foundation building. */

Source from the content-addressed store, hash-verified

387 * @return Error message or cost for foundation building.
388 */
389static CommandCost CheckRailSlope(Slope tileh, TrackBits rail_bits, TrackBits existing, TileIndex tile)
390{
391 /* don't allow building on the lower side of a coast */
392 if (GetFloodingBehaviour(tile) != FLOOD_NONE) {
393 if (!IsSteepSlope(tileh) && ((~_valid_tracks_on_leveled_foundation[tileh] & (rail_bits | existing)) != 0)) return CommandCost(STR_ERROR_CAN_T_BUILD_ON_WATER);
394 }
395
396 Foundation f_new = GetRailFoundation(tileh, rail_bits | existing);
397
398 /* check track/slope combination */
399 if ((f_new == FOUNDATION_INVALID) ||
400 ((f_new != FOUNDATION_NONE) && (!_settings_game.construction.build_on_slopes))) {
401 return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
402 }
403
404 Foundation f_old = GetRailFoundation(tileh, existing);
405 return CommandCost(EXPENSES_CONSTRUCTION, f_new != f_old ? _price[PR_BUILD_FOUNDATION] : (Money)0);
406}
407
408/* Validate functions for rail building */
409static inline bool ValParamTrackOrientation(Track track)

Callers 2

CmdBuildSingleRailFunction · 0.85
TestAutoslopeOnRailTileFunction · 0.85

Calls 4

GetFloodingBehaviourFunction · 0.85
IsSteepSlopeFunction · 0.85
CommandCostClass · 0.85
GetRailFoundationFunction · 0.85

Tested by 1

TestAutoslopeOnRailTileFunction · 0.68