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

Function CheckTrackCombination

src/rail_cmd.cpp:238–255  ·  view source on GitHub ↗

* Check that the new track bits may be built. * @param tile %Tile to build on. * @param to_build New track bits. * @return Succeeded or failed command. */

Source from the content-addressed store, hash-verified

236 * @return Succeeded or failed command.
237 */
238static CommandCost CheckTrackCombination(TileIndex tile, TrackBits to_build)
239{
240 if (!IsPlainRail(tile)) return CommandCost(STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION);
241
242 /* So, we have a tile with tracks on it (and possibly signals). Let's see
243 * what tracks first */
244 TrackBits current = GetTrackBits(tile); // The current track layout.
245 TrackBits future = current | to_build; // The track layout we want to build.
246
247 /* Are we really building something new? */
248 if (current == future) {
249 /* Nothing new is being built */
250 return CommandCost(STR_ERROR_ALREADY_BUILT);
251 }
252
253 /* Normally, we may overlap and any combination is valid */
254 return CommandCost();
255}
256
257
258/** Valid TrackBits on a specific (non-steep)-slope without foundation */

Callers 1

CmdBuildSingleRailFunction · 0.85

Calls 3

IsPlainRailFunction · 0.85
CommandCostClass · 0.85
GetTrackBitsFunction · 0.85

Tested by

no test coverage detected