Codechange: Use helper function for company recolour offset (#14740)

This commit is contained in:
Rito12
2025-11-03 13:25:32 +01:00
committed by dP
parent a588ba960d
commit b19380969c
3 changed files with 15 additions and 7 deletions

View File

@@ -185,6 +185,18 @@ struct Company : CompanyProperties, CompanyPool::PoolItem<&_company_pool> {
return !Company::Get(index)->is_ai;
}
/**
* Get offset for recolour palette of specific company.
* @param livery_scheme Scheme to use for recolour.
* @param use_secondary Specify whether to add secondary colour offset to the result.
* @return palette offset.
*/
inline uint8_t GetCompanyRecolourOffset(LiveryScheme livery_scheme, bool use_secondary = true) const
{
const Livery &l = this->livery[livery_scheme];
return use_secondary ? l.colour1 + l.colour2 * 16 : l.colour1;
}
static void PostDestructor(size_t index);
};

View File

@@ -246,10 +246,8 @@ static uint32_t GetCountAndDistanceOfClosestInstance(const ResolverObject &objec
const Company *c = Company::GetIfValid(this->industry->founder);
if (c != nullptr) {
const Livery *l = &c->livery[LS_DEFAULT];
is_ai = c->is_ai;
colours = l->colour1 + l->colour2 * 16;
colours = c->GetCompanyRecolourOffset(LS_DEFAULT);
}
return this->industry->founder.base() | (is_ai ? 0x10000 : 0) | (colours << 24);

View File

@@ -97,8 +97,7 @@ void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town, u
if (owner == OWNER_NONE) {
o->colour = Random();
} else {
const Livery &l = Company::Get(owner)->livery[0];
o->colour = l.colour1 + l.colour2 * 16;
o->colour = Company::Get(owner)->GetCompanyRecolourOffset(LS_DEFAULT);
}
/* If the object wants only one colour, then give it that colour. */
@@ -193,8 +192,7 @@ void UpdateObjectColours(const Company *c)
/* Using the object colour callback, so not using company colour. */
if (spec->callback_mask.Test(ObjectCallbackMask::Colour)) continue;
const Livery &l = c->livery[0];
obj->colour = (spec->flags.Test(ObjectFlag::Uses2CC) ? (l.colour2 * 16) : 0) + l.colour1;
obj->colour = c->GetCompanyRecolourOffset(LS_DEFAULT, spec->flags.Test(ObjectFlag::Uses2CC));
}
}