summaryrefslogtreecommitdiff
path: root/src/vehicle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/vehicle.cpp')
-rw-r--r--src/vehicle.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 46141ce26..a5fe2ffa7 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -1886,14 +1886,24 @@ const Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID
const Company *c = Company::Get(company);
LiveryScheme scheme = LS_DEFAULT;
- /* The default livery is always available for use, but its in_use flag determines
- * whether any _other_ liveries are in use. */
- if (c->livery[LS_DEFAULT].in_use && (livery_setting == LIT_ALL || (livery_setting == LIT_COMPANY && company == _local_company))) {
- /* Determine the livery scheme to use */
- scheme = GetEngineLiveryScheme(engine_type, parent_engine_type, v);
-
- /* Switch back to the default scheme if the resolved scheme is not in use */
- if (!c->livery[scheme].in_use) scheme = LS_DEFAULT;
+ if (livery_setting == LIT_ALL || (livery_setting == LIT_COMPANY && company == _local_company)) {
+ if (v != NULL) {
+ const Group *g = Group::GetIfValid(v->First()->group_id);
+ if (g != NULL) {
+ /* Traverse parents until we find a livery or reach the top */
+ while (g->livery.in_use == 0 && g->parent != INVALID_GROUP) {
+ g = Group::Get(g->parent);
+ }
+ if (g->livery.in_use != 0) return &g->livery;
+ }
+ }
+
+ /* The default livery is always available for use, but its in_use flag determines
+ * whether any _other_ liveries are in use. */
+ if (c->livery[LS_DEFAULT].in_use != 0) {
+ /* Determine the livery scheme to use */
+ scheme = GetEngineLiveryScheme(engine_type, parent_engine_type, v);
+ }
}
return &c->livery[scheme];