summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcelestar <celestar@openttd.org>2007-03-24 09:12:03 +0000
committercelestar <celestar@openttd.org>2007-03-24 09:12:03 +0000
commit49ff7cb9389ca6a2611738fae6b338d7e8a83c3b (patch)
tree0609b0f1d83ccc09e2f2cdf84583392216005ed5 /src
parentd5f16924d92a7cb793b891118ffc074d902c20a6 (diff)
downloadopenttd-49ff7cb9389ca6a2611738fae6b338d7e8a83c3b.tar.xz
(svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
Diffstat (limited to 'src')
-rw-r--r--src/rail_cmd.cpp15
-rw-r--r--src/road_cmd.cpp10
-rw-r--r--src/station_cmd.cpp10
-rw-r--r--src/tunnelbridge_cmd.cpp14
4 files changed, 42 insertions, 7 deletions
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index ed6f39649..1c5f3603c 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -849,15 +849,24 @@ int32 CmdRemoveSignalTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
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;
-
- // 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;
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index b95df8bc1..8ffb07aba 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -367,6 +367,14 @@ do_clear:;
return cost;
}
+/**
+ * Switches the rail type on a level crossing.
+ * @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.
+ */
int32 DoConvertStreetRail(TileIndex tile, RailType totype, bool exec)
{
// not a railroad crossing?
@@ -386,7 +394,7 @@ int32 DoConvertStreetRail(TileIndex tile, RailType totype, bool exec)
YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetCrossingRailBits(tile)));
}
- return _price.build_rail >> 1;
+ return _price.build_rail / 2;
}
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 09153ba39..6341fd7df 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -1120,6 +1120,14 @@ static int32 RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags)
return cost;
}
+/**
+ * Switches the rail type at a railway station tile.
+ * @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.
+ */
int32 DoConvertStationRail(TileIndex tile, RailType totype, bool exec)
{
const Station* st = GetStationByTile(tile);
@@ -1140,7 +1148,7 @@ int32 DoConvertStationRail(TileIndex tile, RailType totype, bool exec)
YapfNotifyTrackLayoutChange(tile, GetRailStationTrack(tile));
}
- return _price.build_rail >> 1;
+ return _price.build_rail / 2;
}
/**
diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp
index aa2279d7d..e386da262 100644
--- a/src/tunnelbridge_cmd.cpp
+++ b/src/tunnelbridge_cmd.cpp
@@ -696,6 +696,16 @@ static int32 ClearTile_TunnelBridge(TileIndex tile, byte flags)
return CMD_ERROR;
}
+/**
+ * Switches the rail type for a tunnel or a bridgehead. As the railtype
+ * on the bridge are determined by the one of the bridgehead, this
+ * functions converts the railtype on the entire bridge.
+ * @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.
+ */
int32 DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec)
{
TileIndex endtile;
@@ -724,7 +734,7 @@ int32 DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec)
YapfNotifyTrackLayoutChange(tile, track);
YapfNotifyTrackLayoutChange(endtile, track);
}
- return (length + 1) * (_price.build_rail >> 1);
+ return (length + 1) * (_price.build_rail / 2);
} else if (IsBridge(tile) && GetBridgeTransportType(tile) == TRANSPORT_RAIL) {
if (!CheckTileOwnership(tile)) return CMD_ERROR;
@@ -758,7 +768,7 @@ int32 DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec)
}
}
- return (DistanceManhattan(tile, endtile) + 1) * (_price.build_rail >> 1);
+ return (DistanceManhattan(tile, endtile) + 1) * (_price.build_rail / 2);
} else {
return CMD_ERROR;
}