Codechange: move calculating livery recolour offset to Livery

This commit is contained in:
Rubidium
2026-04-17 21:16:51 +02:00
committed by rubidium42
parent e24f92ce82
commit 9a87f184c4
4 changed files with 13 additions and 5 deletions
+1 -2
View File
@@ -192,8 +192,7 @@ struct Company : CompanyProperties, CompanyPool::PoolItem<&_company_pool> {
*/
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;
return this->livery[livery_scheme].GetRecolourOffset(use_secondary);
}
static void PostDestructor(size_t index);
+10
View File
@@ -87,6 +87,16 @@ struct Livery {
Flags in_use{}; ///< Livery flags.
Colours colour1 = COLOUR_BEGIN; ///< First colour, for all vehicles.
Colours colour2 = COLOUR_BEGIN; ///< Second colour, for vehicles with 2CC support.
/**
* Get offset for recolour palette.
* @param use_secondary Specify whether to add secondary colour offset to the result.
* @return The palette offset.
*/
inline uint8_t GetRecolourOffset(bool use_secondary = true) const
{
return use_secondary ? this->colour1 + this->colour2 * 16 : this->colour1;
}
};
void ResetCompanyLivery(Company *c);
+1 -1
View File
@@ -506,7 +506,7 @@ void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8_t view)
/* Get the colours of our company! */
if (spec->flags.Test(ObjectFlag::Uses2CC)) {
const Livery &l = Company::Get(_local_company)->livery[0];
palette = SPR_2CCMAP_BASE + l.colour1 + l.colour2 * 16;
palette = SPR_2CCMAP_BASE + l.GetRecolourOffset();
} else {
palette = GetCompanyPalette(_local_company);
}
+1 -2
View File
@@ -2148,8 +2148,7 @@ static PaletteID GetEngineColourMap(EngineID engine_type, CompanyID company, Eng
const Livery *livery = GetEngineLivery(engine_type, company, parent_engine_type, v, _settings_client.gui.liveries);
map += livery->colour1;
if (twocc) map += livery->colour2 * 16;
map += livery->GetRecolourOffset(twocc);
/* Update cache */
if (v != nullptr) const_cast<Vehicle *>(v)->colourmap = map;