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

Function UpdateLoadUnloadTicks

src/economy.cpp:1597–1609  ·  view source on GitHub ↗

* Update the vehicle's load_unload_ticks, the time it will wait until it tries to load or unload * again. Adjust for overhang of trains and set it at least to 1. * @param front The vehicle to be updated. * @param st The station the vehicle is loading at. * @param ticks The time it would normally wait, based on cargo loaded and unloaded. */

Source from the content-addressed store, hash-verified

1595 * @param ticks The time it would normally wait, based on cargo loaded and unloaded.
1596 */
1597static void UpdateLoadUnloadTicks(Vehicle *front, const Station *st, int ticks)
1598{
1599 if (front->type == VEH_TRAIN && _settings_game.order.station_length_loading_penalty) {
1600 /* Each platform tile is worth 2 rail vehicles. */
1601 int overhang = front->GetGroundVehicleCache()->cached_total_length - st->GetPlatformLength(front->tile) * TILE_SIZE;
1602 if (overhang > 0) {
1603 ticks <<= 1;
1604 ticks += (overhang * ticks) / 8;
1605 }
1606 }
1607 /* Always wait at least 1, otherwise we'll wait 'infinitively' long. */
1608 front->load_unload_ticks = std::max(1, ticks);
1609}
1610
1611/**
1612 * Loads/unload the vehicle if possible.

Callers 1

LoadUnloadVehicleFunction · 0.85

Calls 2

GetGroundVehicleCacheMethod · 0.80
GetPlatformLengthMethod · 0.45

Tested by

no test coverage detected