* Check whether a train needs service, and if so, find a depot or service it. * @return v %Train to check. */
| 4142 | * @return v %Train to check. |
| 4143 | */ |
| 4144 | static void CheckIfTrainNeedsService(Train *v) |
| 4145 | { |
| 4146 | if (Company::Get(v->owner)->settings.vehicle.servint_trains == 0 || !v->NeedsAutomaticServicing()) return; |
| 4147 | if (v->IsChainInDepot()) { |
| 4148 | VehicleServiceInDepot(v); |
| 4149 | return; |
| 4150 | } |
| 4151 | |
| 4152 | uint max_penalty = _settings_game.pf.yapf.maximum_go_to_depot_penalty; |
| 4153 | |
| 4154 | FindDepotData tfdd = FindClosestTrainDepot(v, max_penalty); |
| 4155 | /* Only go to the depot if it is not too far out of our way. */ |
| 4156 | if (tfdd.best_length == UINT_MAX || tfdd.best_length > max_penalty) { |
| 4157 | if (v->current_order.IsType(OT_GOTO_DEPOT)) { |
| 4158 | /* If we were already heading for a depot but it has |
| 4159 | * suddenly moved farther away, we continue our normal |
| 4160 | * schedule? */ |
| 4161 | v->current_order.MakeDummy(); |
| 4162 | SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP); |
| 4163 | } |
| 4164 | return; |
| 4165 | } |
| 4166 | |
| 4167 | DepotID depot = GetDepotIndex(tfdd.tile); |
| 4168 | |
| 4169 | if (v->current_order.IsType(OT_GOTO_DEPOT) && |
| 4170 | v->current_order.GetDestination() != depot && |
| 4171 | !Chance16(3, 16)) { |
| 4172 | return; |
| 4173 | } |
| 4174 | |
| 4175 | SetBit(v->gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS); |
| 4176 | v->current_order.MakeGoToDepot(depot, OrderDepotTypeFlag::Service, OrderNonStopFlag::NoIntermediate, OrderDepotActionFlag::NearestDepot); |
| 4177 | v->dest_tile = tfdd.tile; |
| 4178 | SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP); |
| 4179 | } |
| 4180 | |
| 4181 | /** Calendar day handler. */ |
| 4182 | void Train::OnNewCalendarDay() |
no test coverage detected