1
0
Fork 0

(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times

release/1.1
smatz 2011-01-18 20:06:56 +00:00
parent 488b525161
commit 772de6b52d
1 changed files with 20 additions and 16 deletions

View File

@ -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. */