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