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

Method HandleLoading

src/vehicle.cpp:2407–2436  ·  view source on GitHub ↗

* Handle the loading of the vehicle; when not it skips through dummy * orders and does nothing in all other cases. * @param mode is the non-first call for this vehicle in this tick? */

Source from the content-addressed store, hash-verified

2405 * @param mode is the non-first call for this vehicle in this tick?
2406 */
2407void Vehicle::HandleLoading(bool mode)
2408{
2409 switch (this->current_order.GetType()) {
2410 case OT_LOADING: {
2411 TimerGameTick::Ticks wait_time = std::max(this->current_order.GetTimetabledWait() - this->lateness_counter, 0);
2412
2413 /* Not the first call for this tick, or still loading */
2414 if (mode || !this->vehicle_flags.Test(VehicleFlag::LoadingFinished) || this->current_order_time < wait_time) return;
2415
2416 this->PlayLeaveStationSound();
2417
2418 this->LeaveStation();
2419
2420 /* Only advance to next order if we just loaded at the current one */
2421 const Order *order = this->GetOrder(this->cur_implicit_order_index);
2422 if (order == nullptr ||
2423 (!order->IsType(OT_IMPLICIT) && !order->IsType(OT_GOTO_STATION)) ||
2424 order->GetDestination() != this->last_station_visited) {
2425 return;
2426 }
2427 break;
2428 }
2429
2430 case OT_DUMMY: break;
2431
2432 default: return;
2433 }
2434
2435 this->IncrementImplicitOrderIndex();
2436}
2437
2438/**
2439 * Check if the current vehicle has a full load order.

Callers 4

ShipControllerFunction · 0.80
TrainLocoHandlerFunction · 0.80
RoadVehControllerFunction · 0.80
AircraftEventHandlerFunction · 0.80

Calls 9

PlayLeaveStationSoundMethod · 0.95
LeaveStationMethod · 0.95
GetOrderMethod · 0.95
GetTimetabledWaitMethod · 0.80
TestMethod · 0.80
IsTypeMethod · 0.80
GetDestinationMethod · 0.80
GetTypeMethod · 0.45

Tested by

no test coverage detected