summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2014-01-26 14:54:34 +0000
committerfrosch <frosch@openttd.org>2014-01-26 14:54:34 +0000
commit5d4c4b9172632fa069592298e2f86a3259ff760c (patch)
tree62244f3234c85d4104cbfac8cc5f2ec84313f369 /src
parentcce3d4fec805ae3c55d24a9d05cbc6c1a3aeba99 (diff)
downloadopenttd-5d4c4b9172632fa069592298e2f86a3259ff760c.tar.xz
(svn r26279) -Fix [FS#5853]: [NoAI] Some RemoveRail methods required to set a valid railtype, though it was not used anyway. Remove the need to set one.
Diffstat (limited to 'src')
-rw-r--r--src/rail_cmd.cpp8
-rw-r--r--src/script/api/script_rail.cpp7
2 files changed, 7 insertions, 8 deletions
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index 1b2d64d7f..f471af23d 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -821,7 +821,7 @@ static CommandCost ValidateAutoDrag(Trackdir *trackdir, TileIndex start, TileInd
* @param flags operation to perform
* @param p1 end tile of drag
* @param p2 various bitstuffed elements
- * - p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev)
+ * - p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev), only used for building
* - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
* - p2 = (bit 7) - 0 = build, 1 = remove tracks
* - p2 = (bit 8) - 0 = build up to an obstacle, 1 = fail if an obstacle is found (used for AIs).
@@ -835,7 +835,7 @@ static CommandCost CmdRailTrackHelper(TileIndex tile, DoCommandFlag flags, uint3
bool remove = HasBit(p2, 7);
RailType railtype = Extract<RailType, 0, 4>(p2);
- if (!ValParamRailtype(railtype) || !ValParamTrackOrientation(track)) return CMD_ERROR;
+ if ((!remove && !ValParamRailtype(railtype)) || !ValParamTrackOrientation(track)) return CMD_ERROR;
if (p1 >= MapSize()) return CMD_ERROR;
TileIndex end_tile = p1;
Trackdir trackdir = TrackToTrackdir(track);
@@ -846,7 +846,7 @@ static CommandCost CmdRailTrackHelper(TileIndex tile, DoCommandFlag flags, uint3
bool had_success = false;
CommandCost last_error = CMD_ERROR;
for (;;) {
- CommandCost ret = DoCommand(tile, railtype, TrackdirToTrack(trackdir), flags, remove ? CMD_REMOVE_SINGLE_RAIL : CMD_BUILD_SINGLE_RAIL);
+ CommandCost ret = DoCommand(tile, remove ? 0 : railtype, TrackdirToTrack(trackdir), flags, remove ? CMD_REMOVE_SINGLE_RAIL : CMD_BUILD_SINGLE_RAIL);
if (ret.Failed()) {
last_error = ret;
@@ -900,7 +900,7 @@ CommandCost CmdBuildRailroadTrack(TileIndex tile, DoCommandFlag flags, uint32 p1
* @param flags operation to perform
* @param p1 end tile of drag
* @param p2 various bitstuffed elements
- * - p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev)
+ * - p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev), only used for building
* - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
* - p2 = (bit 7) - 0 = build, 1 = remove tracks
* @param text unused
diff --git a/src/script/api/script_rail.cpp b/src/script/api/script_rail.cpp
index 161007de9..26317a72c 100644
--- a/src/script/api/script_rail.cpp
+++ b/src/script/api/script_rail.cpp
@@ -253,7 +253,7 @@
EnforcePrecondition(false, GetRailTracks(tile) & rail_track);
EnforcePrecondition(false, KillFirstBit((uint)rail_track) == 0);
- return ScriptObject::DoCommand(tile, tile, GetCurrentRailType() | (FindFirstTrack((::TrackBits)rail_track) << 4), CMD_REMOVE_RAILROAD_TRACK);
+ return ScriptObject::DoCommand(tile, tile, FindFirstTrack((::TrackBits)rail_track) << 4, CMD_REMOVE_RAILROAD_TRACK);
}
/* static */ bool ScriptRail::AreTilesConnected(TileIndex from, TileIndex tile, TileIndex to)
@@ -284,7 +284,7 @@
static uint32 SimulateDrag(TileIndex from, TileIndex tile, TileIndex *to)
{
int diag_offset = abs(abs((int)::TileX(*to) - (int)::TileX(tile)) - abs((int)::TileY(*to) - (int)::TileY(tile)));
- uint32 p2 = ScriptRail::GetCurrentRailType();
+ uint32 p2 = 0;
if (::TileY(from) == ::TileY(*to)) {
p2 |= (TRACK_X << 4);
*to -= Clamp((int)::TileX(*to) - (int)::TileX(tile), -1, 1);
@@ -353,7 +353,7 @@ static uint32 SimulateDrag(TileIndex from, TileIndex tile, TileIndex *to)
(::TileX(from) == ::TileX(tile) && ::TileX(tile) == ::TileX(to)) ||
(::TileY(from) == ::TileY(tile) && ::TileY(tile) == ::TileY(to)));
- uint32 p2 = SimulateDrag(from, tile, &to) | 1 << 8;
+ uint32 p2 = SimulateDrag(from, tile, &to) | 1 << 8 | ScriptRail::GetCurrentRailType();;
return ScriptObject::DoCommand(tile, to, p2, CMD_BUILD_RAILROAD_TRACK);
}
@@ -370,7 +370,6 @@ static uint32 SimulateDrag(TileIndex from, TileIndex tile, TileIndex *to)
(::TileX(from) == ::TileX(tile) && ::TileX(tile) == ::TileX(to)) ||
(::TileY(from) == ::TileY(tile) && ::TileY(tile) == ::TileY(to)));
- if (!IsRailTypeAvailable(GetCurrentRailType())) SetCurrentRailType(GetRailType(tile));
uint32 p2 = SimulateDrag(from, tile, &to);
return ScriptObject::DoCommand(tile, to, p2, CMD_REMOVE_RAILROAD_TRACK);
}