MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ShipAccelerate

Function ShipAccelerate

src/ship_cmd.cpp:414–432  ·  view source on GitHub ↗

* Accelerates the ship towards its target speed. * @param v Ship to accelerate. * @return Number of steps to move the ship. */

Source from the content-addressed store, hash-verified

412 * @return Number of steps to move the ship.
413 */
414static 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.

Callers 1

ShipControllerFunction · 0.85

Calls 4

SetWindowWidgetDirtyFunction · 0.85
GetAdvanceSpeedMethod · 0.80
GetAdvanceDistanceMethod · 0.80
GetMaxSpeedMethod · 0.45

Tested by

no test coverage detected