1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-20 19:02:41 +01:00

Change: New company face definition system and UI. (#14319)

Bits used by company faces are now defined by a variable system instead of being hardcoded, allowing future expansion.

The four face types covering gender and skin colour are now separate face styles with their own definitions.
This commit is contained in:
Peter Nelson
2025-06-24 07:59:49 +01:00
committed by GitHub
parent ebc74c8905
commit a46a3a97f3
19 changed files with 785 additions and 763 deletions

View File

@@ -108,12 +108,18 @@
EnforcePrecondition(false, gender == GENDER_MALE || gender == GENDER_FEMALE);
EnforcePrecondition(false, GetPresidentGender(ScriptCompany::COMPANY_SELF) != gender);
Randomizer &randomizer = ScriptObject::GetRandomizer();
CompanyManagerFace cmf;
GenderEthnicity ge = (GenderEthnicity)((gender == GENDER_FEMALE ? (1 << ::GENDER_FEMALE) : 0) | (randomizer.Next() & (1 << ETHNICITY_BLACK)));
RandomCompanyManagerFaceBits(cmf, ge, false, randomizer);
assert(GetNumCompanyManagerFaceStyles() >= 2); /* At least two styles are needed to fake a gender. */
return ScriptObject::Command<CMD_SET_COMPANY_MANAGER_FACE>::Do(cmf);
/* Company faces no longer have a defined gender, so pick a random face style instead. */
Randomizer &randomizer = ScriptObject::GetRandomizer();
CompanyManagerFace cmf{};
do {
cmf.style = randomizer.Next(GetNumCompanyManagerFaceStyles());
} while ((HasBit(cmf.style, 0) ? GENDER_FEMALE : GENDER_MALE) != gender);
RandomiseCompanyManagerFaceBits(cmf, GetCompanyManagerFaceVars(cmf.style), randomizer);
return ScriptObject::Command<CMD_SET_COMPANY_MANAGER_FACE>::Do(cmf.style, cmf.bits);
}
/* static */ ScriptCompany::Gender ScriptCompany::GetPresidentGender(ScriptCompany::CompanyID company)
@@ -121,8 +127,10 @@
company = ResolveCompanyID(company);
if (company == ScriptCompany::COMPANY_INVALID) return GENDER_INVALID;
GenderEthnicity ge = (GenderEthnicity)GetCompanyManagerFaceBits(Company::Get(ScriptCompany::FromScriptCompanyID(company))->face, CMFV_GEN_ETHN, GE_WM);
return HasBit(ge, ::GENDER_FEMALE) ? GENDER_FEMALE : GENDER_MALE;
/* Company faces no longer have a defined gender, so fake one based on the style index. This might not match
* the face appearance. */
const auto &cmf = ::Company::Get(ScriptCompany::FromScriptCompanyID(company))->face;
return HasBit(cmf.style, 0) ? GENDER_FEMALE : GENDER_MALE;
}
/* static */ Money ScriptCompany::GetQuarterlyIncome(ScriptCompany::CompanyID company, SQInteger quarter)