853 return CmdSignalTrackHelper(tile, flags, p1, SETBIT(p2, 5)); // bit 5 is remove bit |
853 return CmdSignalTrackHelper(tile, flags, p1, SETBIT(p2, 5)); // bit 5 is remove bit |
854 } |
854 } |
855 |
855 |
856 typedef int32 DoConvertRailProc(TileIndex tile, RailType totype, bool exec); |
856 typedef int32 DoConvertRailProc(TileIndex tile, RailType totype, bool exec); |
857 |
857 |
|
858 /** |
|
859 * Switches the rail type. |
|
860 * Railtypes are stored on a per-tile basis, not on a per-track basis, so |
|
861 * all the tracks in the given tile will be converted. |
|
862 * @param tile The tile on which the railtype is to be convert. |
|
863 * @param totype The railtype we want to convert to |
|
864 * @param exec Switches between test and execute mode |
|
865 * @return The cost and state of the operation |
|
866 * @retval CMD_ERROR An error occured during the operation. |
|
867 */ |
858 static int32 DoConvertRail(TileIndex tile, RailType totype, bool exec) |
868 static int32 DoConvertRail(TileIndex tile, RailType totype, bool exec) |
859 { |
869 { |
860 if (!CheckTileOwnership(tile)) return CMD_ERROR; |
870 if (!CheckTileOwnership(tile)) return CMD_ERROR; |
861 |
871 |
|
872 if (GetRailType(tile) == totype) return CMD_ERROR; |
|
873 |
862 if (!EnsureNoVehicle(tile) && (!IsCompatibleRail(GetRailType(tile), totype) || IsPlainRailTile(tile))) return CMD_ERROR; |
874 if (!EnsureNoVehicle(tile) && (!IsCompatibleRail(GetRailType(tile), totype) || IsPlainRailTile(tile))) return CMD_ERROR; |
863 |
|
864 // tile is already of requested type? |
|
865 if (GetRailType(tile) == totype) return CMD_ERROR; |
|
866 |
875 |
867 // 'hidden' elrails can't be downgraded to normal rail when elrails are disabled |
876 // 'hidden' elrails can't be downgraded to normal rail when elrails are disabled |
868 if (_patches.disable_elrails && totype == RAILTYPE_RAIL && GetRailType(tile) == RAILTYPE_ELECTRIC) return CMD_ERROR; |
877 if (_patches.disable_elrails && totype == RAILTYPE_RAIL && GetRailType(tile) == RAILTYPE_ELECTRIC) return CMD_ERROR; |
869 |
878 |
870 // change type. |
879 // change type. |