Codechange: Replace reliability magic numbers with constants.

These are derived as a percentage of UINT16_MAX.
This commit is contained in:
Peter Nelson 2023-12-28 18:11:26 +00:00 committed by Peter Nelson
parent 7b2c143df0
commit bd3b28551e
1 changed files with 15 additions and 4 deletions

View File

@ -717,12 +717,23 @@ void StartupOneEngine(Engine *e, TimerGameCalendar::Date aging_date, uint32_t se
e->type ^
e->GetGRFID());
r = Random();
e->reliability_start = GB(r, 16, 14) + 0x7AE0;
e->reliability_max = GB(r, 0, 14) + 0xBFFF;
/* Base reliability defined as a percentage of UINT16_MAX. */
const uint16_t RELIABILITY_START = UINT16_MAX * 48 / 100;
const uint16_t RELIABILITY_MAX = UINT16_MAX * 75 / 100;
const uint16_t RELIABILITY_FINAL = UINT16_MAX * 25 / 100;
static_assert(RELIABILITY_START == 0x7AE0);
static_assert(RELIABILITY_MAX == 0xBFFF);
static_assert(RELIABILITY_FINAL == 0x3FFF);
r = Random();
e->reliability_final = GB(r, 16, 14) + 0x3FFF;
/* 14 bits gives a value between 0 and 16383, which is up to an additional 25%p reliability on top of the base reliability. */
e->reliability_start = GB(r, 16, 14) + RELIABILITY_START;
e->reliability_max = GB(r, 0, 14) + RELIABILITY_MAX;
r = Random();
e->reliability_final = GB(r, 16, 14) + RELIABILITY_FINAL;
e->duration_phase_1 = GB(r, 0, 5) + 7;
e->duration_phase_2 = std::max(0, int(GB(r, 5, 4)) + ei->base_life.base() * 12 - 96);
e->duration_phase_3 = GB(r, 9, 7) + 120;