* Accelerates the ship towards its target speed. * @param v Ship to accelerate. * @return Number of steps to move the ship. */
| 412 | * @return Number of steps to move the ship. |
| 413 | */ |
| 414 | static uint ShipAccelerate(Vehicle *v) |
| 415 | { |
| 416 | uint speed; |
| 417 | speed = std::min<uint>(v->cur_speed + v->acceleration, v->vcache.cached_max_speed); |
| 418 | speed = std::min<uint>(speed, v->current_order.GetMaxSpeed() * 2); |
| 419 | |
| 420 | /* updates statusbar only if speed have changed to save CPU time */ |
| 421 | if (speed != v->cur_speed) { |
| 422 | v->cur_speed = speed; |
| 423 | SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP); |
| 424 | } |
| 425 | |
| 426 | const uint advance_speed = v->GetAdvanceSpeed(speed); |
| 427 | const uint number_of_steps = (advance_speed + v->progress) / v->GetAdvanceDistance(); |
| 428 | const uint remainder = (advance_speed + v->progress) % v->GetAdvanceDistance(); |
| 429 | assert(remainder <= std::numeric_limits<uint8_t>::max()); |
| 430 | v->progress = static_cast<uint8_t>(remainder); |
| 431 | return number_of_steps; |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * Ship arrives at a dock. If it is the first time, send out a news item. |
no test coverage detected