Changeset - r28342:789af7f79bae
[Not reviewed]
master
0 1 0
Peter Nelson - 4 months ago 2023-12-28 18:11:26
peter1138@openttd.org
Codechange: Replace reliability magic numbers with constants.

These are derived as a percentage of UINT16_MAX.
1 file changed with 15 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/engine.cpp
Show inline comments
 
@@ -717,12 +717,23 @@ void StartupOneEngine(Engine *e, TimerGa
 
	              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;
0 comments (0 inline, 0 general)