summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2007-05-28 21:40:40 +0000
committerbjarni <bjarni@openttd.org>2007-05-28 21:40:40 +0000
commita6bea527a3af7657947e3c71fc99fdef3858384b (patch)
treee7f1ab431b0a2d5ff6e50b4805c168c6833a0bdb /src
parentdf1bbe55e2096d327d412870768884c6be12685c (diff)
downloadopenttd-a6bea527a3af7657947e3c71fc99fdef3858384b.tar.xz
(svn r9967) -Fix (r9938): autoreplace would in certain conditions move dualheaded engines in a train (usually to the rear)
-Change: moving an engine in between the two ends of a dualheaded engine will now move the rear dualheaded engine to the front of the newly added engine (instead of moving the new engine to the rear of the rear dualheaded engine) This can make a difference if there are wagons in the train
Diffstat (limited to 'src')
-rw-r--r--src/autoreplace_cmd.cpp3
-rw-r--r--src/train_cmd.cpp33
2 files changed, 3 insertions, 33 deletions
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp
index 5d1dce962..6bcab4ca5 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -195,7 +195,10 @@ static int32 ReplaceVehicle(Vehicle **w, byte flags, int32 total_cost)
* We add the new engine after the old one instead of replacing it. It will give the same result anyway when we
* sell the old engine in a moment
*/
+ /* Get the vehicle in front of the one we move out */
Vehicle *front = GetPrevVehicleInChain(old_v);
+ /* If the vehicle in front is the rear end of a dualheaded engine, then we need to use the one in front of that one */
+ if (IsMultiheaded(front) && !IsTrainEngine(front)) front = GetPrevVehicleInChain(front);
/* Now we move the old one out of the train */
DoCommand(0, (INVALID_VEHICLE << 16) | old_v->index, 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
/* Add the new vehicle */
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 1c2fe227a..c15b2a233 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -1017,39 +1017,6 @@ int32 CmdMoveRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
dst_head = NULL;
}
- if (dst != NULL && IsMultiheaded(dst) && !IsTrainEngine(dst) && IsTrainWagon(src)) {
- /* We are moving a wagon to the rear part of a multiheaded engine */
- if (dst->next == NULL) {
- /* It's the last one, so we will add the wagon just before the rear engine */
- dst = GetPrevVehicleInChain(dst);
- /* Now if the vehicle we want to link to is the vehicle itself, drop out */
- if (dst == src) return CMD_ERROR;
- /* if dst is NULL, it means that dst got a rear multiheaded engine as first engine. We can't use that */
- if (dst == NULL) return CMD_ERROR;
- } else {
- /* there are more units on this train, so we will add the wagon after the next one*/
- dst = dst->next;
- }
- }
-
- if (IsTrainEngine(src) && dst_head != NULL) {
- /* we need to make sure that we didn't place it between a pair of multiheaded engines */
- Vehicle *engine = NULL;
-
- for (Vehicle *u = dst_head; u != NULL; u = u->next) {
- if (IsTrainEngine(u) && IsMultiheaded(u) && u->u.rail.other_multiheaded_part != NULL) {
- engine = u;
- }
- if (engine != NULL && engine->u.rail.other_multiheaded_part == u) {
- engine = NULL;
- }
- if (u == dst) {
- if (engine != NULL) dst = engine->u.rail.other_multiheaded_part;
- break;
- }
- }
- }
-
if (IsMultiheaded(src) && !IsTrainEngine(src)) return_cmd_error(STR_REAR_ENGINE_FOLLOW_FRONT_ERROR);
/* when moving all wagons, we can't have the same src_head and dst_head */