1
0
Fork 0

Codechange: Use EnumBitSet for CargoClasses. (#13491)

pull/13494/head
Peter Nelson 2025-02-08 08:46:38 +00:00 committed by GitHub
parent 04d53ed6f5
commit d61b376998
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 157 additions and 160 deletions

View File

@ -207,11 +207,11 @@ static bool CargoSpecNameSorter(const CargoSpec * const &a, const CargoSpec * co
/** Sort cargo specifications by their cargo class. */ /** Sort cargo specifications by their cargo class. */
static bool CargoSpecClassSorter(const CargoSpec * const &a, const CargoSpec * const &b) static bool CargoSpecClassSorter(const CargoSpec * const &a, const CargoSpec * const &b)
{ {
int res = (b->classes & CC_PASSENGERS) - (a->classes & CC_PASSENGERS); int res = b->classes.Test(CargoClass::Passengers) - a->classes.Test(CargoClass::Passengers);
if (res == 0) { if (res == 0) {
res = (b->classes & CC_MAIL) - (a->classes & CC_MAIL); res = b->classes.Test(CargoClass::Mail) - a->classes.Test(CargoClass::Mail);
if (res == 0) { if (res == 0) {
res = (a->classes & CC_SPECIAL) - (b->classes & CC_SPECIAL); res = a->classes.Test(CargoClass::Special) - b->classes.Test(CargoClass::Special);
if (res == 0) { if (res == 0) {
return CargoSpecNameSorter(a, b); return CargoSpecNameSorter(a, b);
} }
@ -245,7 +245,7 @@ void InitializeSortedCargoSpecs()
for (const auto &cargo : _sorted_cargo_specs) { for (const auto &cargo : _sorted_cargo_specs) {
assert(cargo->town_production_effect != INVALID_TPE); assert(cargo->town_production_effect != INVALID_TPE);
CargoSpec::town_production_cargoes[cargo->town_production_effect].push_back(cargo); CargoSpec::town_production_cargoes[cargo->town_production_effect].push_back(cargo);
if (cargo->classes & CC_SPECIAL) break; if (cargo->classes.Test(CargoClass::Special)) break;
nb_standard_cargo++; nb_standard_cargo++;
SetBit(_standard_cargo_mask, cargo->Index()); SetBit(_standard_cargo_mask, cargo->Index());
} }

View File

@ -46,28 +46,25 @@ enum TownProductionEffect : uint8_t {
}; };
/** Cargo classes. */ /** Cargo classes. */
enum CargoClass : uint16_t { enum class CargoClass : uint8_t {
CC_NOAVAILABLE = 0, ///< No cargo class has been specified Passengers = 0, ///< Passengers
CC_PASSENGERS = 1 << 0, ///< Passengers Mail = 1, ///< Mail
CC_MAIL = 1 << 1, ///< Mail Express = 2, ///< Express cargo (Goods, Food, Candy, but also possible for passengers)
CC_EXPRESS = 1 << 2, ///< Express cargo (Goods, Food, Candy, but also possible for passengers) Armoured = 3, ///< Armoured cargo (Valuables, Gold, Diamonds)
CC_ARMOURED = 1 << 3, ///< Armoured cargo (Valuables, Gold, Diamonds) Bulk = 4, ///< Bulk cargo (Coal, Grain etc., Ores, Fruit)
CC_BULK = 1 << 4, ///< Bulk cargo (Coal, Grain etc., Ores, Fruit) PieceGoods = 5, ///< Piece goods (Livestock, Wood, Steel, Paper)
CC_PIECE_GOODS = 1 << 5, ///< Piece goods (Livestock, Wood, Steel, Paper) Liquid = 6, ///< Liquids (Oil, Water, Rubber)
CC_LIQUID = 1 << 6, ///< Liquids (Oil, Water, Rubber) Refrigerated = 7, ///< Refrigerated cargo (Food, Fruit)
CC_REFRIGERATED = 1 << 7, ///< Refrigerated cargo (Food, Fruit) Hazardous = 8, ///< Hazardous cargo (Nuclear Fuel, Explosives, etc.)
CC_HAZARDOUS = 1 << 8, ///< Hazardous cargo (Nuclear Fuel, Explosives, etc.) Covered = 9, ///< Covered/Sheltered Freight (Transportation in Box Vans, Silo Wagons, etc.)
CC_COVERED = 1 << 9, ///< Covered/Sheltered Freight (Transportation in Box Vans, Silo Wagons, etc.) Oversized = 10, ///< Oversized (stake/flatbed wagon)
CC_OVERSIZED = 1 << 10, ///< Oversized (stake/flatbed wagon) Powderized = 11, ///< Powderized, moist protected (powder/silo wagon)
CC_POWDERIZED = 1 << 11, ///< Powderized, moist protected (powder/silo wagon) NotPourable = 12, ///< Not Pourable (open wagon, but not hopper wagon)
CC_NOT_POURABLE = 1 << 12, ///< Not Pourable (open wagon, but not hopper wagon) Potable = 13, ///< Potable / food / clean.
CC_POTABLE = 1 << 13, ///< Potable / food / clean. NonPotable = 14, ///< Non-potable / non-food / dirty.
CC_NON_POTABLE = 1 << 14, ///< Non-potable / non-food / dirty. Special = 15, ///< Special bit used for livery refit tricks instead of normal cargoes.
CC_SPECIAL = 1 << 15, ///< Special bit used for livery refit tricks instead of normal cargoes.
}; };
using CargoClasses = EnumBitSet<CargoClass, uint16_t>;
/** Bitmask of cargo classes. */
using CargoClasses = uint16_t;
static const uint8_t INVALID_CARGO_BITNUM = 0xFF; ///< Constant representing invalid cargo static const uint8_t INVALID_CARGO_BITNUM = 0xFF; ///< Constant representing invalid cargo
@ -236,9 +233,9 @@ extern std::span<const CargoSpec *> _sorted_standard_cargo_specs;
* @param cc Cargo class. * @param cc Cargo class.
* @return The type fits in the class. * @return The type fits in the class.
*/ */
inline bool IsCargoInClass(CargoType c, CargoClass cc) inline bool IsCargoInClass(CargoType c, CargoClasses cc)
{ {
return (CargoSpec::Get(c)->classes & cc) != 0; return CargoSpec::Get(c)->classes.Any(cc);
} }
using SetCargoBitIterator = SetBitIterator<CargoType, CargoTypes>; using SetCargoBitIterator = SetBitIterator<CargoType, CargoTypes>;

View File

@ -2713,22 +2713,22 @@ static void ConDumpCargoTypes()
spec->bitnum, spec->bitnum,
FormatLabel(spec->label.base()), FormatLabel(spec->label.base()),
spec->callback_mask.base(), spec->callback_mask.base(),
(spec->classes & CC_PASSENGERS) != 0 ? 'p' : '-', spec->classes.Test(CargoClass::Passengers) ? 'p' : '-',
(spec->classes & CC_MAIL) != 0 ? 'm' : '-', spec->classes.Test(CargoClass::Mail) ? 'm' : '-',
(spec->classes & CC_EXPRESS) != 0 ? 'x' : '-', spec->classes.Test(CargoClass::Express) ? 'x' : '-',
(spec->classes & CC_ARMOURED) != 0 ? 'a' : '-', spec->classes.Test(CargoClass::Armoured) ? 'a' : '-',
(spec->classes & CC_BULK) != 0 ? 'b' : '-', spec->classes.Test(CargoClass::Bulk) ? 'b' : '-',
(spec->classes & CC_PIECE_GOODS) != 0 ? 'g' : '-', spec->classes.Test(CargoClass::PieceGoods) ? 'g' : '-',
(spec->classes & CC_LIQUID) != 0 ? 'l' : '-', spec->classes.Test(CargoClass::Liquid) ? 'l' : '-',
(spec->classes & CC_REFRIGERATED) != 0 ? 'r' : '-', spec->classes.Test(CargoClass::Refrigerated) ? 'r' : '-',
(spec->classes & CC_HAZARDOUS) != 0 ? 'h' : '-', spec->classes.Test(CargoClass::Hazardous) ? 'h' : '-',
(spec->classes & CC_COVERED) != 0 ? 'c' : '-', spec->classes.Test(CargoClass::Covered) ? 'c' : '-',
(spec->classes & CC_OVERSIZED) != 0 ? 'o' : '-', spec->classes.Test(CargoClass::Oversized) ? 'o' : '-',
(spec->classes & CC_POWDERIZED) != 0 ? 'd' : '-', spec->classes.Test(CargoClass::Powderized) ? 'd' : '-',
(spec->classes & CC_NOT_POURABLE) != 0 ? 'n' : '-', spec->classes.Test(CargoClass::NotPourable) ? 'n' : '-',
(spec->classes & CC_POTABLE) != 0 ? 'e' : '-', spec->classes.Test(CargoClass::Potable) ? 'e' : '-',
(spec->classes & CC_NON_POTABLE) != 0 ? 'i' : '-', spec->classes.Test(CargoClass::NonPotable) ? 'i' : '-',
(spec->classes & CC_SPECIAL) != 0 ? 'S' : '-', spec->classes.Test(CargoClass::Special) ? 'S' : '-',
std::byteswap(grfid), std::byteswap(grfid),
GetStringPtr(spec->name) GetStringPtr(spec->name)
); );

View File

@ -1887,7 +1887,7 @@ static void LoadUnloadVehicle(Vehicle *front)
if (front->current_order.GetLoadType() == OLF_FULL_LOAD_ANY) { if (front->current_order.GetLoadType() == OLF_FULL_LOAD_ANY) {
/* if the aircraft carries passengers and is NOT full, then /* if the aircraft carries passengers and is NOT full, then
* continue loading, no matter how much mail is in */ * continue loading, no matter how much mail is in */
if ((front->type == VEH_AIRCRAFT && IsCargoInClass(front->cargo_type, CC_PASSENGERS) && front->cargo_cap > front->cargo.StoredCount()) || if ((front->type == VEH_AIRCRAFT && IsCargoInClass(front->cargo_type, CargoClass::Passengers) && front->cargo_cap > front->cargo.StoredCount()) ||
(cargo_not_full != 0 && (cargo_full & ~cargo_not_full) == 0)) { // There are still non-full cargoes (cargo_not_full != 0 && (cargo_full & ~cargo_not_full) == 0)) { // There are still non-full cargoes
finished_loading = false; finished_loading = false;
} }

View File

@ -209,7 +209,7 @@ uint Engine::DetermineCapacity(const Vehicle *v, uint16_t *mail_capacity) const
CargoType default_cargo = this->GetDefaultCargoType(); CargoType default_cargo = this->GetDefaultCargoType();
CargoType cargo_type = (v != nullptr) ? v->cargo_type : default_cargo; CargoType cargo_type = (v != nullptr) ? v->cargo_type : default_cargo;
if (mail_capacity != nullptr && this->type == VEH_AIRCRAFT && IsCargoInClass(cargo_type, CC_PASSENGERS)) { if (mail_capacity != nullptr && this->type == VEH_AIRCRAFT && IsCargoInClass(cargo_type, CargoClass::Passengers)) {
*mail_capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity, v); *mail_capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity, v);
} }
@ -241,7 +241,7 @@ uint Engine::DetermineCapacity(const Vehicle *v, uint16_t *mail_capacity) const
case VEH_AIRCRAFT: case VEH_AIRCRAFT:
capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_PASSENGER_CAPACITY, this->u.air.passenger_capacity, v); capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_PASSENGER_CAPACITY, this->u.air.passenger_capacity, v);
if (!IsCargoInClass(cargo_type, CC_PASSENGERS)) { if (!IsCargoInClass(cargo_type, CargoClass::Passengers)) {
extra_mail_cap = GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity, v); extra_mail_cap = GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity, v);
} }
if (IsValidCargoType(GetCargoTypeByLabel(CT_MAIL))) { if (IsValidCargoType(GetCargoTypeByLabel(CT_MAIL))) {

View File

@ -285,9 +285,9 @@ void MultiCommodityFlow::Dijkstra(NodeID source_node, PathVector &paths)
/* Prioritize the fastest route for passengers, mail and express cargo, /* Prioritize the fastest route for passengers, mail and express cargo,
* and the shortest route for other classes of cargo. * and the shortest route for other classes of cargo.
* In-between stops are punished with a 1 tile or 1 day penalty. */ * In-between stops are punished with a 1 tile or 1 day penalty. */
bool express = IsCargoInClass(this->job.Cargo(), CC_PASSENGERS) || bool express = IsCargoInClass(this->job.Cargo(), CargoClass::Passengers) ||
IsCargoInClass(this->job.Cargo(), CC_MAIL) || IsCargoInClass(this->job.Cargo(), CargoClass::Mail) ||
IsCargoInClass(this->job.Cargo(), CC_EXPRESS); IsCargoInClass(this->job.Cargo(), CargoClass::Express);
uint distance = DistanceMaxPlusManhattan(this->job[from].base.xy, this->job[to].base.xy) + 1; uint distance = DistanceMaxPlusManhattan(this->job[from].base.xy, this->job[to].base.xy) + 1;
/* Compute a default travel time from the distance and an average speed of 1 tile/day. */ /* Compute a default travel time from the distance and an average speed of 1 tile/day. */
uint time = (edge.base.TravelTime() != 0) ? edge.base.TravelTime() + Ticks::DAY_TICKS : distance * Ticks::DAY_TICKS; uint time = (edge.base.TravelTime() != 0) ? edge.base.TravelTime() + Ticks::DAY_TICKS : distance * Ticks::DAY_TICKS;

View File

@ -1299,13 +1299,13 @@ static ChangeInfoResult RailVehicleChangeInfo(uint first, uint last, int prop, B
break; break;
case 0x28: // Cargo classes allowed case 0x28: // Cargo classes allowed
_gted[e->index].cargo_allowed = buf.ReadWord(); _gted[e->index].cargo_allowed = CargoClasses{buf.ReadWord()};
_gted[e->index].UpdateRefittability(_gted[e->index].cargo_allowed != 0); _gted[e->index].UpdateRefittability(_gted[e->index].cargo_allowed != CargoClasses{});
_gted[e->index].defaultcargo_grf = _cur.grffile; _gted[e->index].defaultcargo_grf = _cur.grffile;
break; break;
case 0x29: // Cargo classes disallowed case 0x29: // Cargo classes disallowed
_gted[e->index].cargo_disallowed = buf.ReadWord(); _gted[e->index].cargo_disallowed = CargoClasses{buf.ReadWord()};
_gted[e->index].UpdateRefittability(false); _gted[e->index].UpdateRefittability(false);
break; break;
@ -1351,7 +1351,7 @@ static ChangeInfoResult RailVehicleChangeInfo(uint first, uint last, int prop, B
} }
case 0x32: // Cargo classes required for a refit. case 0x32: // Cargo classes required for a refit.
_gted[e->index].cargo_allowed_required = buf.ReadWord(); _gted[e->index].cargo_allowed_required = CargoClasses{buf.ReadWord()};
break; break;
default: default:
@ -1496,13 +1496,13 @@ static ChangeInfoResult RoadVehicleChangeInfo(uint first, uint last, int prop, B
break; break;
case 0x1D: // Cargo classes allowed case 0x1D: // Cargo classes allowed
_gted[e->index].cargo_allowed = buf.ReadWord(); _gted[e->index].cargo_allowed = CargoClasses{buf.ReadWord()};
_gted[e->index].UpdateRefittability(_gted[e->index].cargo_allowed != 0); _gted[e->index].UpdateRefittability(_gted[e->index].cargo_allowed != CargoClasses{});
_gted[e->index].defaultcargo_grf = _cur.grffile; _gted[e->index].defaultcargo_grf = _cur.grffile;
break; break;
case 0x1E: // Cargo classes disallowed case 0x1E: // Cargo classes disallowed
_gted[e->index].cargo_disallowed = buf.ReadWord(); _gted[e->index].cargo_disallowed = CargoClasses{buf.ReadWord()};
_gted[e->index].UpdateRefittability(false); _gted[e->index].UpdateRefittability(false);
break; break;
@ -1562,7 +1562,7 @@ static ChangeInfoResult RoadVehicleChangeInfo(uint first, uint last, int prop, B
} }
case 0x29: // Cargo classes required for a refit. case 0x29: // Cargo classes required for a refit.
_gted[e->index].cargo_allowed_required = buf.ReadWord(); _gted[e->index].cargo_allowed_required = CargoClasses{buf.ReadWord()};
break; break;
default: default:
@ -1689,13 +1689,13 @@ static ChangeInfoResult ShipVehicleChangeInfo(uint first, uint last, int prop, B
break; break;
case 0x18: // Cargo classes allowed case 0x18: // Cargo classes allowed
_gted[e->index].cargo_allowed = buf.ReadWord(); _gted[e->index].cargo_allowed = CargoClasses{buf.ReadWord()};
_gted[e->index].UpdateRefittability(_gted[e->index].cargo_allowed != 0); _gted[e->index].UpdateRefittability(_gted[e->index].cargo_allowed != CargoClasses{});
_gted[e->index].defaultcargo_grf = _cur.grffile; _gted[e->index].defaultcargo_grf = _cur.grffile;
break; break;
case 0x19: // Cargo classes disallowed case 0x19: // Cargo classes disallowed
_gted[e->index].cargo_disallowed = buf.ReadWord(); _gted[e->index].cargo_disallowed = CargoClasses{buf.ReadWord()};
_gted[e->index].UpdateRefittability(false); _gted[e->index].UpdateRefittability(false);
break; break;
@ -1759,7 +1759,7 @@ static ChangeInfoResult ShipVehicleChangeInfo(uint first, uint last, int prop, B
break; break;
case 0x25: // Cargo classes required for a refit. case 0x25: // Cargo classes required for a refit.
_gted[e->index].cargo_allowed_required = buf.ReadWord(); _gted[e->index].cargo_allowed_required = CargoClasses{buf.ReadWord()};
break; break;
default: default:
@ -1878,13 +1878,13 @@ static ChangeInfoResult AircraftVehicleChangeInfo(uint first, uint last, int pro
break; break;
case 0x18: // Cargo classes allowed case 0x18: // Cargo classes allowed
_gted[e->index].cargo_allowed = buf.ReadWord(); _gted[e->index].cargo_allowed = CargoClasses{buf.ReadWord()};
_gted[e->index].UpdateRefittability(_gted[e->index].cargo_allowed != 0); _gted[e->index].UpdateRefittability(_gted[e->index].cargo_allowed != CargoClasses{});
_gted[e->index].defaultcargo_grf = _cur.grffile; _gted[e->index].defaultcargo_grf = _cur.grffile;
break; break;
case 0x19: // Cargo classes disallowed case 0x19: // Cargo classes disallowed
_gted[e->index].cargo_disallowed = buf.ReadWord(); _gted[e->index].cargo_disallowed = CargoClasses{buf.ReadWord()};
_gted[e->index].UpdateRefittability(false); _gted[e->index].UpdateRefittability(false);
break; break;
@ -1934,7 +1934,7 @@ static ChangeInfoResult AircraftVehicleChangeInfo(uint first, uint last, int pro
} }
case 0x23: // Cargo classes required for a refit. case 0x23: // Cargo classes required for a refit.
_gted[e->index].cargo_allowed_required = buf.ReadWord(); _gted[e->index].cargo_allowed_required = CargoClasses{buf.ReadWord()};
break; break;
default: default:
@ -3167,7 +3167,7 @@ static ChangeInfoResult CargoChangeInfo(uint first, uint last, int prop, ByteRea
break; break;
case 0x16: // Cargo classes case 0x16: // Cargo classes
cs->classes = buf.ReadWord(); cs->classes = CargoClasses{buf.ReadWord()};
break; break;
case 0x17: // Cargo label case 0x17: // Cargo label
@ -9057,47 +9057,47 @@ static void CalculateRefitMasks()
CargoClasses cargo_allowed; CargoClasses cargo_allowed;
CargoClasses cargo_disallowed; CargoClasses cargo_disallowed;
} _default_refit_masks[] = { } _default_refit_masks[] = {
{{T, A, S, Y}, CT_PASSENGERS, CC_PASSENGERS, 0}, {{T, A, S, Y}, CT_PASSENGERS, {CargoClass::Passengers}, {}},
{{T, A, S }, CT_MAIL, CC_MAIL, 0}, {{T, A, S }, CT_MAIL, {CargoClass::Mail}, {}},
{{T, A, S }, CT_VALUABLES, CC_ARMOURED, CC_LIQUID}, {{T, A, S }, CT_VALUABLES, {CargoClass::Armoured}, {CargoClass::Liquid}},
{{ Y}, CT_MAIL, CC_MAIL | CC_ARMOURED, CC_LIQUID}, {{ Y}, CT_MAIL, {CargoClass::Mail, CargoClass::Armoured}, {CargoClass::Liquid}},
{{T, A }, CT_COAL, CC_BULK, 0}, {{T, A }, CT_COAL, {CargoClass::Bulk}, {}},
{{ S }, CT_COPPER_ORE, CC_BULK, 0}, {{ S }, CT_COPPER_ORE, {CargoClass::Bulk}, {}},
{{ Y}, CT_SUGAR, CC_BULK, 0}, {{ Y}, CT_SUGAR, {CargoClass::Bulk}, {}},
{{T, A, S }, CT_OIL, CC_LIQUID, 0}, {{T, A, S }, CT_OIL, {CargoClass::Liquid}, {}},
{{ Y}, CT_COLA, CC_LIQUID, 0}, {{ Y}, CT_COLA, {CargoClass::Liquid}, {}},
{{T }, CT_GOODS, CC_PIECE_GOODS | CC_EXPRESS, CC_LIQUID | CC_PASSENGERS}, {{T }, CT_GOODS, {CargoClass::PieceGoods, CargoClass::Express}, {CargoClass::Liquid, CargoClass::Passengers}},
{{ A, S }, CT_GOODS, CC_PIECE_GOODS | CC_EXPRESS, CC_LIQUID | CC_PASSENGERS | CC_REFRIGERATED}, {{ A, S }, CT_GOODS, {CargoClass::PieceGoods, CargoClass::Express}, {CargoClass::Liquid, CargoClass::Passengers, CargoClass::Refrigerated}},
{{ A, S }, CT_FOOD, CC_REFRIGERATED, 0}, {{ A, S }, CT_FOOD, {CargoClass::Refrigerated}, {}},
{{ Y}, CT_CANDY, CC_PIECE_GOODS | CC_EXPRESS, CC_LIQUID | CC_PASSENGERS}, {{ Y}, CT_CANDY, {CargoClass::PieceGoods, CargoClass::Express}, {CargoClass::Liquid, CargoClass::Passengers}},
}; };
if (e->type == VEH_AIRCRAFT) { if (e->type == VEH_AIRCRAFT) {
/* Aircraft default to "light" cargoes */ /* Aircraft default to "light" cargoes */
_gted[engine].cargo_allowed = CC_PASSENGERS | CC_MAIL | CC_ARMOURED | CC_EXPRESS; _gted[engine].cargo_allowed = {CargoClass::Passengers, CargoClass::Mail, CargoClass::Armoured, CargoClass::Express};
_gted[engine].cargo_disallowed = CC_LIQUID; _gted[engine].cargo_disallowed = {CargoClass::Liquid};
} else if (e->type == VEH_SHIP) { } else if (e->type == VEH_SHIP) {
CargoLabel label = GetActiveCargoLabel(ei->cargo_label); CargoLabel label = GetActiveCargoLabel(ei->cargo_label);
switch (label.base()) { switch (label.base()) {
case CT_PASSENGERS.base(): case CT_PASSENGERS.base():
/* Ferries */ /* Ferries */
_gted[engine].cargo_allowed = CC_PASSENGERS; _gted[engine].cargo_allowed = {CargoClass::Passengers};
_gted[engine].cargo_disallowed = 0; _gted[engine].cargo_disallowed = {};
break; break;
case CT_OIL.base(): case CT_OIL.base():
/* Tankers */ /* Tankers */
_gted[engine].cargo_allowed = CC_LIQUID; _gted[engine].cargo_allowed = {CargoClass::Liquid};
_gted[engine].cargo_disallowed = 0; _gted[engine].cargo_disallowed = {};
break; break;
default: default:
/* Cargo ships */ /* Cargo ships */
if (_settings_game.game_creation.landscape == LandscapeType::Toyland) { if (_settings_game.game_creation.landscape == LandscapeType::Toyland) {
/* No tanker in toyland :( */ /* No tanker in toyland :( */
_gted[engine].cargo_allowed = CC_MAIL | CC_ARMOURED | CC_EXPRESS | CC_BULK | CC_PIECE_GOODS | CC_LIQUID; _gted[engine].cargo_allowed = {CargoClass::Mail, CargoClass::Armoured, CargoClass::Express, CargoClass::Bulk, CargoClass::PieceGoods, CargoClass::Liquid};
_gted[engine].cargo_disallowed = CC_PASSENGERS; _gted[engine].cargo_disallowed = {CargoClass::Passengers};
} else { } else {
_gted[engine].cargo_allowed = CC_MAIL | CC_ARMOURED | CC_EXPRESS | CC_BULK | CC_PIECE_GOODS; _gted[engine].cargo_allowed = {CargoClass::Mail, CargoClass::Armoured, CargoClass::Express, CargoClass::Bulk, CargoClass::PieceGoods};
_gted[engine].cargo_disallowed = CC_LIQUID | CC_PASSENGERS; _gted[engine].cargo_disallowed = {CargoClass::Liquid, CargoClass::Passengers};
} }
break; break;
} }
@ -9105,8 +9105,8 @@ static void CalculateRefitMasks()
} else if (e->type == VEH_TRAIN && e->u.rail.railveh_type != RAILVEH_WAGON) { } else if (e->type == VEH_TRAIN && e->u.rail.railveh_type != RAILVEH_WAGON) {
/* Train engines default to all cargoes, so you can build single-cargo consists with fast engines. /* Train engines default to all cargoes, so you can build single-cargo consists with fast engines.
* Trains loading multiple cargoes may start stations accepting unwanted cargoes. */ * Trains loading multiple cargoes may start stations accepting unwanted cargoes. */
_gted[engine].cargo_allowed = CC_PASSENGERS | CC_MAIL | CC_ARMOURED | CC_EXPRESS | CC_BULK | CC_PIECE_GOODS | CC_LIQUID; _gted[engine].cargo_allowed = {CargoClass::Passengers, CargoClass::Mail, CargoClass::Armoured, CargoClass::Express, CargoClass::Bulk, CargoClass::PieceGoods, CargoClass::Liquid};
_gted[engine].cargo_disallowed = 0; _gted[engine].cargo_disallowed = {};
} else { } else {
/* Train wagons and road vehicles are classified by their default cargo type */ /* Train wagons and road vehicles are classified by their default cargo type */
CargoLabel label = GetActiveCargoLabel(ei->cargo_label); CargoLabel label = GetActiveCargoLabel(ei->cargo_label);
@ -9123,7 +9123,7 @@ static void CalculateRefitMasks()
_gted[engine].ctt_exclude_mask = original_known_cargoes; _gted[engine].ctt_exclude_mask = original_known_cargoes;
} }
} }
_gted[engine].UpdateRefittability(_gted[engine].cargo_allowed != 0); _gted[engine].UpdateRefittability(_gted[engine].cargo_allowed != CargoClasses{});
if (IsValidCargoType(ei->cargo_type)) ClrBit(_gted[engine].ctt_exclude_mask, ei->cargo_type); if (IsValidCargoType(ei->cargo_type)) ClrBit(_gted[engine].ctt_exclude_mask, ei->cargo_type);
} }
@ -9138,11 +9138,11 @@ static void CalculateRefitMasks()
* Note: After applying the translations, the vehicle may end up carrying no defined cargo. It becomes unavailable in that case. */ * Note: After applying the translations, the vehicle may end up carrying no defined cargo. It becomes unavailable in that case. */
only_defaultcargo = _gted[engine].refittability != GRFTempEngineData::NONEMPTY; only_defaultcargo = _gted[engine].refittability != GRFTempEngineData::NONEMPTY;
if (_gted[engine].cargo_allowed != 0) { if (_gted[engine].cargo_allowed != CargoClasses{}) {
/* Build up the list of cargo types from the set cargo classes. */ /* Build up the list of cargo types from the set cargo classes. */
for (const CargoSpec *cs : CargoSpec::Iterate()) { for (const CargoSpec *cs : CargoSpec::Iterate()) {
if ((_gted[engine].cargo_allowed & cs->classes) != 0 && (_gted[engine].cargo_allowed_required & cs->classes) == _gted[engine].cargo_allowed_required) SetBit(mask, cs->Index()); if (cs->classes.Any(_gted[engine].cargo_allowed) && cs->classes.All(_gted[engine].cargo_allowed_required)) SetBit(mask, cs->Index());
if (_gted[engine].cargo_disallowed & cs->classes) SetBit(not_mask, cs->Index()); if (cs->classes.Any(_gted[engine].cargo_disallowed)) SetBit(not_mask, cs->Index());
} }
} }
@ -9158,7 +9158,7 @@ static void CalculateRefitMasks()
if (file != nullptr && e->info.callback_mask.Test(VehicleCallbackMask::CustomRefit)) { if (file != nullptr && e->info.callback_mask.Test(VehicleCallbackMask::CustomRefit)) {
for (const CargoSpec *cs : CargoSpec::Iterate()) { for (const CargoSpec *cs : CargoSpec::Iterate()) {
uint8_t local_slot = file->cargo_map[cs->Index()]; uint8_t local_slot = file->cargo_map[cs->Index()];
uint16_t callback = GetVehicleCallback(CBID_VEHICLE_CUSTOM_REFIT, cs->classes, local_slot, engine, nullptr); uint16_t callback = GetVehicleCallback(CBID_VEHICLE_CUSTOM_REFIT, cs->classes.base(), local_slot, engine, nullptr);
switch (callback) { switch (callback) {
case CALLBACK_FAILED: case CALLBACK_FAILED:
case 0: case 0:

View File

@ -446,7 +446,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
/* Skip empty engines */ /* Skip empty engines */
if (!u->GetEngine()->CanCarryCargo()) continue; if (!u->GetEngine()->CanCarryCargo()) continue;
cargo_classes |= CargoSpec::Get(u->cargo_type)->classes; cargo_classes |= CargoSpec::Get(u->cargo_type)->classes.base();
common_cargoes[u->cargo_type]++; common_cargoes[u->cargo_type]++;
} }
@ -554,7 +554,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
* is object->ro.grffile. * is object->ro.grffile.
* In case of CBID_TRAIN_ALLOW_WAGON_ATTACH this is not the same as v->GetGRF(). * In case of CBID_TRAIN_ALLOW_WAGON_ATTACH this is not the same as v->GetGRF().
*/ */
return (cs->classes << 16) | (cs->weight << 8) | object->ro.grffile->cargo_map[v->cargo_type]; return (cs->classes.base() << 16) | (cs->weight << 8) | object->ro.grffile->cargo_map[v->cargo_type];
} }
case 0x48: return v->GetEngine()->flags.base(); // Vehicle Type Info case 0x48: return v->GetEngine()->flags.base(); // Vehicle Type Info
@ -952,7 +952,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
CargoType cargo_type = e->GetDefaultCargoType(); CargoType cargo_type = e->GetDefaultCargoType();
if (IsValidCargoType(cargo_type)) { if (IsValidCargoType(cargo_type)) {
const CargoSpec *cs = CargoSpec::Get(cargo_type); const CargoSpec *cs = CargoSpec::Get(cargo_type);
return (cs->classes << 16) | (cs->weight << 8) | this->ro.grffile->cargo_map[cargo_type]; return (cs->classes.base() << 16) | (cs->weight << 8) | this->ro.grffile->cargo_map[cargo_type];
} else { } else {
return 0x000000FF; return 0x000000FF;
} }

View File

@ -82,7 +82,7 @@ static const Trackdir _road_reverse_table[DIAGDIR_END] = {
bool RoadVehicle::IsBus() const bool RoadVehicle::IsBus() const
{ {
assert(this->IsFrontEngine()); assert(this->IsFrontEngine());
return IsCargoInClass(this->cargo_type, CC_PASSENGERS); return IsCargoInClass(this->cargo_type, CargoClass::Passengers);
} }
/** /**

View File

@ -60,7 +60,7 @@
/* static */ bool ScriptCargo::HasCargoClass(CargoType cargo_type, CargoClass cargo_class) /* static */ bool ScriptCargo::HasCargoClass(CargoType cargo_type, CargoClass cargo_class)
{ {
if (!IsValidCargo(cargo_type)) return false; if (!IsValidCargo(cargo_type)) return false;
return ::IsCargoInClass(cargo_type, (::CargoClass)cargo_class); return ::IsCargoInClass(cargo_type, ::CargoClasses(to_underlying(cargo_class)));
} }
/* static */ ScriptCargo::TownEffect ScriptCargo::GetTownEffect(CargoType cargo_type) /* static */ ScriptCargo::TownEffect ScriptCargo::GetTownEffect(CargoType cargo_type)

View File

@ -25,16 +25,16 @@ public:
*/ */
enum CargoClass { enum CargoClass {
/* Note: these values represent part of the in-game CargoClass enum */ /* Note: these values represent part of the in-game CargoClass enum */
CC_PASSENGERS = ::CC_PASSENGERS, ///< Passengers. Cargoes of this class appear at bus stops. Cargoes not of this class appear at truck stops. CC_PASSENGERS = ::CargoClasses{::CargoClass::Passengers}.base(), ///< Passengers. Cargoes of this class appear at bus stops. Cargoes not of this class appear at truck stops.
CC_MAIL = ::CC_MAIL, ///< Mail CC_MAIL = ::CargoClasses{::CargoClass::Mail}.base(), ///< Mail
CC_EXPRESS = ::CC_EXPRESS, ///< Express cargo (Goods, Food, Candy, but also possible for passengers) CC_EXPRESS = ::CargoClasses{::CargoClass::Express}.base(), ///< Express cargo (Goods, Food, Candy, but also possible for passengers)
CC_ARMOURED = ::CC_ARMOURED, ///< Armoured cargo (Valuables, Gold, Diamonds) CC_ARMOURED = ::CargoClasses{::CargoClass::Armoured}.base(), ///< Armoured cargo (Valuables, Gold, Diamonds)
CC_BULK = ::CC_BULK, ///< Bulk cargo (Coal, Grain etc., Ores, Fruit) CC_BULK = ::CargoClasses{::CargoClass::Bulk}.base(), ///< Bulk cargo (Coal, Grain etc., Ores, Fruit)
CC_PIECE_GOODS = ::CC_PIECE_GOODS, ///< Piece goods (Livestock, Wood, Steel, Paper) CC_PIECE_GOODS = ::CargoClasses{::CargoClass::PieceGoods}.base(), ///< Piece goods (Livestock, Wood, Steel, Paper)
CC_LIQUID = ::CC_LIQUID, ///< Liquids (Oil, Water, Rubber) CC_LIQUID = ::CargoClasses{::CargoClass::Liquid}.base(), ///< Liquids (Oil, Water, Rubber)
CC_REFRIGERATED = ::CC_REFRIGERATED, ///< Refrigerated cargo (Food, Fruit) CC_REFRIGERATED = ::CargoClasses{::CargoClass::Refrigerated}.base(), ///< Refrigerated cargo (Food, Fruit)
CC_HAZARDOUS = ::CC_HAZARDOUS, ///< Hazardous cargo (Nuclear Fuel, Explosives, etc.) CC_HAZARDOUS = ::CargoClasses{::CargoClass::Hazardous}.base(), ///< Hazardous cargo (Nuclear Fuel, Explosives, etc.)
CC_COVERED = ::CC_COVERED, ///< Covered/Sheltered Freight (Transportation in Box Vans, Silo Wagons, etc.) CC_COVERED = ::CargoClasses{::CargoClass::Covered}.base(), ///< Covered/Sheltered Freight (Transportation in Box Vans, Silo Wagons, etc.)
}; };
/** /**

View File

@ -553,9 +553,9 @@ struct LinkGraphSettings {
inline DistributionType GetDistributionType(CargoType cargo) const inline DistributionType GetDistributionType(CargoType cargo) const
{ {
if (IsCargoInClass(cargo, CC_PASSENGERS)) return this->distribution_pax; if (IsCargoInClass(cargo, CargoClass::Passengers)) return this->distribution_pax;
if (IsCargoInClass(cargo, CC_MAIL)) return this->distribution_mail; if (IsCargoInClass(cargo, CargoClass::Mail)) return this->distribution_mail;
if (IsCargoInClass(cargo, CC_ARMOURED)) return this->distribution_armoured; if (IsCargoInClass(cargo, CargoClass::Armoured)) return this->distribution_armoured;
return this->distribution_default; return this->distribution_default;
} }
}; };

View File

@ -182,7 +182,7 @@ static bool CMSAMine(TileIndex tile)
/* The industry extracts something non-liquid, i.e. no oil or plastic, so it is a mine. /* The industry extracts something non-liquid, i.e. no oil or plastic, so it is a mine.
* Also the production of passengers and mail is ignored. */ * Also the production of passengers and mail is ignored. */
if (IsValidCargoType(p.cargo) && if (IsValidCargoType(p.cargo) &&
(CargoSpec::Get(p.cargo)->classes & (CC_LIQUID | CC_PASSENGERS | CC_MAIL)) == 0) { !CargoSpec::Get(p.cargo)->classes.Any({CargoClass::Liquid, CargoClass::Passengers, CargoClass::Mail})) {
return true; return true;
} }
} }
@ -636,7 +636,7 @@ void UpdateStationAcceptance(Station *st, bool show_msg)
uint amt = acceptance[i]; uint amt = acceptance[i];
/* Make sure the station can accept the goods type. */ /* Make sure the station can accept the goods type. */
bool is_passengers = IsCargoInClass(i, CC_PASSENGERS); bool is_passengers = IsCargoInClass(i, CargoClass::Passengers);
if ((!is_passengers && !(st->facilities & ~FACIL_BUS_STOP)) || if ((!is_passengers && !(st->facilities & ~FACIL_BUS_STOP)) ||
(is_passengers && !(st->facilities & ~FACIL_TRUCK_STOP))) { (is_passengers && !(st->facilities & ~FACIL_TRUCK_STOP))) {
amt = 0; amt = 0;
@ -4381,7 +4381,7 @@ static bool CanMoveGoodsToStation(const Station *st, CargoType type)
/* Selectively servicing stations, and not this one. */ /* Selectively servicing stations, and not this one. */
if (_settings_game.order.selectgoods && !st->goods[type].HasVehicleEverTriedLoading()) return false; if (_settings_game.order.selectgoods && !st->goods[type].HasVehicleEverTriedLoading()) return false;
if (IsCargoInClass(type, CC_PASSENGERS)) { if (IsCargoInClass(type, CargoClass::Passengers)) {
/* Passengers are never served by just a truck stop. */ /* Passengers are never served by just a truck stop. */
if (st->facilities == FACIL_TRUCK_STOP) return false; if (st->facilities == FACIL_TRUCK_STOP) return false;
} else { } else {

View File

@ -87,8 +87,8 @@ int DrawStationCoverageAreaText(const Rect &r, StationCoverageType sct, int rad,
/* Convert cargo counts to a set of cargo bits, and draw the result. */ /* Convert cargo counts to a set of cargo bits, and draw the result. */
for (CargoType i = 0; i < NUM_CARGO; i++) { for (CargoType i = 0; i < NUM_CARGO; i++) {
switch (sct) { switch (sct) {
case SCT_PASSENGERS_ONLY: if (!IsCargoInClass(i, CC_PASSENGERS)) continue; break; case SCT_PASSENGERS_ONLY: if (!IsCargoInClass(i, CargoClass::Passengers)) continue; break;
case SCT_NON_PASSENGERS_ONLY: if (IsCargoInClass(i, CC_PASSENGERS)) continue; break; case SCT_NON_PASSENGERS_ONLY: if (IsCargoInClass(i, CargoClass::Passengers)) continue; break;
case SCT_ALL: break; case SCT_ALL: break;
default: NOT_REACHED(); default: NOT_REACHED();
} }

View File

@ -50,48 +50,48 @@
/** Cargo types available by default. */ /** Cargo types available by default. */
static const CargoSpec _default_cargo[] = { static const CargoSpec _default_cargo[] = {
MK( 0, CT_PASSENGERS, 152, 1, 0x400, 3185, 0, 24, false, TAE_PASSENGERS, PASSENGERS, PASSENGER, STR_PASSENGERS, CC_PASSENGERS), MK( 0, CT_PASSENGERS, 152, 1, 0x400, 3185, 0, 24, false, TAE_PASSENGERS, PASSENGERS, PASSENGER, STR_PASSENGERS, CargoClasses({CargoClass::Passengers})),
MK( 1, CT_COAL, 6, 16, 0x100, 5916, 7, 255, true, TAE_NONE, COAL, COAL, STR_TONS, CC_BULK | CC_NON_POTABLE), MK( 1, CT_COAL, 6, 16, 0x100, 5916, 7, 255, true, TAE_NONE, COAL, COAL, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::NonPotable})),
MK( 2, CT_MAIL, 15, 4, 0x200, 4550, 20, 90, false, TAE_MAIL, MAIL, MAIL, STR_BAGS, CC_MAIL), MK( 2, CT_MAIL, 15, 4, 0x200, 4550, 20, 90, false, TAE_MAIL, MAIL, MAIL, STR_BAGS, CargoClasses({CargoClass::Mail})),
/* Oil in temperate and arctic */ /* Oil in temperate and arctic */
MK( 3, CT_OIL, 174, 16, 0x100, 4437, 25, 255, true, TAE_NONE, OIL, OIL, STR_LITERS, CC_LIQUID | CC_NON_POTABLE), MK( 3, CT_OIL, 174, 16, 0x100, 4437, 25, 255, true, TAE_NONE, OIL, OIL, STR_LITERS, CargoClasses({CargoClass::Liquid, CargoClass::NonPotable})),
/* Oil in subtropic */ /* Oil in subtropic */
MK( 3, CT_OIL, 174, 16, 0x100, 4892, 25, 255, true, TAE_NONE, OIL, OIL, STR_LITERS, CC_LIQUID | CC_NON_POTABLE), MK( 3, CT_OIL, 174, 16, 0x100, 4892, 25, 255, true, TAE_NONE, OIL, OIL, STR_LITERS, CargoClasses({CargoClass::Liquid, CargoClass::NonPotable})),
MK( 4, CT_LIVESTOCK, 208, 3, 0x100, 4322, 4, 18, true, TAE_NONE, LIVESTOCK, LIVESTOCK, STR_ITEMS, CC_PIECE_GOODS | CC_NON_POTABLE), MK( 4, CT_LIVESTOCK, 208, 3, 0x100, 4322, 4, 18, true, TAE_NONE, LIVESTOCK, LIVESTOCK, STR_ITEMS, CargoClasses({CargoClass::PieceGoods, CargoClass::NonPotable})),
MK( 5, CT_GOODS, 194, 8, 0x200, 6144, 5, 28, true, TAE_GOODS, GOODS, GOODS, STR_CRATES, CC_EXPRESS), MK( 5, CT_GOODS, 194, 8, 0x200, 6144, 5, 28, true, TAE_GOODS, GOODS, GOODS, STR_CRATES, CargoClasses({CargoClass::Express})),
MK( 6, CT_GRAIN, 191, 16, 0x100, 4778, 4, 40, true, TAE_NONE, GRAIN, GRAIN, STR_TONS, CC_BULK | CC_POTABLE), MK( 6, CT_GRAIN, 191, 16, 0x100, 4778, 4, 40, true, TAE_NONE, GRAIN, GRAIN, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::Potable})),
MK( 6, CT_WHEAT, 191, 16, 0x100, 4778, 4, 40, true, TAE_NONE, WHEAT, WHEAT, STR_TONS, CC_BULK | CC_POTABLE), MK( 6, CT_WHEAT, 191, 16, 0x100, 4778, 4, 40, true, TAE_NONE, WHEAT, WHEAT, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::Potable})),
MK( 6, CT_MAIZE, 191, 16, 0x100, 4322, 4, 40, true, TAE_NONE, MAIZE, MAIZE, STR_TONS, CC_BULK | CC_POTABLE), MK( 6, CT_MAIZE, 191, 16, 0x100, 4322, 4, 40, true, TAE_NONE, MAIZE, MAIZE, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::Potable})),
/* Wood in temperate and arctic */ /* Wood in temperate and arctic */
MK( 7, CT_WOOD, 84, 16, 0x100, 5005, 15, 255, true, TAE_NONE, WOOD, WOOD, STR_TONS, CC_PIECE_GOODS), MK( 7, CT_WOOD, 84, 16, 0x100, 5005, 15, 255, true, TAE_NONE, WOOD, WOOD, STR_TONS, CargoClasses({CargoClass::PieceGoods})),
/* Wood in subtropic */ /* Wood in subtropic */
MK( 7, CT_WOOD, 84, 16, 0x100, 7964, 15, 255, true, TAE_NONE, WOOD, WOOD, STR_TONS, CC_PIECE_GOODS), MK( 7, CT_WOOD, 84, 16, 0x100, 7964, 15, 255, true, TAE_NONE, WOOD, WOOD, STR_TONS, CargoClasses({CargoClass::PieceGoods})),
MK( 8, CT_IRON_ORE, 184, 16, 0x100, 5120, 9, 255, true, TAE_NONE, IRON_ORE, IRON_ORE, STR_TONS, CC_BULK | CC_NON_POTABLE), MK( 8, CT_IRON_ORE, 184, 16, 0x100, 5120, 9, 255, true, TAE_NONE, IRON_ORE, IRON_ORE, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::NonPotable})),
MK( 9, CT_STEEL, 10, 16, 0x100, 5688, 7, 255, true, TAE_NONE, STEEL, STEEL, STR_TONS, CC_PIECE_GOODS), MK( 9, CT_STEEL, 10, 16, 0x100, 5688, 7, 255, true, TAE_NONE, STEEL, STEEL, STR_TONS, CargoClasses({CargoClass::PieceGoods})),
MK( 10, CT_VALUABLES, 202, 2, 0x100, 7509, 1, 32, true, TAE_NONE, VALUABLES, VALUABLES, STR_BAGS, CC_ARMOURED), MK( 10, CT_VALUABLES, 202, 2, 0x100, 7509, 1, 32, true, TAE_NONE, VALUABLES, VALUABLES, STR_BAGS, CargoClasses({CargoClass::Armoured})),
MK( 10, CT_GOLD, 202, 8, 0x100, 5802, 10, 40, true, TAE_NONE, GOLD, GOLD, STR_BAGS, CC_ARMOURED), MK( 10, CT_GOLD, 202, 8, 0x100, 5802, 10, 40, true, TAE_NONE, GOLD, GOLD, STR_BAGS, CargoClasses({CargoClass::Armoured})),
MK( 10, CT_DIAMONDS, 202, 2, 0x100, 5802, 10, 255, true, TAE_NONE, DIAMONDS, DIAMOND, STR_BAGS, CC_ARMOURED), MK( 10, CT_DIAMONDS, 202, 2, 0x100, 5802, 10, 255, true, TAE_NONE, DIAMONDS, DIAMOND, STR_BAGS, CargoClasses({CargoClass::Armoured})),
MK( 11, CT_PAPER, 10, 16, 0x100, 5461, 7, 60, true, TAE_NONE, PAPER, PAPER, STR_TONS, CC_PIECE_GOODS), MK( 11, CT_PAPER, 10, 16, 0x100, 5461, 7, 60, true, TAE_NONE, PAPER, PAPER, STR_TONS, CargoClasses({CargoClass::PieceGoods})),
MK( 12, CT_FOOD, 48, 16, 0x100, 5688, 0, 30, true, TAE_FOOD, FOOD, FOOD, STR_TONS, CC_EXPRESS | CC_REFRIGERATED | CC_POTABLE), MK( 12, CT_FOOD, 48, 16, 0x100, 5688, 0, 30, true, TAE_FOOD, FOOD, FOOD, STR_TONS, CargoClasses({CargoClass::Express, CargoClass::Refrigerated, CargoClass::Potable})),
MK( 13, CT_FRUIT, 208, 16, 0x100, 4209, 0, 15, true, TAE_NONE, FRUIT, FRUIT, STR_TONS, CC_BULK | CC_REFRIGERATED | CC_POTABLE), MK( 13, CT_FRUIT, 208, 16, 0x100, 4209, 0, 15, true, TAE_NONE, FRUIT, FRUIT, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::Refrigerated, CargoClass::Potable})),
MK( 14, CT_COPPER_ORE, 184, 16, 0x100, 4892, 12, 255, true, TAE_NONE, COPPER_ORE, COPPER_ORE, STR_TONS, CC_BULK | CC_NON_POTABLE), MK( 14, CT_COPPER_ORE, 184, 16, 0x100, 4892, 12, 255, true, TAE_NONE, COPPER_ORE, COPPER_ORE, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::NonPotable})),
MK( 15, CT_WATER, 10, 16, 0x100, 4664, 20, 80, true, TAE_WATER, WATER, WATER, STR_LITERS, CC_LIQUID | CC_POTABLE), MK( 15, CT_WATER, 10, 16, 0x100, 4664, 20, 80, true, TAE_WATER, WATER, WATER, STR_LITERS, CargoClasses({CargoClass::Liquid, CargoClass::Potable})),
MK( 16, CT_RUBBER, 6, 16, 0x100, 4437, 2, 20, true, TAE_NONE, RUBBER, RUBBER, STR_LITERS, CC_LIQUID | CC_NON_POTABLE), MK( 16, CT_RUBBER, 6, 16, 0x100, 4437, 2, 20, true, TAE_NONE, RUBBER, RUBBER, STR_LITERS, CargoClasses({CargoClass::Liquid, CargoClass::NonPotable})),
MK( 17, CT_SUGAR, 6, 16, 0x100, 4437, 20, 255, true, TAE_NONE, SUGAR, SUGAR, STR_TONS, CC_BULK | CC_POTABLE), MK( 17, CT_SUGAR, 6, 16, 0x100, 4437, 20, 255, true, TAE_NONE, SUGAR, SUGAR, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::Potable})),
MK( 18, CT_TOYS, 174, 2, 0x100, 5574, 25, 255, true, TAE_NONE, TOYS, TOY, STR_ITEMS, CC_PIECE_GOODS), MK( 18, CT_TOYS, 174, 2, 0x100, 5574, 25, 255, true, TAE_NONE, TOYS, TOY, STR_ITEMS, CargoClasses({CargoClass::PieceGoods})),
MK( 19, CT_BATTERIES, 208, 4, 0x100, 4322, 2, 30, true, TAE_NONE, BATTERIES, BATTERY, STR_ITEMS, CC_PIECE_GOODS), MK( 19, CT_BATTERIES, 208, 4, 0x100, 4322, 2, 30, true, TAE_NONE, BATTERIES, BATTERY, STR_ITEMS, CargoClasses({CargoClass::PieceGoods})),
MK( 20, CT_CANDY, 194, 5, 0x200, 6144, 8, 40, true, TAE_GOODS, SWEETS, SWEETS, STR_BAGS, CC_EXPRESS), MK( 20, CT_CANDY, 194, 5, 0x200, 6144, 8, 40, true, TAE_GOODS, SWEETS, SWEETS, STR_BAGS, CargoClasses({CargoClass::Express})),
MK( 21, CT_TOFFEE, 191, 16, 0x100, 4778, 14, 60, true, TAE_NONE, TOFFEE, TOFFEE, STR_TONS, CC_BULK), MK( 21, CT_TOFFEE, 191, 16, 0x100, 4778, 14, 60, true, TAE_NONE, TOFFEE, TOFFEE, STR_TONS, CargoClasses({CargoClass::Bulk})),
MK( 22, CT_COLA, 84, 16, 0x100, 4892, 5, 75, true, TAE_NONE, COLA, COLA, STR_LITERS, CC_LIQUID), MK( 22, CT_COLA, 84, 16, 0x100, 4892, 5, 75, true, TAE_NONE, COLA, COLA, STR_LITERS, CargoClasses({CargoClass::Liquid})),
MK( 23, CT_COTTON_CANDY, 184, 16, 0x100, 5005, 10, 25, true, TAE_NONE, CANDYFLOSS, CANDYFLOSS, STR_TONS, CC_BULK), MK( 23, CT_COTTON_CANDY, 184, 16, 0x100, 5005, 10, 25, true, TAE_NONE, CANDYFLOSS, CANDYFLOSS, STR_TONS, CargoClasses({CargoClass::Bulk})),
MK( 24, CT_BUBBLES, 10, 1, 0x100, 5077, 20, 80, true, TAE_NONE, BUBBLES, BUBBLE, STR_ITEMS, CC_PIECE_GOODS), MK( 24, CT_BUBBLES, 10, 1, 0x100, 5077, 20, 80, true, TAE_NONE, BUBBLES, BUBBLE, STR_ITEMS, CargoClasses({CargoClass::PieceGoods})),
MK( 25, CT_PLASTIC, 202, 16, 0x100, 4664, 30, 255, true, TAE_NONE, PLASTIC, PLASTIC, STR_LITERS, CC_LIQUID), MK( 25, CT_PLASTIC, 202, 16, 0x100, 4664, 30, 255, true, TAE_NONE, PLASTIC, PLASTIC, STR_LITERS, CargoClasses({CargoClass::Liquid})),
MK( 26, CT_FIZZY_DRINKS, 48, 2, 0x100, 6250, 30, 50, true, TAE_FOOD, FIZZY_DRINKS, FIZZY_DRINK, STR_ITEMS, CC_PIECE_GOODS), MK( 26, CT_FIZZY_DRINKS, 48, 2, 0x100, 6250, 30, 50, true, TAE_FOOD, FIZZY_DRINKS, FIZZY_DRINK, STR_ITEMS, CargoClasses({CargoClass::PieceGoods})),
/* Void slot in temperate */ /* Void slot in temperate */
MK(0xFF, CT_INVALID, 1, 0, 0x100, 5688, 0, 30, true, TAE_NONE, NOTHING, NOTHING, STR_TONS, CC_NOAVAILABLE), MK(0xFF, CT_INVALID, 1, 0, 0x100, 5688, 0, 30, true, TAE_NONE, NOTHING, NOTHING, STR_TONS, CargoClasses({})),
/* Void slot in arctic */ /* Void slot in arctic */
MK(0xFF, CT_INVALID, 184, 0, 0x100, 5120, 9, 255, true, TAE_NONE, NOTHING, NOTHING, STR_TONS, CC_NOAVAILABLE), MK(0xFF, CT_INVALID, 184, 0, 0x100, 5120, 9, 255, true, TAE_NONE, NOTHING, NOTHING, STR_TONS, CargoClasses({})),
}; };

View File

@ -288,7 +288,7 @@ uint Vehicle::Crash(bool)
/* crash all wagons, and count passengers */ /* crash all wagons, and count passengers */
for (Vehicle *v = this; v != nullptr; v = v->Next()) { for (Vehicle *v = this; v != nullptr; v = v->Next()) {
/* We do not transfer reserver cargo back, so TotalCount() instead of StoredCount() */ /* We do not transfer reserver cargo back, so TotalCount() instead of StoredCount() */
if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) pass += v->cargo.TotalCount(); if (IsCargoInClass(v->cargo_type, CargoClass::Passengers)) pass += v->cargo.TotalCount();
v->vehstatus |= VS_CRASHED; v->vehstatus |= VS_CRASHED;
v->MarkAllViewportsDirty(); v->MarkAllViewportsDirty();
} }
@ -2030,17 +2030,17 @@ LiveryScheme GetEngineLiveryScheme(EngineID engine_type, EngineID parent_engine_
/* 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 (e->info.misc_flags.Test(EngineMiscFlag::RoadIsTram)) { if (e->info.misc_flags.Test(EngineMiscFlag::RoadIsTram)) {
/* Tram */ /* Tram */
return IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_PASSENGER_TRAM : LS_FREIGHT_TRAM; return IsCargoInClass(cargo_type, CargoClass::Passengers) ? LS_PASSENGER_TRAM : LS_FREIGHT_TRAM;
} else { } else {
/* Bus or truck */ /* Bus or truck */
return IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_BUS : LS_TRUCK; return IsCargoInClass(cargo_type, CargoClass::Passengers) ? LS_BUS : LS_TRUCK;
} }
case VEH_SHIP: case VEH_SHIP:
if (!IsValidCargoType(cargo_type)) cargo_type = e->GetDefaultCargoType(); if (!IsValidCargoType(cargo_type)) cargo_type = e->GetDefaultCargoType();
if (!IsValidCargoType(cargo_type)) cargo_type = GetCargoTypeByLabel(CT_GOODS); // The vehicle does not carry anything, let's pick some freight cargo if (!IsValidCargoType(cargo_type)) cargo_type = GetCargoTypeByLabel(CT_GOODS); // The vehicle does not carry anything, let's pick some freight cargo
assert(IsValidCargoType(cargo_type)); assert(IsValidCargoType(cargo_type));
return IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_PASSENGER_SHIP : LS_FREIGHT_SHIP; return IsCargoInClass(cargo_type, CargoClass::Passengers) ? LS_PASSENGER_SHIP : LS_FREIGHT_SHIP;
case VEH_AIRCRAFT: case VEH_AIRCRAFT:
switch (e->u.air.subtype) { switch (e->u.air.subtype) {

View File

@ -289,7 +289,7 @@ static int GetRefitCostFactor(const Vehicle *v, EngineID engine_type, CargoType
/* Is this vehicle a NewGRF vehicle? */ /* Is this vehicle a NewGRF vehicle? */
if (e->GetGRF() != nullptr) { if (e->GetGRF() != nullptr) {
const CargoSpec *cs = CargoSpec::Get(new_cargo_type); const CargoSpec *cs = CargoSpec::Get(new_cargo_type);
uint32_t param1 = (cs->classes << 16) | (new_subtype << 8) | e->GetGRF()->cargo_map[new_cargo_type]; uint32_t param1 = (cs->classes.base() << 16) | (new_subtype << 8) | e->GetGRF()->cargo_map[new_cargo_type];
uint16_t cb_res = GetVehicleCallback(CBID_VEHICLE_REFIT_COST, param1, 0, engine_type, v); uint16_t cb_res = GetVehicleCallback(CBID_VEHICLE_REFIT_COST, param1, 0, engine_type, v);
if (cb_res != CALLBACK_FAILED) { if (cb_res != CALLBACK_FAILED) {

View File

@ -292,7 +292,7 @@ static bool CargoFilterSingle(const Vehicle *v, const CargoType cargo_type)
bool have_capacity = false; bool have_capacity = false;
for (const Vehicle *w = v; w != nullptr; w = w->Next()) { for (const Vehicle *w = v; w != nullptr; w = w->Next()) {
if (w->cargo_cap > 0) { if (w->cargo_cap > 0) {
if (IsCargoInClass(w->cargo_type, CC_PASSENGERS)) { if (IsCargoInClass(w->cargo_type, CargoClass::Passengers)) {
return false; return false;
} else { } else {
have_capacity = true; have_capacity = true;