Mercurial > hg > openttd
changeset 17098:5035955400bc draft
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
author | smatz <smatz@openttd.org> |
---|---|
date | Tue, 18 Jan 2011 20:06:56 +0000 |
parents | 6d078ffe055b |
children | b23e23e3904a |
files | src/train_cmd.cpp |
diffstat | 1 files changed, 20 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -1442,6 +1442,23 @@ } } +/** + * 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 @@ 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 @@ 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. */