MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetEngineLiveryScheme

Function GetEngineLiveryScheme

src/vehicle.cpp:1951–2034  ·  view source on GitHub ↗

* Determines the #LiveryScheme for a vehicle. * @param engine_type Engine of the vehicle. * @param parent_engine_type Engine of the front vehicle, #EngineID::Invalid() if vehicle is at front itself. * @param v the vehicle, \c nullptr if in purchase list etc. * @return livery scheme to use. */

Source from the content-addressed store, hash-verified

1949 * @return livery scheme to use.
1950 */
1951LiveryScheme GetEngineLiveryScheme(EngineID engine_type, EngineID parent_engine_type, const Vehicle *v)
1952{
1953 CargoType cargo_type = v == nullptr ? INVALID_CARGO : v->cargo_type;
1954 const Engine *e = Engine::Get(engine_type);
1955 switch (e->type) {
1956 default: NOT_REACHED();
1957 case VEH_TRAIN:
1958 if (v != nullptr && parent_engine_type != EngineID::Invalid() && (UsesWagonOverride(v) || (v->IsArticulatedPart() && e->VehInfo<RailVehicleInfo>().railveh_type != RAILVEH_WAGON))) {
1959 /* Wagonoverrides use the colour scheme of the front engine.
1960 * Articulated parts use the colour scheme of the first part. (Not supported for articulated wagons) */
1961 engine_type = parent_engine_type;
1962 e = Engine::Get(engine_type);
1963 /* Note: Luckily cargo_type is not needed for engines */
1964 }
1965
1966 if (!IsValidCargoType(cargo_type)) cargo_type = e->GetDefaultCargoType();
1967 if (!IsValidCargoType(cargo_type)) cargo_type = GetCargoTypeByLabel(CT_GOODS); // The vehicle does not carry anything, let's pick some freight cargo
1968 assert(IsValidCargoType(cargo_type));
1969 if (e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON) {
1970 if (!CargoSpec::Get(cargo_type)->is_freight) {
1971 if (parent_engine_type == EngineID::Invalid()) {
1972 return LS_PASSENGER_WAGON_STEAM;
1973 } else {
1974 bool is_mu = EngInfo(parent_engine_type)->misc_flags.Test(EngineMiscFlag::RailIsMU);
1975 switch (RailVehInfo(parent_engine_type)->engclass) {
1976 default: NOT_REACHED();
1977 case EC_STEAM: return LS_PASSENGER_WAGON_STEAM;
1978 case EC_DIESEL: return is_mu ? LS_DMU : LS_PASSENGER_WAGON_DIESEL;
1979 case EC_ELECTRIC: return is_mu ? LS_EMU : LS_PASSENGER_WAGON_ELECTRIC;
1980 case EC_MONORAIL: return LS_PASSENGER_WAGON_MONORAIL;
1981 case EC_MAGLEV: return LS_PASSENGER_WAGON_MAGLEV;
1982 }
1983 }
1984 } else {
1985 return LS_FREIGHT_WAGON;
1986 }
1987 } else {
1988 bool is_mu = e->info.misc_flags.Test(EngineMiscFlag::RailIsMU);
1989
1990 switch (e->VehInfo<RailVehicleInfo>().engclass) {
1991 default: NOT_REACHED();
1992 case EC_STEAM: return LS_STEAM;
1993 case EC_DIESEL: return is_mu ? LS_DMU : LS_DIESEL;
1994 case EC_ELECTRIC: return is_mu ? LS_EMU : LS_ELECTRIC;
1995 case EC_MONORAIL: return LS_MONORAIL;
1996 case EC_MAGLEV: return LS_MAGLEV;
1997 }
1998 }
1999
2000 case VEH_ROAD:
2001 /* Always use the livery of the front */
2002 if (v != nullptr && parent_engine_type != EngineID::Invalid()) {
2003 engine_type = parent_engine_type;
2004 e = Engine::Get(engine_type);
2005 cargo_type = v->First()->cargo_type;
2006 }
2007 if (!IsValidCargoType(cargo_type)) cargo_type = e->GetDefaultCargoType();
2008 if (!IsValidCargoType(cargo_type)) cargo_type = GetCargoTypeByLabel(CT_GOODS); // The vehicle does not carry anything, let's pick some freight cargo

Callers 2

FinaliseEngineArrayFunction · 0.85
GetEngineLiveryFunction · 0.85

Calls 12

NOT_REACHEDFunction · 0.85
InvalidFunction · 0.85
UsesWagonOverrideFunction · 0.85
IsValidCargoTypeFunction · 0.85
GetCargoTypeByLabelFunction · 0.85
EngInfoFunction · 0.85
RailVehInfoFunction · 0.85
IsCargoInClassFunction · 0.85
IsArticulatedPartMethod · 0.80
GetDefaultCargoTypeMethod · 0.80
TestMethod · 0.80
FirstMethod · 0.45

Tested by

no test coverage detected