1
0
Fork 0

(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.

release/1.1
frosch 2010-09-25 21:57:52 +00:00
parent e0b3b1ffe7
commit 611e986226
2 changed files with 91 additions and 84 deletions

View File

@ -1454,28 +1454,19 @@ bool CanBuildVehicleInfrastructure(VehicleType type)
/** /**
* Determines the livery for a vehicle. * Determines the #LiveryScheme for a vehicle.
* @param engine_type EngineID of the vehicle * @param engine_type EngineID of the vehicle
* @param company Owner of the vehicle
* @param parent_engine_type EngineID of the front vehicle. INVALID_VEHICLE if vehicle is at front itself. * @param parent_engine_type EngineID of the front vehicle. INVALID_VEHICLE if vehicle is at front itself.
* @param v the vehicle. NULL if in purchase list etc. * @param v the vehicle. NULL if in purchase list etc.
* @param livery_setting The livery settings to use for acquiring the livery information. * @return livery scheme to use
* @return livery to use
*/ */
const Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v, byte livery_setting) LiveryScheme GetEngineLiveryScheme(EngineID engine_type, EngineID parent_engine_type, const Vehicle *v)
{ {
const Company *c = Company::Get(company);
LiveryScheme scheme = LS_DEFAULT;
CargoID cargo_type = v == NULL ? (CargoID)CT_INVALID : v->cargo_type; CargoID cargo_type = v == NULL ? (CargoID)CT_INVALID : v->cargo_type;
/* 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 */
const Engine *e = Engine::Get(engine_type); const Engine *e = Engine::Get(engine_type);
switch (e->type) { switch (e->type) {
default: NOT_REACHED(); default: NOT_REACHED();
case VEH_TRAIN: { case VEH_TRAIN:
if (v != NULL && parent_engine_type != INVALID_ENGINE && (UsesWagonOverride(v) || (Train::From(v)->IsArticulatedPart() && e->u.rail.railveh_type != RAILVEH_WAGON))) { if (v != NULL && parent_engine_type != INVALID_ENGINE && (UsesWagonOverride(v) || (Train::From(v)->IsArticulatedPart() && e->u.rail.railveh_type != RAILVEH_WAGON))) {
/* Wagonoverrides use the colour scheme of the front engine. /* Wagonoverrides use the colour scheme of the front engine.
* Articulated parts use the colour scheme of the first part. (Not supported for articulated wagons) */ * Articulated parts use the colour scheme of the first part. (Not supported for articulated wagons) */
@ -1489,36 +1480,34 @@ const Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID
if (e->u.rail.railveh_type == RAILVEH_WAGON) { if (e->u.rail.railveh_type == RAILVEH_WAGON) {
if (!CargoSpec::Get(cargo_type)->is_freight) { if (!CargoSpec::Get(cargo_type)->is_freight) {
if (parent_engine_type == INVALID_ENGINE) { if (parent_engine_type == INVALID_ENGINE) {
scheme = LS_PASSENGER_WAGON_STEAM; return LS_PASSENGER_WAGON_STEAM;
} else { } else {
switch (RailVehInfo(parent_engine_type)->engclass) { switch (RailVehInfo(parent_engine_type)->engclass) {
default: NOT_REACHED(); default: NOT_REACHED();
case EC_STEAM: scheme = LS_PASSENGER_WAGON_STEAM; break; case EC_STEAM: return LS_PASSENGER_WAGON_STEAM;
case EC_DIESEL: scheme = LS_PASSENGER_WAGON_DIESEL; break; case EC_DIESEL: return LS_PASSENGER_WAGON_DIESEL;
case EC_ELECTRIC: scheme = LS_PASSENGER_WAGON_ELECTRIC; break; case EC_ELECTRIC: return LS_PASSENGER_WAGON_ELECTRIC;
case EC_MONORAIL: scheme = LS_PASSENGER_WAGON_MONORAIL; break; case EC_MONORAIL: return LS_PASSENGER_WAGON_MONORAIL;
case EC_MAGLEV: scheme = LS_PASSENGER_WAGON_MAGLEV; break; case EC_MAGLEV: return LS_PASSENGER_WAGON_MAGLEV;
} }
} }
} else { } else {
scheme = LS_FREIGHT_WAGON; return LS_FREIGHT_WAGON;
} }
} else { } else {
bool is_mu = HasBit(e->info.misc_flags, EF_RAIL_IS_MU); bool is_mu = HasBit(e->info.misc_flags, EF_RAIL_IS_MU);
switch (e->u.rail.engclass) { switch (e->u.rail.engclass) {
default: NOT_REACHED(); default: NOT_REACHED();
case EC_STEAM: scheme = LS_STEAM; break; case EC_STEAM: return LS_STEAM;
case EC_DIESEL: scheme = is_mu ? LS_DMU : LS_DIESEL; break; case EC_DIESEL: return is_mu ? LS_DMU : LS_DIESEL;
case EC_ELECTRIC: scheme = is_mu ? LS_EMU : LS_ELECTRIC; break; case EC_ELECTRIC: return is_mu ? LS_EMU : LS_ELECTRIC;
case EC_MONORAIL: scheme = LS_MONORAIL; break; case EC_MONORAIL: return LS_MONORAIL;
case EC_MAGLEV: scheme = LS_MAGLEV; break; case EC_MAGLEV: return LS_MAGLEV;
} }
} }
break;
}
case VEH_ROAD: { case VEH_ROAD:
/* Always use the livery of the front */ /* Always use the livery of the front */
if (v != NULL && parent_engine_type != INVALID_ENGINE) { if (v != NULL && parent_engine_type != INVALID_ENGINE) {
engine_type = parent_engine_type; engine_type = parent_engine_type;
@ -1531,30 +1520,46 @@ const Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID
/* Important: Use Tram Flag of front part. Luckily engine_type refers to the front part here. */ /* Important: Use Tram Flag of front part. Luckily engine_type refers to the front part here. */
if (HasBit(e->info.misc_flags, EF_ROAD_TRAM)) { if (HasBit(e->info.misc_flags, EF_ROAD_TRAM)) {
/* Tram */ /* Tram */
scheme = IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_PASSENGER_TRAM : LS_FREIGHT_TRAM; return IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_PASSENGER_TRAM : LS_FREIGHT_TRAM;
} else { } else {
/* Bus or truck */ /* Bus or truck */
scheme = IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_BUS : LS_TRUCK; return IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_BUS : LS_TRUCK;
}
break;
} }
case VEH_SHIP: { case VEH_SHIP:
if (cargo_type == CT_INVALID) cargo_type = e->GetDefaultCargoType(); if (cargo_type == CT_INVALID) cargo_type = e->GetDefaultCargoType();
if (cargo_type == CT_INVALID) cargo_type = CT_GOODS; // The vehicle does not carry anything, let's pick some freight cargo if (cargo_type == CT_INVALID) cargo_type = CT_GOODS; // The vehicle does not carry anything, let's pick some freight cargo
scheme = IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_PASSENGER_SHIP : LS_FREIGHT_SHIP; return IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_PASSENGER_SHIP : LS_FREIGHT_SHIP;
break;
}
case VEH_AIRCRAFT: { case VEH_AIRCRAFT:
switch (e->u.air.subtype) { switch (e->u.air.subtype) {
case AIR_HELI: scheme = LS_HELICOPTER; break; case AIR_HELI: return LS_HELICOPTER;
case AIR_CTOL: scheme = LS_SMALL_PLANE; break; case AIR_CTOL: return LS_SMALL_PLANE;
case AIR_CTOL | AIR_FAST: scheme = LS_LARGE_PLANE; break; case AIR_CTOL | AIR_FAST: return LS_LARGE_PLANE;
} default: NOT_REACHED();
break;
} }
} }
}
/**
* Determines the livery for a vehicle.
* @param engine_type EngineID of the vehicle
* @param company Owner of the vehicle
* @param parent_engine_type EngineID of the front vehicle. INVALID_VEHICLE if vehicle is at front itself.
* @param v the vehicle. NULL if in purchase list etc.
* @param livery_setting The livery settings to use for acquiring the livery information.
* @return livery to use
*/
const Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v, byte livery_setting)
{
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 */ /* Switch back to the default scheme if the resolved scheme is not in use */
if (!c->livery[scheme].in_use) scheme = LS_DEFAULT; if (!c->livery[scheme].in_use) scheme = LS_DEFAULT;

View File

@ -21,6 +21,7 @@
#include "newgrf_config.h" #include "newgrf_config.h"
#include "company_type.h" #include "company_type.h"
#include "track_type.h" #include "track_type.h"
#include "livery.h"
#define is_custom_sprite(x) (x >= 0xFD) #define is_custom_sprite(x) (x >= 0xFD)
#define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD) #define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD)
@ -91,6 +92,7 @@ static inline bool IsCompanyBuildableVehicleType(const BaseVehicle *v)
return IsCompanyBuildableVehicleType(v->type); return IsCompanyBuildableVehicleType(v->type);
} }
LiveryScheme GetEngineLiveryScheme(EngineID engine_type, EngineID parent_engine_type, const Vehicle *v);
const struct Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v, byte livery_setting); const struct Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v, byte livery_setting);
/** /**