summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/train_cmd.cpp36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 600deddca..a96d87b25 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -1442,6 +1442,23 @@ static void SwapTrainFlags(uint16 *swap_flag1, uint16 *swap_flag2)
}
}
+/**
+ * Updates some variables after swapping the vehicle.
+ * @param v swapped vehicle
+ */
+static void UpdateStatusAfterSwap(Train *v)
+{
+ /* Reverse the direction. */
+ if (v->track != TRACK_BIT_DEPOT) v->direction = ReverseDir(v->direction);
+
+ /* Call the proper EnterTile function unless we are in a wormhole. */
+ if (v->track != TRACK_BIT_WORMHOLE) {
+ VehicleEnterTile(v, v->tile, v->x_pos, v->y_pos);
+ }
+
+ v->UpdateViewport(true, true);
+}
+
static void ReverseTrainSwapVeh(Train *v, int l, int r)
{
Train *a, *b;
@@ -1460,11 +1477,6 @@ static void ReverseTrainSwapVeh(Train *v, int l, int r)
Swap(a->track, b->track);
Swap(a->direction, b->direction);
-
- /* toggle direction */
- if (a->track != TRACK_BIT_DEPOT) a->direction = ReverseDir(a->direction);
- if (b->track != TRACK_BIT_DEPOT) b->direction = ReverseDir(b->direction);
-
Swap(a->x_pos, b->x_pos);
Swap(a->y_pos, b->y_pos);
Swap(a->tile, b->tile);
@@ -1472,18 +1484,10 @@ static void ReverseTrainSwapVeh(Train *v, int l, int r)
SwapTrainFlags(&a->gv_flags, &b->gv_flags);
- /* update other vars */
- a->UpdateViewport(true, true);
- b->UpdateViewport(true, true);
-
- /* call the proper EnterTile function unless we are in a wormhole */
- if (a->track != TRACK_BIT_WORMHOLE) VehicleEnterTile(a, a->tile, a->x_pos, a->y_pos);
- if (b->track != TRACK_BIT_WORMHOLE) VehicleEnterTile(b, b->tile, b->x_pos, b->y_pos);
+ UpdateStatusAfterSwap(a);
+ UpdateStatusAfterSwap(b);
} else {
- if (a->track != TRACK_BIT_DEPOT) a->direction = ReverseDir(a->direction);
- a->UpdateViewport(true, true);
-
- if (a->track != TRACK_BIT_WORMHOLE) VehicleEnterTile(a, a->tile, a->x_pos, a->y_pos);
+ UpdateStatusAfterSwap(a);
}
/* Update power of the train in case tiles were different rail type. */