* Update #Engine::reliability and (if needed) update the engine GUIs. * @param e %Engine to update. */
| 644 | * @param e %Engine to update. |
| 645 | */ |
| 646 | void CalcEngineReliability(Engine *e, bool new_month) |
| 647 | { |
| 648 | /* Get source engine for reliability age. This is normally our engine unless variant reliability syncing is requested. */ |
| 649 | Engine *re = e; |
| 650 | while (re->info.variant_id != EngineID::Invalid() && re->info.extra_flags.Test(ExtraEngineFlag::SyncReliability)) { |
| 651 | re = Engine::Get(re->info.variant_id); |
| 652 | } |
| 653 | |
| 654 | uint32_t age = re->age; |
| 655 | if (new_month && re->index > e->index && age != INT32_MAX) age++; /* parent variant's age has not yet updated. */ |
| 656 | |
| 657 | /* Check for early retirement */ |
| 658 | if (e->company_avail.Any() && !_settings_game.vehicle.never_expire_vehicles && e->info.base_life != 0xFF) { |
| 659 | int retire_early = e->info.retire_early; |
| 660 | uint retire_early_max_age = std::max(0, e->duration_phase_1 + e->duration_phase_2 - retire_early * 12); |
| 661 | if (retire_early != 0 && age >= retire_early_max_age) { |
| 662 | /* Early retirement is enabled and we're past the date... */ |
| 663 | e->company_avail = CompanyMask{}; |
| 664 | ClearLastVariant(e->index, e->type); |
| 665 | AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | if (age < e->duration_phase_1) { |
| 670 | uint start = e->reliability_start; |
| 671 | e->reliability = age * (e->reliability_max - start) / e->duration_phase_1 + start; |
| 672 | } else if ((age -= e->duration_phase_1) < e->duration_phase_2 || _settings_game.vehicle.never_expire_vehicles || e->info.base_life == 0xFF) { |
| 673 | /* We are at the peak of this engines life. It will have max reliability. |
| 674 | * This is also true if the engines never expire. They will not go bad over time */ |
| 675 | e->reliability = e->reliability_max; |
| 676 | } else if ((age -= e->duration_phase_2) < e->duration_phase_3) { |
| 677 | uint max = e->reliability_max; |
| 678 | e->reliability = (int)age * (int)(e->reliability_final - max) / e->duration_phase_3 + max; |
| 679 | } else { |
| 680 | /* time's up for this engine. |
| 681 | * We will now completely retire this design */ |
| 682 | e->company_avail = CompanyMask{}; |
| 683 | e->reliability = e->reliability_final; |
| 684 | /* Kick this engine out of the lists */ |
| 685 | ClearLastVariant(e->index, e->type); |
| 686 | AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); |
| 687 | } |
| 688 | |
| 689 | } |
| 690 | |
| 691 | /** Compute the value for #_year_engine_aging_stops. */ |
| 692 | void SetYearEngineAgingStops() |
no test coverage detected