mirror of https://github.com/OpenTTD/OpenTTD
(svn r21835) -Codechange: use UpdateStatusAfterSwap() instead of copying the same code three times
parent
488b525161
commit
772de6b52d
|
@ -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)
|
static void ReverseTrainSwapVeh(Train *v, int l, int r)
|
||||||
{
|
{
|
||||||
Train *a, *b;
|
Train *a, *b;
|
||||||
|
@ -1460,11 +1477,6 @@ static void ReverseTrainSwapVeh(Train *v, int l, int r)
|
||||||
|
|
||||||
Swap(a->track, b->track);
|
Swap(a->track, b->track);
|
||||||
Swap(a->direction, b->direction);
|
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->x_pos, b->x_pos);
|
||||||
Swap(a->y_pos, b->y_pos);
|
Swap(a->y_pos, b->y_pos);
|
||||||
Swap(a->tile, b->tile);
|
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);
|
SwapTrainFlags(&a->gv_flags, &b->gv_flags);
|
||||||
|
|
||||||
/* update other vars */
|
UpdateStatusAfterSwap(a);
|
||||||
a->UpdateViewport(true, true);
|
UpdateStatusAfterSwap(b);
|
||||||
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);
|
|
||||||
} else {
|
} else {
|
||||||
if (a->track != TRACK_BIT_DEPOT) a->direction = ReverseDir(a->direction);
|
UpdateStatusAfterSwap(a);
|
||||||
a->UpdateViewport(true, true);
|
|
||||||
|
|
||||||
if (a->track != TRACK_BIT_WORMHOLE) VehicleEnterTile(a, a->tile, a->x_pos, a->y_pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update power of the train in case tiles were different rail type. */
|
/* Update power of the train in case tiles were different rail type. */
|
||||||
|
|
Loading…
Reference in New Issue