rail_cmd.c
branch0.5
changeset 5481 acf12c0e6f31
parent 5198 2547d72f2db4
child 5483 a0d5f45dbdcf
--- a/rail_cmd.c	Mon Mar 26 00:20:22 2007 +0000
+++ b/rail_cmd.c	Tue Apr 10 09:40:36 2007 +0000
@@ -874,14 +874,23 @@
 
 typedef int32 DoConvertRailProc(TileIndex tile, RailType totype, bool exec);
 
+/**
+ * Switches the rail type.
+ * Railtypes are stored on a per-tile basis, not on a per-track basis, so
+ * all the tracks in the given tile will be converted.
+ * @param tile        The tile on which the railtype is to be convert.
+ * @param totype      The railtype we want to convert to
+ * @param exec        Switches between test and execute mode
+ * @return            The cost and state of the operation
+ * @retval CMD_ERROR  An error occured during the operation.
+ */
 static int32 DoConvertRail(TileIndex tile, RailType totype, bool exec)
 {
 	if (!CheckTileOwnership(tile)) return CMD_ERROR;
 
-	if (!EnsureNoVehicle(tile) && (!IsCompatibleRail(GetRailType(tile), totype) || IsPlainRailTile(tile))) return CMD_ERROR;
+	if (GetRailType(tile) == totype) return CMD_ERROR;
 
-	// tile is already of requested type?
-	if (GetRailType(tile) == totype) return CMD_ERROR;
+	if (!EnsureNoVehicle(tile) && (!IsCompatibleRail(GetRailType(tile), totype) || IsPlainRailTile(tile))) return CMD_ERROR;
 
 	// 'hidden' elrails can't be downgraded to normal rail when elrails are disabled
 	if (_patches.disable_elrails && totype == RAILTYPE_RAIL && GetRailType(tile) == RAILTYPE_ELECTRIC) return CMD_ERROR;