(svn r21911) -Codechange: move tcache.last_speed to gcache.last_speed and make SetLastSpeed a function of GroundVehicle

This commit is contained in:
rubidium
2011-01-26 17:31:07 +00:00
parent 02f3de6d1f
commit 0f411f9899
4 changed files with 26 additions and 19 deletions

View File

@@ -1395,17 +1395,6 @@ void Train::UpdateDeltaXY(Direction direction)
this->z_extent = 6;
}
static inline void SetLastSpeed(Train *v, int spd)
{
int old = v->tcache.last_speed;
if (spd != old) {
v->tcache.last_speed = spd;
if (_settings_client.gui.vehicle_speed || (old == 0) != (spd == 0)) {
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
}
}
}
/** Mark a train as stuck and stop it if it isn't stopped right now. */
static void MarkTrainAsStuck(Train *v)
{
@@ -1418,7 +1407,7 @@ static void MarkTrainAsStuck(Train *v)
/* Stop train */
v->cur_speed = 0;
v->subspeed = 0;
SetLastSpeed(v, 0);
v->SetLastSpeed();
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
}
@@ -1843,7 +1832,7 @@ CommandCost CmdReverseTrainDirection(TileIndex tile, DoCommandFlag flags, uint32
ToggleBit(v->flags, VRF_REVERSING);
} else {
v->cur_speed = 0;
SetLastSpeed(v, 0);
v->SetLastSpeed();
HideFillingPercent(&v->fill_percent_te_id);
ReverseTrainDirection(v);
}
@@ -3659,7 +3648,7 @@ static bool TrainLocoHandler(Train *v, bool mode)
int adv_spd = v->GetAdvanceDistance();
if (j < adv_spd) {
/* if the vehicle has speed 0, update the last_speed field. */
if (v->cur_speed == 0) SetLastSpeed(v, v->cur_speed);
if (v->cur_speed == 0) v->SetLastSpeed();
} else {
TrainCheckIfLineEnds(v);
/* Loop until the train has finished moving. */
@@ -3683,7 +3672,7 @@ static bool TrainLocoHandler(Train *v, bool mode)
ProcessOrders(v);
}
}
SetLastSpeed(v, v->cur_speed);
v->SetLastSpeed();
}
for (Train *u = v; u != NULL; u = u->Next()) {