From b3b8c3fd2d19694b91f2ebdd835445cd8022095b Mon Sep 17 00:00:00 2001 From: Rubidium Date: Fri, 13 Jan 2023 22:30:18 +0100 Subject: [PATCH] Codechange: pass the randomizer to use directly to the company face generation --- src/company_cmd.cpp | 2 +- src/company_gui.cpp | 2 +- src/company_manager_face.h | 8 +++----- src/script/api/script_company.cpp | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index a4e5fc9c3b..58da230836 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -573,7 +573,7 @@ Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY) if (_company_manager_face != 0 && !is_ai && !_networking) { c->face = _company_manager_face; } else { - RandomCompanyManagerFaceBits(c->face, (GenderEthnicity)Random(), false, false); + RandomCompanyManagerFaceBits(c->face, (GenderEthnicity)Random(), false, _random); } SetDefaultCompanySettings(c->index); diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 3d8fe8896b..3649e79c21 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -1694,7 +1694,7 @@ public: /* Randomize face button */ case WID_SCMF_RANDOM_NEW_FACE: - RandomCompanyManagerFaceBits(this->face, this->ge, this->advanced); + RandomCompanyManagerFaceBits(this->face, this->ge, this->advanced, _interactive_random); this->UpdateData(); this->SetDirty(); break; diff --git a/src/company_manager_face.h b/src/company_manager_face.h index fe6365a121..83bfd29e11 100644 --- a/src/company_manager_face.h +++ b/src/company_manager_face.h @@ -199,15 +199,13 @@ static inline void ScaleAllCompanyManagerFaceBits(CompanyManagerFace &cmf) * @param cmf the company manager's face to write the bits to * @param ge the gender and ethnicity of the old company manager's face * @param adv if it for the advanced company manager's face window - * @param interactive is the call from within the user interface? + * @param randomizer the source of random to use for creating the manager face * * @pre scale 'ge' to a valid gender/ethnicity combination */ -static inline void RandomCompanyManagerFaceBits(CompanyManagerFace &cmf, GenderEthnicity ge, bool adv, bool interactive = true) +static inline void RandomCompanyManagerFaceBits(CompanyManagerFace &cmf, GenderEthnicity ge, bool adv, Randomizer &randomizer) { - /* This method is called from a command when not interactive and - * then we must use Random to get the same result on all clients. */ - cmf = interactive ? InteractiveRandom() : Random(); // random all company manager's face bits + cmf = randomizer.Next(); // random all company manager's face bits /* scale ge: 0 == GE_WM, 1 == GE_WF, 2 == GE_BM, 3 == GE_BF (and maybe in future: ...) */ ge = (GenderEthnicity)((uint)ge % GE_END); diff --git a/src/script/api/script_company.cpp b/src/script/api/script_company.cpp index 6a06852da5..c38f85385a 100644 --- a/src/script/api/script_company.cpp +++ b/src/script/api/script_company.cpp @@ -99,7 +99,7 @@ CompanyManagerFace cmf; GenderEthnicity ge = (GenderEthnicity)((gender == GENDER_FEMALE ? (1 << ::GENDER_FEMALE) : 0) | (::InteractiveRandom() & (1 << ETHNICITY_BLACK))); - RandomCompanyManagerFaceBits(cmf, ge, false); + RandomCompanyManagerFaceBits(cmf, ge, false, _interactive_random); return ScriptObject::Command::Do(cmf); }