changeset 12415:6a77d1df56e2 draft

(svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()
author smatz <smatz@openttd.org>
date Thu, 16 Jul 2009 19:00:13 +0000
parents 5443128573f4
children 0f2c3c5e5288
files src/ai/api/ai_cargo.cpp src/ai/api/ai_cargolist.cpp src/ai/api/ai_subsidy.cpp src/build_vehicle_gui.cpp src/cargotype.cpp src/cargotype.h src/economy.cpp src/graph_gui.cpp src/industry_cmd.cpp src/industry_gui.cpp src/misc.cpp src/misc_gui.cpp src/newgrf.cpp src/newgrf_cargo.cpp src/newgrf_engine.cpp src/newgrf_station.cpp src/order_gui.cpp src/saveload/afterload.cpp src/station_cmd.cpp src/station_gui.cpp src/strings.cpp src/subsidy.cpp src/subsidy_gui.cpp src/town_cmd.cpp src/town_gui.cpp src/train_cmd.cpp src/vehicle.cpp src/vehicle_gui.cpp
diffstat 28 files changed, 100 insertions(+), 91 deletions(-) [+]
line wrap: on
line diff
--- a/src/ai/api/ai_cargo.cpp
+++ b/src/ai/api/ai_cargo.cpp
@@ -11,13 +11,13 @@
 
 /* static */ bool AICargo::IsValidCargo(CargoID cargo_type)
 {
-	return (cargo_type < NUM_CARGO && ::GetCargo(cargo_type)->IsValid());
+	return (cargo_type < NUM_CARGO && ::CargoSpec::Get(cargo_type)->IsValid());
 }
 
 /* static */ char *AICargo::GetCargoLabel(CargoID cargo_type)
 {
 	if (!IsValidCargo(cargo_type)) return NULL;
-	const CargoSpec *cargo = ::GetCargo(cargo_type);
+	const CargoSpec *cargo = ::CargoSpec::Get(cargo_type);
 
 	/* cargo->label is a uint32 packing a 4 character non-terminated string,
 	 * like "PASS", "COAL", "OIL_". New ones can be defined by NewGRFs */
@@ -32,7 +32,7 @@
 /* static */ bool AICargo::IsFreight(CargoID cargo_type)
 {
 	if (!IsValidCargo(cargo_type)) return false;
-	const CargoSpec *cargo = ::GetCargo(cargo_type);
+	const CargoSpec *cargo = ::CargoSpec::Get(cargo_type);
 	return cargo->is_freight;
 }
 
@@ -46,7 +46,7 @@
 {
 	if (!IsValidCargo(cargo_type)) return TE_NONE;
 
-	return (AICargo::TownEffect)GetCargo(cargo_type)->town_effect;
+	return (AICargo::TownEffect)CargoSpec::Get(cargo_type)->town_effect;
 }
 
 /* static */ Money AICargo::GetCargoIncome(CargoID cargo_type, uint32 distance, uint32 days_in_transit)
--- a/src/ai/api/ai_cargolist.cpp
+++ b/src/ai/api/ai_cargolist.cpp
@@ -11,7 +11,7 @@
 AICargoList::AICargoList()
 {
 	for (byte i = 0; i < NUM_CARGO; i++) {
-		const CargoSpec *c = ::GetCargo(i);
+		const CargoSpec *c = ::CargoSpec::Get(i);
 		if (c->IsValid()) {
 			this->AddItem(i);
 		}
--- a/src/ai/api/ai_subsidy.cpp
+++ b/src/ai/api/ai_subsidy.cpp
@@ -57,8 +57,8 @@
 {
 	if (!IsValidSubsidy(subsidy_id) || IsAwarded(subsidy_id)) return false;
 
-	return GetCargo(GetCargoType(subsidy_id))->town_effect == TE_PASSENGERS ||
-	       GetCargo(GetCargoType(subsidy_id))->town_effect == TE_MAIL;
+	return CargoSpec::Get(GetCargoType(subsidy_id))->town_effect == TE_PASSENGERS ||
+	       CargoSpec::Get(GetCargoType(subsidy_id))->town_effect == TE_MAIL;
 }
 
 /* static */ int32 AISubsidy::GetSource(SubsidyID subsidy_id)
@@ -72,7 +72,7 @@
 {
 	if (!IsValidSubsidy(subsidy_id) || IsAwarded(subsidy_id)) return false;
 
-	switch (GetCargo(GetCargoType(subsidy_id))->town_effect) {
+	switch (CargoSpec::Get(GetCargoType(subsidy_id))->town_effect) {
 		case TE_PASSENGERS:
 		case TE_MAIL:
 		case TE_GOODS:
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -445,7 +445,7 @@
 	/* Wagon weight - (including cargo) */
 	uint weight = e->GetDisplayWeight();
 	SetDParam(0, weight);
-	uint cargo_weight = (e->CanCarryCargo() ? GetCargo(e->GetDefaultCargoType())->weight * e->GetDisplayDefaultCapacity() >> 4 : 0);
+	uint cargo_weight = (e->CanCarryCargo() ? CargoSpec::Get(e->GetDefaultCargoType())->weight * e->GetDisplayDefaultCapacity() >> 4 : 0);
 	SetDParam(1, cargo_weight + weight);
 	DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
 	y += FONT_HEIGHT_NORMAL;
@@ -821,7 +821,7 @@
 
 		/* Collect available cargo types for filtering */
 		for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
-			const CargoSpec *cargo = GetCargo(cid);
+			const CargoSpec *cargo = CargoSpec::Get(cid);
 			if (!cargo->IsValid()) continue;
 			if (IsCargoInClass(cid, CC_SPECIAL)) continue; // exclude fake cargo types
 			this->cargo_filter[filter_items] = cid;
--- a/src/cargotype.cpp
+++ b/src/cargotype.cpp
@@ -11,7 +11,7 @@
 #include "table/strings.h"
 #include "table/cargo_const.h"
 
-CargoSpec _cargo[NUM_CARGO];
+CargoSpec CargoSpec::cargo[NUM_CARGO];
 
 /* Bitmask of cargo types available */
 uint32 _cargo_mask;
@@ -22,8 +22,8 @@
 	assert(l < lengthof(_default_climate_cargo));
 
 	/* Reset and disable all cargo types */
-	memset(_cargo, 0, sizeof(_cargo));
-	for (CargoID i = 0; i < lengthof(_cargo); i++) _cargo[i].bitnum = INVALID_CARGO;
+	memset(CargoSpec::cargo, 0, sizeof(CargoSpec::cargo));
+	for (CargoID i = 0; i < lengthof(CargoSpec::cargo); i++) CargoSpec::Get(i)->bitnum = INVALID_CARGO;
 
 	_cargo_mask = 0;
 
@@ -33,8 +33,9 @@
 		/* Bzzt: check if cl is just an index into the cargo table */
 		if (cl < lengthof(_default_cargo)) {
 			/* Copy the indexed cargo */
-			_cargo[i] = _default_cargo[cl];
-			if (_cargo[i].bitnum != INVALID_CARGO) SetBit(_cargo_mask, i);
+			CargoSpec *cargo = CargoSpec::Get(i);
+			*cargo = _default_cargo[cl];
+			if (cargo->bitnum != INVALID_CARGO) SetBit(_cargo_mask, i);
 			continue;
 		}
 
@@ -42,7 +43,7 @@
 		 * the label matches */
 		for (uint j = 0; j < lengthof(_default_cargo); j++) {
 			if (_default_cargo[j].label == cl) {
-				_cargo[i] = _default_cargo[j];
+				*CargoSpec::Get(i) = _default_cargo[j];
 
 				/* Populate the available cargo mask */
 				SetBit(_cargo_mask, i);
@@ -55,9 +56,10 @@
 
 CargoID GetCargoIDByLabel(CargoLabel cl)
 {
-	for (CargoID c = 0; c < lengthof(_cargo); c++) {
-		if (_cargo[c].bitnum == INVALID_CARGO) continue;
-		if (_cargo[c].label == cl) return c;
+	for (CargoID c = 0; c < lengthof(CargoSpec::cargo); c++) {
+		CargoSpec *cargo = CargoSpec::Get(c);
+		if (cargo->bitnum == INVALID_CARGO) continue;
+		if (cargo->label == cl) return c;
 	}
 
 	/* No matching label was found, so it is invalid */
@@ -73,8 +75,8 @@
 {
 	if (bitnum == INVALID_CARGO) return CT_INVALID;
 
-	for (CargoID c = 0; c < lengthof(_cargo); c++) {
-		if (_cargo[c].bitnum == bitnum) return c;
+	for (CargoID c = 0; c < lengthof(CargoSpec::cargo); c++) {
+		if (CargoSpec::Get(c)->bitnum == bitnum) return c;
 	}
 
 	/* No matching label was found, so it is invalid */
--- a/src/cargotype.h
+++ b/src/cargotype.h
@@ -54,11 +54,27 @@
 	{
 		return this->bitnum != INVALID_CARGO;
 	}
+
+	/**
+	 * Retrieve cargo details for the given cargo ID
+	 * @param c ID of cargo
+	 * @pre c is a valid cargo ID
+	 */
+	static CargoSpec *Get(CargoID c)
+	{
+		assert(c < lengthof(CargoSpec::cargo));
+		return &CargoSpec::cargo[c];
+	}
+
+private:
+	static CargoSpec cargo[NUM_CARGO];
+
+	friend void SetupCargoForClimate(LandscapeID l);
+	friend CargoID GetCargoIDByLabel(CargoLabel cl);
+	friend CargoID GetCargoIDByBitnum(uint8 bitnum);
 };
 
 extern uint32 _cargo_mask;
-extern CargoSpec _cargo[NUM_CARGO];
-
 
 /* Set up the default cargo types for the given landscape type */
 void SetupCargoForClimate(LandscapeID l);
@@ -68,18 +84,9 @@
 CargoID GetCargoIDByLabel(CargoLabel cl);
 CargoID GetCargoIDByBitnum(uint8 bitnum);
 
-/* Retrieve cargo details for the given cargo ID */
-static inline const CargoSpec *GetCargo(CargoID c)
+static inline bool IsCargoInClass(CargoID c, uint16 cc)
 {
-	assert(c < lengthof(_cargo));
-	return &_cargo[c];
+	return (CargoSpec::Get(c)->classes & cc) != 0;
 }
 
-
-static inline bool IsCargoInClass(CargoID c, uint16 cc)
-{
-	return (GetCargo(c)->classes & cc) != 0;
-}
-
-
 #endif /* CARGOTYPE_H */
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -833,7 +833,7 @@
 	bool needed = false;
 
 	for (CargoID c = 0; c < NUM_CARGO; c++) {
-		const CargoSpec *cs = GetCargo(c);
+		const CargoSpec *cs = CargoSpec::Get(c);
 		if (!cs->IsValid()) continue;
 		if (_cargo_payment_rates[c] == 0) {
 			needed = true;
@@ -866,7 +866,7 @@
 
 Money GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, CargoID cargo_type)
 {
-	const CargoSpec *cs = GetCargo(cargo_type);
+	const CargoSpec *cs = CargoSpec::Get(cargo_type);
 
 	/* Use callback to calculate cargo profit, if available */
 	if (HasBit(cs->callback_mask, CBM_CARGO_PROFIT_CALC)) {
@@ -1089,7 +1089,7 @@
 	}
 
 	/* Increase town's counter for some special goods types */
-	const CargoSpec *cs = GetCargo(cargo_type);
+	const CargoSpec *cs = CargoSpec::Get(cargo_type);
 	if (cs->town_effect == TE_FOOD) s_to->town->new_act_food += num_pieces;
 	if (cs->town_effect == TE_WATER) s_to->town->new_act_water += num_pieces;
 
--- a/src/graph_gui.cpp
+++ b/src/graph_gui.cpp
@@ -737,7 +737,7 @@
 	{
 		uint num_active = 0;
 		for (CargoID c = 0; c < NUM_CARGO; c++) {
-			if (GetCargo(c)->IsValid()) num_active++;
+			if (CargoSpec::Get(c)->IsValid()) num_active++;
 		}
 
 		/* Resize the window to fit the cargo types */
@@ -787,7 +787,7 @@
 
 		uint i = 0;
 		for (CargoID c = 0; c < NUM_CARGO; c++) {
-			const CargoSpec *cs = GetCargo(c);
+			const CargoSpec *cs = CargoSpec::Get(c);
 			if (!cs->IsValid()) continue;
 
 			/* Only draw labels for widgets that exist. If the widget doesn't
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -2076,7 +2076,7 @@
 		default: NOT_REACHED();
 	}
 	SetDParam(2, abs(percent));
-	SetDParam(0, GetCargo(type)->name);
+	SetDParam(0, CargoSpec::Get(type)->name);
 	SetDParam(1, ind->index);
 	AddIndustryNewsItem(
 		percent >= 0 ? STR_NEWS_INDUSTRY_PRODUCTION_INCREASE_SMOOTH : STR_NEWS_INDUSTRY_PRODUCTION_DECREASE_SMOOTH,
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -261,7 +261,7 @@
 		for (byte j = 0; j < lengthof(indsp->accepts_cargo); j++) {
 			if (indsp->accepts_cargo[j] == CT_INVALID) continue;
 			if (p > 0) str++;
-			SetDParam(p++, GetCargo(indsp->accepts_cargo[j])->name);
+			SetDParam(p++, CargoSpec::Get(indsp->accepts_cargo[j])->name);
 			SetDParam(p++, GetCargoSuffix(j, CST_FUND, NULL, this->selected_type, indsp));
 		}
 		DrawString(x_str, right, y_str, str);
@@ -275,7 +275,7 @@
 		for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) {
 			if (indsp->produced_cargo[j] == CT_INVALID) continue;
 			if (p > 0) str++;
-			SetDParam(p++, GetCargo(indsp->produced_cargo[j])->name);
+			SetDParam(p++, CargoSpec::Get(indsp->produced_cargo[j])->name);
 			SetDParam(p++, GetCargoSuffix(j + 3, CST_FUND, NULL, this->selected_type, indsp));
 		}
 		DrawString(x_str, right, y_str, str);
@@ -522,7 +522,7 @@
 				if (i->accepts_cargo[j] == CT_INVALID) continue;
 				has_accept = true;
 				if (p > 0) str++;
-				SetDParam(p++, GetCargo(i->accepts_cargo[j])->name);
+				SetDParam(p++, CargoSpec::Get(i->accepts_cargo[j])->name);
 				SetDParam(p++, GetCargoSuffix(j, CST_VIEW, i, i->type, ind));
 			}
 			if (has_accept) {
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -133,7 +133,7 @@
 	if (only_constants) return;
 
 	for (CargoID i = 0; i < NUM_CARGO; i++) {
-		_cargo_payment_rates[i] = GetCargo(i)->initial_payment;
+		_cargo_payment_rates[i] = CargoSpec::Get(i)->initial_payment;
 		_cargo_payment_rates_frac[i] = 0;
 	}
 }
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -240,10 +240,10 @@
 				/* If the accepted value is less than 8, show it in 1/8:ths */
 				if (acceptance[i] < 8) {
 					SetDParam(0, acceptance[i]);
-					SetDParam(1, GetCargo(i)->name);
+					SetDParam(1, CargoSpec::Get(i)->name);
 					strp = GetString(strp, STR_LAND_AREA_INFORMATION_CARGO_EIGHTS, lastof(this->landinfo_data[LAND_INFO_MULTICENTER_LINE]));
 				} else {
-					strp = GetString(strp, GetCargo(i)->name, lastof(this->landinfo_data[LAND_INFO_MULTICENTER_LINE]));
+					strp = GetString(strp, CargoSpec::Get(i)->name, lastof(this->landinfo_data[LAND_INFO_MULTICENTER_LINE]));
 				}
 			}
 		}
@@ -834,7 +834,7 @@
 				*b++ = ',';
 				*b++ = ' ';
 			}
-			b = InlineString(b, GetCargo(i)->name);
+			b = InlineString(b, CargoSpec::Get(i)->name);
 		}
 	}
 
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -1506,7 +1506,7 @@
 				 * climate. This can cause problems when copying the properties
 				 * of a house that accepts food, where the new house is valid
 				 * in the temperate climate. */
-				if (!GetCargo(housespec->accepts_cargo[2])->IsValid()) {
+				if (!CargoSpec::Get(housespec->accepts_cargo[2])->IsValid()) {
 					housespec->cargo_acceptance[2] = 0;
 				}
 
@@ -1552,7 +1552,7 @@
 						((_settings_game.game_creation.landscape == LT_TOYLAND) ? CT_FIZZY_DRINKS : CT_FOOD);
 
 				/* Make sure the cargo type is valid in this climate. */
-				if (!GetCargo(cid)->IsValid()) goods = 0;
+				if (!CargoSpec::Get(cid)->IsValid()) goods = 0;
 
 				housespec->accepts_cargo[2] = cid;
 				housespec->cargo_acceptance[2] = abs(goods); // but we do need positive value here
@@ -1897,7 +1897,7 @@
 	}
 
 	for (int i = 0; i < numinfo; i++) {
-		CargoSpec *cs = &_cargo[cid + i];
+		CargoSpec *cs = CargoSpec::Get(cid + i);
 
 		switch (prop) {
 			case 0x08: // Bit number of cargo
@@ -2995,7 +2995,7 @@
 		}
 
 		for (CargoID c = 0; c < NUM_CARGO; c++) {
-			const CargoSpec *cs = GetCargo(c);
+			const CargoSpec *cs = CargoSpec::Get(c);
 			if (!cs->IsValid()) continue;
 
 			if (cs->bitnum == ctype) {
@@ -3290,7 +3290,7 @@
 			continue;
 		}
 
-		CargoSpec *cs = &_cargo[cid];
+		CargoSpec *cs = CargoSpec::Get(cid);
 		cs->grffile = _cur_grffile;
 		cs->group = _cur_grffile->spritegroups[groupid];
 	}
@@ -5587,7 +5587,7 @@
 	memset(_cur_grffile->cargo_map, 0xFF, sizeof(_cur_grffile->cargo_map));
 
 	for (CargoID c = 0; c < NUM_CARGO; c++) {
-		const CargoSpec *cs = GetCargo(c);
+		const CargoSpec *cs = CargoSpec::Get(c);
 		if (!cs->IsValid()) continue;
 
 		if (_cur_grffile->cargo_max == 0) {
@@ -5699,7 +5699,7 @@
 			} else {
 				/* No cargo table, so use the cargo bitnum values */
 				for (CargoID c = 0; c < NUM_CARGO; c++) {
-					const CargoSpec *cs = GetCargo(c);
+					const CargoSpec *cs = CargoSpec::Get(c);
 					if (!cs->IsValid()) continue;
 
 					if (HasBit(ei->refit_mask, cs->bitnum)) SetBit(xor_mask, c);
@@ -5710,7 +5710,7 @@
 		if (_gted[engine].cargo_allowed != 0) {
 			/* Build up the list of cargo types from the set cargo classes. */
 			for (CargoID i = 0; i < NUM_CARGO; i++) {
-				const CargoSpec *cs = GetCargo(i);
+				const CargoSpec *cs = CargoSpec::Get(i);
 				if (_gted[engine].cargo_allowed    & cs->classes) SetBit(mask,     i);
 				if (_gted[engine].cargo_disallowed & cs->classes) SetBit(not_mask, i);
 			}
--- a/src/newgrf_cargo.cpp
+++ b/src/newgrf_cargo.cpp
@@ -122,7 +122,7 @@
 uint8 GetReverseCargoTranslation(CargoID cargo, const GRFFile *grffile)
 {
 	/* Note: All grf versions use CargoBit here. Pre-version 7 do NOT use the 'climate dependent' ID. */
-	const CargoSpec *cs = GetCargo(cargo);
+	const CargoSpec *cs = CargoSpec::Get(cargo);
 
 	/* If the GRF contains a translation table (and the cargo is in the table)
 	 * then get the cargo ID for the label */
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -493,7 +493,7 @@
 				const Engine *e = Engine::Get(object->u.vehicle.self_type);
 				CargoID cargo_type = e->GetDefaultCargoType();
 				if (cargo_type != CT_INVALID) {
-					const CargoSpec *cs = GetCargo(cargo_type);
+					const CargoSpec *cs = CargoSpec::Get(cargo_type);
 					return (cs->classes << 16) | (cs->weight << 8) | GetEngineGRF(e->index)->cargo_map[cargo_type];
 				} else {
 					return 0x000000FF;
@@ -549,7 +549,7 @@
 					/* Skip empty engines */
 					if (u->cargo_cap == 0) continue;
 
-					cargo_classes |= GetCargo(u->cargo_type)->classes;
+					cargo_classes |= CargoSpec::Get(u->cargo_type)->classes;
 					common_cargos[u->cargo_type]++;
 				}
 
@@ -579,7 +579,7 @@
 					}
 				}
 
-				uint8 common_bitnum = (common_cargo_type == CT_INVALID ? 0xFF : GetCargo(common_cargo_type)->bitnum);
+				uint8 common_bitnum = (common_cargo_type == CT_INVALID ? 0xFF : CargoSpec::Get(common_cargo_type)->bitnum);
 				v->vcache.cached_var42 = cargo_classes | (common_bitnum << 8) | (common_subtype << 16) | (user_def_data << 24);
 				SetBit(v->vcache.cache_valid, 2);
 			}
@@ -652,7 +652,7 @@
 			 * ww - cargo unit weight in 1/16 tons, same as cargo prop. 0F.
 			 * cccc - the cargo class value of the cargo transported by the vehicle.
 			 */
-			const CargoSpec *cs = GetCargo(v->cargo_type);
+			const CargoSpec *cs = CargoSpec::Get(v->cargo_type);
 
 			return (cs->classes << 16) | (cs->weight << 8) | GetEngineGRF(v->engine_type)->cargo_map[v->cargo_type];
 		}
--- a/src/newgrf_station.cpp
+++ b/src/newgrf_station.cpp
@@ -611,7 +611,7 @@
 	} else {
 		/* Pick the first cargo that we have waiting */
 		for (CargoID cargo = 0; cargo < NUM_CARGO; cargo++) {
-			const CargoSpec *cs = GetCargo(cargo);
+			const CargoSpec *cs = CargoSpec::Get(cargo);
 			if (cs->IsValid() && object->u.station.statspec->spritegroup[cargo] != NULL &&
 					!object->u.station.st->goods[cargo].cargo.Empty()) {
 				ctype = cargo;
--- a/src/order_gui.cpp
+++ b/src/order_gui.cpp
@@ -248,7 +248,7 @@
 
 			if (!timetable && order->IsRefit()) {
 				SetDParam(6, (order->GetDepotActionType() & ODATFB_HALT) ? STR_REFIT_STOP_ORDER : STR_REFIT_ORDER);
-				SetDParam(7, GetCargo(order->GetRefitCargo())->name);
+				SetDParam(7, CargoSpec::Get(order->GetRefitCargo())->name);
 			}
 			break;
 
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -1924,7 +1924,7 @@
 				const Station *to = Station::GetIfValid(s->to);
 				if (from != NULL && to != NULL && from->owner == to->owner && Company::IsValidID(from->owner)) continue;
 			} else {
-				const CargoSpec *cs = GetCargo(s->cargo_type);
+				const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
 				switch (cs->town_effect) {
 					case TE_PASSENGERS:
 					case TE_MAIL:
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -137,7 +137,7 @@
 		/* 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. */
 		if (ind->produced_cargo[i] != CT_INVALID &&
-				(GetCargo(ind->produced_cargo[i])->classes & (CC_LIQUID | CC_PASSENGERS | CC_MAIL)) == 0) {
+				(CargoSpec::Get(ind->produced_cargo[i])->classes & (CC_LIQUID | CC_PASSENGERS | CC_MAIL)) == 0) {
 			return true;
 		}
 	}
@@ -182,7 +182,7 @@
 
 	for (uint i = 0; i < lengthof(ind->produced_cargo); i++) {
 		/* The industry produces wood. */
-		if (ind->produced_cargo[i] != CT_INVALID && GetCargo(ind->produced_cargo[i])->label == 'WOOD') return true;
+		if (ind->produced_cargo[i] != CT_INVALID && CargoSpec::Get(ind->produced_cargo[i])->label == 'WOOD') return true;
 	}
 
 	return false;
@@ -411,7 +411,7 @@
 static void ShowRejectOrAcceptNews(const Station *st, uint num_items, CargoID *cargo, StringID msg)
 {
 	for (uint i = 0; i < num_items; i++) {
-		SetDParam(i + 1, GetCargo(cargo[i])->name);
+		SetDParam(i + 1, CargoSpec::Get(cargo[i])->name);
 	}
 
 	SetDParam(0, st->index);
--- a/src/station_gui.cpp
+++ b/src/station_gui.cpp
@@ -49,7 +49,7 @@
 	static const uint units_full  = 576; ///< number of units to show station as 'full'
 	static const uint rating_full = 224; ///< rating needed so it is shown as 'full'
 
-	const CargoSpec *cs = GetCargo(type);
+	const CargoSpec *cs = CargoSpec::Get(type);
 	if (!cs->IsValid()) return;
 
 	int colour = cs->rating_colour;
@@ -258,7 +258,7 @@
 		/* Add cargo filter buttons */
 		uint num_active = 0;
 		for (CargoID c = 0; c < NUM_CARGO; c++) {
-			if (GetCargo(c)->IsValid()) num_active++;
+			if (CargoSpec::Get(c)->IsValid()) num_active++;
 		}
 
 		this->widget_count += num_active;
@@ -267,7 +267,7 @@
 
 		uint i = 0;
 		for (CargoID c = 0; c < NUM_CARGO; c++) {
-			if (!GetCargo(c)->IsValid()) continue;
+			if (!CargoSpec::Get(c)->IsValid()) continue;
 
 			Widget *wi = &this->widget[SLW_CARGOSTART + i];
 			wi->type     = WWT_PANEL;
@@ -346,7 +346,7 @@
 
 		uint i = 0;
 		for (CargoID c = 0; c < NUM_CARGO; c++) {
-			const CargoSpec *cs = GetCargo(c);
+			const CargoSpec *cs = CargoSpec::Get(c);
 			if (!cs->IsValid()) continue;
 
 			cg_ofst = HasBit(this->cargo_filter, c) ? 2 : 1;
@@ -457,7 +457,7 @@
 			case SLW_CARGOALL: {
 				uint i = 0;
 				for (CargoID c = 0; c < NUM_CARGO; c++) {
-					if (!GetCargo(c)->IsValid()) continue;
+					if (!CargoSpec::Get(c)->IsValid()) continue;
 					this->LowerWidget(i + SLW_CARGOSTART);
 					i++;
 				}
@@ -507,7 +507,7 @@
 					CargoID c;
 					int i = 0;
 					for (c = 0; c < NUM_CARGO; c++) {
-						if (!GetCargo(c)->IsValid()) continue;
+						if (!CargoSpec::Get(c)->IsValid()) continue;
 						if (widget - SLW_CARGOSTART == i) break;
 						i++;
 					}
@@ -724,7 +724,7 @@
 
 SpriteID GetCargoSprite(CargoID i)
 {
-	const CargoSpec *cs = GetCargo(i);
+	const CargoSpec *cs = CargoSpec::Get(i);
 	SpriteID sprite;
 
 	if (cs->sprite == 0xFFFF) {
@@ -924,7 +924,7 @@
 						*b++ = ',';
 						*b++ = ' ';
 					}
-					b = InlineString(b, GetCargo(i)->name);
+					b = InlineString(b, CargoSpec::Get(i)->name);
 				}
 			}
 
@@ -945,7 +945,7 @@
 			y += 10;
 
 			for (CargoID i = 0; i < NUM_CARGO; i++) {
-				const CargoSpec *cs = GetCargo(i);
+				const CargoSpec *cs = CargoSpec::Get(i);
 				if (!cs->IsValid()) continue;
 
 				const GoodsEntry *ge = &st->goods[i];
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -611,7 +611,7 @@
 				/* Short description of cargotypes. Layout:
 				 * 8-bit = cargo type
 				 * 16-bit = cargo count */
-				StringID cargo_str = GetCargo(GetInt32(&argv))->units_volume;
+				StringID cargo_str = CargoSpec::Get(GetInt32(&argv))->units_volume;
 				switch (cargo_str) {
 					case STR_TONS: {
 						int64 args[1];
@@ -750,7 +750,7 @@
 				 *   8bit   - cargo type
 				 *   16-bit - cargo count */
 				CargoID cargo = GetInt32(&argv);
-				StringID cargo_str = (cargo == CT_INVALID) ? STR_CARGO_N_A : GetCargo(cargo)->quantifier;
+				StringID cargo_str = (cargo == CT_INVALID) ? STR_CARGO_N_A : CargoSpec::Get(cargo)->quantifier;
 				buff = GetStringWithArgs(buff, cargo_str, argv++, last);
 				break;
 			}
--- a/src/subsidy.cpp
+++ b/src/subsidy.cpp
@@ -57,7 +57,7 @@
 	NewsReferenceType reftype2 = NR_NONE;
 
 	/* if mode is false, use the singular form */
-	const CargoSpec *cs = GetCargo(s->cargo_type);
+	const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
 	SetDParam(0, mode ? cs->name : cs->name_single);
 
 	if (s->age < 12) {
@@ -103,7 +103,7 @@
 	Subsidy *s;
 	FOR_ALL_SUBSIDIES(s) {
 		if (s->age < 12) {
-			const CargoSpec *cs = GetCargo(s->cargo_type);
+			const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
 			if (((cs->town_effect == TE_PASSENGERS || cs->town_effect == TE_MAIL) && (index == s->from || index == s->to)) ||
 				((cs->town_effect == TE_GOODS || cs->town_effect == TE_FOOD) && index == s->to)) {
 				s->cargo_type = CT_INVALID;
@@ -117,7 +117,7 @@
 	Subsidy *s;
 	FOR_ALL_SUBSIDIES(s) {
 		if (s->age < 12) {
-			const CargoSpec *cs = GetCargo(s->cargo_type);
+			const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
 			if (cs->town_effect != TE_PASSENGERS && cs->town_effect != TE_MAIL &&
 				(index == s->from || (cs->town_effect != TE_GOODS && cs->town_effect != TE_FOOD && index == s->to))) {
 				s->cargo_type = CT_INVALID;
@@ -192,7 +192,7 @@
 	 * or if the pct transported is already large enough */
 	if (total == 0 || trans > 42 || cargo == CT_INVALID) return;
 
-	const CargoSpec *cs = GetCargo(cargo);
+	const CargoSpec *cs = CargoSpec::Get(cargo);
 	if (cs->town_effect == TE_PASSENGERS) return;
 
 	fr->cargo = cargo;
@@ -287,7 +287,7 @@
 				s->cargo_type = fr.cargo;
 				s->from = ((Industry*)fr.from)->index;
 				{
-					const CargoSpec *cs = GetCargo(fr.cargo);
+					const CargoSpec *cs = CargoSpec::Get(fr.cargo);
 					s->to = (cs->town_effect == TE_GOODS || cs->town_effect == TE_FOOD) ? ((Town*)fr.to)->index : ((Industry*)fr.to)->index;
 				}
 	add_subsidy:
@@ -326,7 +326,7 @@
 	FOR_ALL_SUBSIDIES(s) {
 		if (s->cargo_type == cargo_type && s->age < 12) {
 			/* Check distance from source */
-			const CargoSpec *cs = GetCargo(cargo_type);
+			const CargoSpec *cs = CargoSpec::Get(cargo_type);
 			if (cs->town_effect == TE_PASSENGERS || cs->town_effect == TE_MAIL) {
 				xy = Town::Get(s->from)->xy;
 			} else {
--- a/src/subsidy_gui.cpp
+++ b/src/subsidy_gui.cpp
@@ -78,7 +78,7 @@
 
 	void HandleClick(const Subsidy *s)
 	{
-		TownEffect te = GetCargo(s->cargo_type)->town_effect;
+		TownEffect te = CargoSpec::Get(s->cargo_type)->town_effect;
 		TileIndex xy;
 
 		/* determine from coordinate for subsidy and try to scroll to it */
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -463,7 +463,7 @@
 
 			uint moved = MoveGoodsToStation(tile, 1, 1, cargo, amt);
 
-			const CargoSpec *cs = GetCargo(cargo);
+			const CargoSpec *cs = CargoSpec::Get(cargo);
 			switch (cs->town_effect) {
 				case TE_PASSENGERS:
 					t->new_max_pass += amt;
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -333,7 +333,7 @@
 			CargoID first_water_cargo = CT_INVALID;
 			StringID water_name = STR_CARGO_PLURAL_WATER;
 			for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
-				const CargoSpec *cs = GetCargo(cid);
+				const CargoSpec *cs = CargoSpec::Get(cid);
 				if (first_food_cargo == CT_INVALID && cs->town_effect == TE_FOOD) {
 					first_food_cargo = cid;
 					food_name = cs->name;
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -76,7 +76,7 @@
  */
 byte FreightWagonMult(CargoID cargo)
 {
-	if (!GetCargo(cargo)->is_freight) return 1;
+	if (!CargoSpec::Get(cargo)->is_freight) return 1;
 	return _settings_game.vehicle.freight_trains;
 }
 
@@ -139,7 +139,7 @@
 	uint32 weight = 0;
 
 	for (Train *u = v; u != NULL; u = u->Next()) {
-		uint32 vweight = GetCargo(u->cargo_type)->weight * u->cargo.Count() * FreightWagonMult(u->cargo_type) / 16;
+		uint32 vweight = CargoSpec::Get(u->cargo_type)->weight * u->cargo.Count() * FreightWagonMult(u->cargo_type) / 16;
 
 		/* Vehicle weight is not added for articulated parts. */
 		if (!u->IsArticulatedPart()) {
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -1290,7 +1290,7 @@
 				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 (rvi->railveh_type == RAILVEH_WAGON) {
-					if (!GetCargo(cargo_type)->is_freight) {
+					if (!CargoSpec::Get(cargo_type)->is_freight) {
 						if (parent_engine_type == INVALID_ENGINE) {
 							scheme = LS_PASSENGER_WAGON_STEAM;
 						} else {
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -251,7 +251,7 @@
 
 		if (i >= pos && i < pos + rows) {
 			/* Draw the cargo name */
-			int last_x = DrawString(2, right, y, GetCargo(refit[i].cargo)->name, colour);
+			int last_x = DrawString(2, right, y, CargoSpec::Get(refit[i].cargo)->name, colour);
 
 			/* If the callback succeeded, draw the cargo suffix */
 			if (refit[i].value != CALLBACK_FAILED) {
@@ -503,7 +503,7 @@
 			if (!first) b = strecpy(b, ", ", lastof(string));
 			first = false;
 
-			b = InlineString(b, GetCargo(cid)->name);
+			b = InlineString(b, CargoSpec::Get(cid)->name);
 		}
 	}