Codechange: Use helper function for company recolour offset (#14740)
This commit is contained in:
@@ -185,6 +185,18 @@ struct Company : CompanyProperties, CompanyPool::PoolItem<&_company_pool> {
|
|||||||
return !Company::Get(index)->is_ai;
|
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);
|
static void PostDestructor(size_t index);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -246,10 +246,8 @@ static uint32_t GetCountAndDistanceOfClosestInstance(const ResolverObject &objec
|
|||||||
|
|
||||||
const Company *c = Company::GetIfValid(this->industry->founder);
|
const Company *c = Company::GetIfValid(this->industry->founder);
|
||||||
if (c != nullptr) {
|
if (c != nullptr) {
|
||||||
const Livery *l = &c->livery[LS_DEFAULT];
|
|
||||||
|
|
||||||
is_ai = c->is_ai;
|
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);
|
return this->industry->founder.base() | (is_ai ? 0x10000 : 0) | (colours << 24);
|
||||||
|
|||||||
@@ -97,8 +97,7 @@ void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town, u
|
|||||||
if (owner == OWNER_NONE) {
|
if (owner == OWNER_NONE) {
|
||||||
o->colour = Random();
|
o->colour = Random();
|
||||||
} else {
|
} else {
|
||||||
const Livery &l = Company::Get(owner)->livery[0];
|
o->colour = Company::Get(owner)->GetCompanyRecolourOffset(LS_DEFAULT);
|
||||||
o->colour = l.colour1 + l.colour2 * 16;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the object wants only one colour, then give it that colour. */
|
/* 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. */
|
/* Using the object colour callback, so not using company colour. */
|
||||||
if (spec->callback_mask.Test(ObjectCallbackMask::Colour)) continue;
|
if (spec->callback_mask.Test(ObjectCallbackMask::Colour)) continue;
|
||||||
|
|
||||||
const Livery &l = c->livery[0];
|
obj->colour = c->GetCompanyRecolourOffset(LS_DEFAULT, spec->flags.Test(ObjectFlag::Uses2CC));
|
||||||
obj->colour = (spec->flags.Test(ObjectFlag::Uses2CC) ? (l.colour2 * 16) : 0) + l.colour1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user