* Check and update if needed all vehicle service intervals. * @param new_value Contains 0 if service intervals are in time (days or real-world minutes), otherwise intervals use percents. */
| 193 | * @param new_value Contains 0 if service intervals are in time (days or real-world minutes), otherwise intervals use percents. |
| 194 | */ |
| 195 | static void UpdateAllServiceInterval(int32_t new_value) |
| 196 | { |
| 197 | bool update_vehicles; |
| 198 | VehicleDefaultSettings *vds; |
| 199 | if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) { |
| 200 | vds = &_settings_client.company.vehicle; |
| 201 | update_vehicles = false; |
| 202 | } else { |
| 203 | vds = &Company::Get(_current_company)->settings.vehicle; |
| 204 | update_vehicles = true; |
| 205 | } |
| 206 | |
| 207 | if (new_value != 0) { |
| 208 | /* Service intervals are in percents. */ |
| 209 | vds->servint_trains = DEF_SERVINT_PERCENT; |
| 210 | vds->servint_roadveh = DEF_SERVINT_PERCENT; |
| 211 | vds->servint_aircraft = DEF_SERVINT_PERCENT; |
| 212 | vds->servint_ships = DEF_SERVINT_PERCENT; |
| 213 | } else if (TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU)) { |
| 214 | /* Service intervals are in minutes. */ |
| 215 | vds->servint_trains = DEF_SERVINT_MINUTES_TRAINS; |
| 216 | vds->servint_roadveh = DEF_SERVINT_MINUTES_ROADVEH; |
| 217 | vds->servint_aircraft = DEF_SERVINT_MINUTES_AIRCRAFT; |
| 218 | vds->servint_ships = DEF_SERVINT_MINUTES_SHIPS; |
| 219 | } else { |
| 220 | /* Service intervals are in days. */ |
| 221 | vds->servint_trains = DEF_SERVINT_DAYS_TRAINS; |
| 222 | vds->servint_roadveh = DEF_SERVINT_DAYS_ROADVEH; |
| 223 | vds->servint_aircraft = DEF_SERVINT_DAYS_AIRCRAFT; |
| 224 | vds->servint_ships = DEF_SERVINT_DAYS_SHIPS; |
| 225 | } |
| 226 | |
| 227 | if (update_vehicles) { |
| 228 | const Company *c = Company::Get(_current_company); |
| 229 | for (Vehicle *v : Vehicle::Iterate()) { |
| 230 | if (v->owner == _current_company && v->IsPrimaryVehicle() && !v->ServiceIntervalIsCustom()) { |
| 231 | v->SetServiceInterval(CompanyServiceInterval(c, v->type)); |
| 232 | v->SetServiceIntervalIsPercent(new_value != 0); |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | SetWindowClassesDirty(WC_VEHICLE_DETAILS); |
| 238 | } |
| 239 | |
| 240 | static bool CanUpdateServiceInterval(VehicleType, int32_t &new_value) |
| 241 | { |
no test coverage detected