summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2011-01-18 20:06:56 +0000
committersmatz <smatz@openttd.org>2011-01-18 20:06:56 +0000
commit772de6b52d275831c1244adf869f33e2ae464fa8 (patch)
tree285a265400a1406ebbcfd0c011210034a676620e /src
parent488b525161160fa2ccf0a1e38cf2118447ff4b6a (diff)
downloadopenttd-772de6b52d275831c1244adf869f33e2ae464fa8.tar.xz
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
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. */