diff --git a/src/vehicle_base.h b/src/vehicle_base.h --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -309,6 +309,21 @@ public: virtual void OnNewDay() {}; /** + * Update vehicle sprite- and position caches + * @param moved Was the vehicle moved? + * @param turned Did the vehicle direction change? + */ + inline void UpdateViewport(bool moved, bool turned) + { + extern void VehicleMove(Vehicle *v, bool update_viewport); + + if (turned) this->UpdateDeltaXY(this->direction); + SpriteID old_image = this->cur_image; + this->cur_image = this->GetImage(this->direction); + if (moved || this->cur_image != old_image) VehicleMove(this, true); + } + + /** * Returns the Trackdir on which the vehicle is currently located. * Works for trains and ships. * Currently works only sortof for road vehicles, since they have a fuzzy