| 2072 | |
| 2073 | |
| 2074 | static PaletteID GetEngineColourMap(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v) |
| 2075 | { |
| 2076 | PaletteID map = (v != nullptr) ? v->colourmap : PAL_NONE; |
| 2077 | |
| 2078 | /* Return cached value if any */ |
| 2079 | if (map != PAL_NONE) return map; |
| 2080 | |
| 2081 | const Engine *e = Engine::Get(engine_type); |
| 2082 | |
| 2083 | /* Check if we should use the colour map callback */ |
| 2084 | if (e->info.callback_mask.Test(VehicleCallbackMask::ColourRemap)) { |
| 2085 | uint16_t callback = GetVehicleCallback(CBID_VEHICLE_COLOUR_MAPPING, 0, 0, engine_type, v); |
| 2086 | /* Failure means "use the default two-colour" */ |
| 2087 | if (callback != CALLBACK_FAILED) { |
| 2088 | static_assert(PAL_NONE == 0); // Returning 0x4000 (resp. 0xC000) coincidences with default value (PAL_NONE) |
| 2089 | map = GB(callback, 0, 14); |
| 2090 | /* If bit 14 is set, then the company colours are applied to the |
| 2091 | * map else it's returned as-is. */ |
| 2092 | if (!HasBit(callback, 14)) { |
| 2093 | /* Update cache */ |
| 2094 | if (v != nullptr) const_cast<Vehicle *>(v)->colourmap = map; |
| 2095 | return map; |
| 2096 | } |
| 2097 | } |
| 2098 | } |
| 2099 | |
| 2100 | bool twocc = e->info.misc_flags.Test(EngineMiscFlag::Uses2CC); |
| 2101 | |
| 2102 | if (map == PAL_NONE) map = twocc ? (PaletteID)SPR_2CCMAP_BASE : (PaletteID)PALETTE_RECOLOUR_START; |
| 2103 | |
| 2104 | /* Spectator has news shown too, but has invalid company ID - as well as dedicated server */ |
| 2105 | if (!Company::IsValidID(company)) return map; |
| 2106 | |
| 2107 | const Livery *livery = GetEngineLivery(engine_type, company, parent_engine_type, v, _settings_client.gui.liveries); |
| 2108 | |
| 2109 | map += livery->colour1; |
| 2110 | if (twocc) map += livery->colour2 * 16; |
| 2111 | |
| 2112 | /* Update cache */ |
| 2113 | if (v != nullptr) const_cast<Vehicle *>(v)->colourmap = map; |
| 2114 | return map; |
| 2115 | } |
| 2116 | |
| 2117 | /** |
| 2118 | * Get the colour map for an engine. This used for unbuilt engines in the user interface. |
no test coverage detected