Fix crash when road vehicle changed length in drive-through road stop
Due to refit and incorrectly implemented NewGRF
This commit is contained in:
@@ -60,6 +60,14 @@ struct RoadStop : RoadStopPool::PoolItem<&_roadstop_pool> {
|
||||
return this->occupied;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust the occupation of this road stop, only to handle vehicles unexpectedly changing length
|
||||
*/
|
||||
inline void AdjustOccupation(int adjustment)
|
||||
{
|
||||
this->occupied += adjustment;
|
||||
}
|
||||
|
||||
void Leave(const RoadVehicle *rv);
|
||||
void Enter(const RoadVehicle *rv);
|
||||
void CheckIntegrity(const RoadStop *rs) const;
|
||||
|
@@ -222,6 +222,7 @@ void RoadVehUpdateCache(RoadVehicle *v, bool same_length)
|
||||
|
||||
v->InvalidateNewGRFCacheOfChain();
|
||||
|
||||
const uint16_t old_total_length = v->gcache.cached_total_length;
|
||||
v->gcache.cached_total_length = 0;
|
||||
|
||||
Vehicle *last_vis_effect = v;
|
||||
@@ -257,6 +258,13 @@ void RoadVehUpdateCache(RoadVehicle *v, bool same_length)
|
||||
|
||||
uint max_speed = GetVehicleProperty(v, PROP_ROADVEH_SPEED, 0);
|
||||
v->vcache.cached_max_speed = (max_speed != 0) ? max_speed * 4 : RoadVehInfo(v->engine_type)->max_speed;
|
||||
|
||||
if (same_length && old_total_length != v->gcache.cached_total_length) {
|
||||
if (IsInsideMM(v->state, RVSB_IN_DT_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END)) {
|
||||
RoadStop *rs = RoadStop::GetByTile(v->tile, GetRoadStopType(v->tile));
|
||||
rs->GetEntry(v)->AdjustOccupation((int)v->gcache.cached_total_length - (int)old_total_length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user