summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-07-16 19:00:13 +0000
committersmatz <smatz@openttd.org>2009-07-16 19:00:13 +0000
commit1f29e38b8372484d51d852b89fc957eb53635ecb (patch)
treeda4a251ac74e87e72a2857233069790f991914f6
parentb6889daf8d11b083358a26eea3f633942e2e50e4 (diff)
downloadopenttd-1f29e38b8372484d51d852b89fc957eb53635ecb.tar.xz
(svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()
-rw-r--r--src/ai/api/ai_cargo.cpp8
-rw-r--r--src/ai/api/ai_cargolist.cpp2
-rw-r--r--src/ai/api/ai_subsidy.cpp6
-rw-r--r--src/build_vehicle_gui.cpp4
-rw-r--r--src/cargotype.cpp24
-rw-r--r--src/cargotype.h31
-rw-r--r--src/economy.cpp6
-rw-r--r--src/graph_gui.cpp4
-rw-r--r--src/industry_cmd.cpp2
-rw-r--r--src/industry_gui.cpp6
-rw-r--r--src/misc.cpp2
-rw-r--r--src/misc_gui.cpp6
-rw-r--r--src/newgrf.cpp16
-rw-r--r--src/newgrf_cargo.cpp2
-rw-r--r--src/newgrf_engine.cpp8
-rw-r--r--src/newgrf_station.cpp2
-rw-r--r--src/order_gui.cpp2
-rw-r--r--src/saveload/afterload.cpp2
-rw-r--r--src/station_cmd.cpp6
-rw-r--r--src/station_gui.cpp18
-rw-r--r--src/strings.cpp4
-rw-r--r--src/subsidy.cpp12
-rw-r--r--src/subsidy_gui.cpp2
-rw-r--r--src/town_cmd.cpp2
-rw-r--r--src/town_gui.cpp2
-rw-r--r--src/train_cmd.cpp4
-rw-r--r--src/vehicle.cpp2
-rw-r--r--src/vehicle_gui.cpp4
28 files changed, 99 insertions, 90 deletions
diff --git a/src/ai/api/ai_cargo.cpp b/src/ai/api/ai_cargo.cpp
index 1e2684f1a..4b1593d26 100644
--- 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)
diff --git a/src/ai/api/ai_cargolist.cpp b/src/ai/api/ai_cargolist.cpp
index d35e54e30..ebf664dee 100644
--- 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);
}
diff --git a/src/ai/api/ai_subsidy.cpp b/src/ai/api/ai_subsidy.cpp
index 839654e43..de7616367 100644
--- 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:
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index 5a8433ffa..07443475b 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -445,7 +445,7 @@ static int DrawRailWagonPurchaseInfo(int left, int right, int y, EngineID engine
/* 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 @@ struct BuildVehicleWindow : Window {
/* 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;
diff --git a/src/cargotype.cpp b/src/cargotype.cpp
index 8216fbb65..cf1acb45e 100644
--- 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 @@ void SetupCargoForClimate(LandscapeID l)
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 @@ void SetupCargoForClimate(LandscapeID l)
/* 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 @@ void SetupCargoForClimate(LandscapeID l)
* 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 @@ void SetupCargoForClimate(LandscapeID l)
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 @@ CargoID GetCargoIDByBitnum(uint8 bitnum)
{
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 */
diff --git a/src/cargotype.h b/src/cargotype.h
index da17c1ada..d7e1b507c 100644
--- a/src/cargotype.h
+++ b/src/cargotype.h
@@ -54,11 +54,27 @@ struct CargoSpec {
{
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 @@ SpriteID GetCargoSprite(CargoID i);
CargoID GetCargoIDByLabel(CargoLabel cl);
CargoID GetCargoIDByBitnum(uint8 bitnum);
-/* Retrieve cargo details for the given cargo ID */
-static inline const CargoSpec *GetCargo(CargoID c)
-{
- assert(c < lengthof(_cargo));
- return &_cargo[c];
-}
-
-
static inline bool IsCargoInClass(CargoID c, uint16 cc)
{
- return (GetCargo(c)->classes & cc) != 0;
+ return (CargoSpec::Get(c)->classes & cc) != 0;
}
-
#endif /* CARGOTYPE_H */
diff --git a/src/economy.cpp b/src/economy.cpp
index 2c2077c0c..bcd678f31 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -833,7 +833,7 @@ void ResetEconomy()
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 GetPriceByIndex(uint8 index)
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 @@ static Money DeliverGoods(int num_pieces, CargoID cargo_type, StationID source,
}
/* 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;
diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp
index 3a8f03967..19a7713c4 100644
--- a/src/graph_gui.cpp
+++ b/src/graph_gui.cpp
@@ -737,7 +737,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
{
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 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
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
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 22c9ede1e..48022dbd8 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -2076,7 +2076,7 @@ static void ReportNewsProductionChangeIndustry(Industry *ind, CargoID type, int
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,
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index e1c3f586b..571b26706 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -261,7 +261,7 @@ public:
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 @@ public:
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 @@ public:
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) {
diff --git a/src/misc.cpp b/src/misc.cpp
index 518cd325a..a211ba4a1 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -133,7 +133,7 @@ void InitializeLandscapeVariables(bool only_constants)
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;
}
}
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index 459ef5f36..ccf557dfc 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -240,10 +240,10 @@ public:
/* 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 @@ static int DrawStationCoverageText(const CargoArray &cargos,
*b++ = ',';
*b++ = ' ';
}
- b = InlineString(b, GetCargo(i)->name);
+ b = InlineString(b, CargoSpec::Get(i)->name);
}
}
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index bd3712b58..9fd96ca40 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -1506,7 +1506,7 @@ static ChangeInfoResult TownHouseChangeInfo(uint hid, int numinfo, int prop, byt
* 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 @@ static ChangeInfoResult TownHouseChangeInfo(uint hid, int numinfo, int prop, byt
((_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 @@ static ChangeInfoResult CargoChangeInfo(uint cid, int numinfo, int prop, byte **
}
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 @@ static CargoID TranslateCargo(uint8 feature, uint8 ctype)
}
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 @@ static void CargoMapSpriteGroup(byte *buf, uint8 idcount)
continue;
}
- CargoSpec *cs = &_cargo[cid];
+ CargoSpec *cs = CargoSpec::Get(cid);
cs->grffile = _cur_grffile;
cs->group = _cur_grffile->spritegroups[groupid];
}
@@ -5587,7 +5587,7 @@ static void BuildCargoTranslationMap()
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 @@ static void CalculateRefitMasks()
} 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 @@ static void CalculateRefitMasks()
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);
}
diff --git a/src/newgrf_cargo.cpp b/src/newgrf_cargo.cpp
index 843c2ea6f..f276703b4 100644
--- a/src/newgrf_cargo.cpp
+++ b/src/newgrf_cargo.cpp
@@ -122,7 +122,7 @@ CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit)
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 */
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index df2622941..677b196f1 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -493,7 +493,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
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 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
/* 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 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
}
}
- 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 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
* 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];
}
diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp
index 89331f26b..9b91d83eb 100644
--- a/src/newgrf_station.cpp
+++ b/src/newgrf_station.cpp
@@ -611,7 +611,7 @@ static const SpriteGroup *ResolveStation(ResolverObject *object)
} 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;
diff --git a/src/order_gui.cpp b/src/order_gui.cpp
index 8a9d01340..96bb000a8 100644
--- a/src/order_gui.cpp
+++ b/src/order_gui.cpp
@@ -248,7 +248,7 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
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;
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index db6573292..3d5af563c 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -1924,7 +1924,7 @@ bool AfterLoadGame()
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:
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 4ab1a93f3..bb1db7152 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -137,7 +137,7 @@ static bool CMSAMine(TileIndex tile)
/* 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 @@ static bool CMSAForest(TileIndex tile)
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 uint GetAcceptanceMask(const Station *st)
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);
diff --git a/src/station_gui.cpp b/src/station_gui.cpp
index 65a2f39f6..310e2b0dd 100644
--- a/src/station_gui.cpp
+++ b/src/station_gui.cpp
@@ -49,7 +49,7 @@ static void StationsWndShowStationRating(int left, int right, int y, CargoID typ
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 @@ public:
/* 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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ static const NWidgetPart _nested_station_view_widgets[] = {
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 @@ struct StationViewWindow : public Window {
*b++ = ',';
*b++ = ' ';
}
- b = InlineString(b, GetCargo(i)->name);
+ b = InlineString(b, CargoSpec::Get(i)->name);
}
}
@@ -945,7 +945,7 @@ struct StationViewWindow : public Window {
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];
diff --git a/src/strings.cpp b/src/strings.cpp
index b113cf915..be047b3dd 100644
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -611,7 +611,7 @@ static char *FormatString(char *buff, const char *str, int64 *argv, uint casei,
/* 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 @@ static char *FormatString(char *buff, const char *str, int64 *argv, uint casei,
* 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;
}
diff --git a/src/subsidy.cpp b/src/subsidy.cpp
index 6bb026ad1..f37e92232 100644
--- a/src/subsidy.cpp
+++ b/src/subsidy.cpp
@@ -57,7 +57,7 @@ Pair SetupSubsidyDecodeParam(const Subsidy *s, bool mode)
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 @@ void DeleteSubsidyWithTown(TownID index)
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 @@ void DeleteSubsidyWithIndustry(IndustryID index)
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 @@ static void FindSubsidyCargoRoute(FoundRoute *fr)
* 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 @@ void SubsidyMonthlyLoop()
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 @@ bool CheckSubsidised(const Station *from, const Station *to, CargoID cargo_type,
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 {
diff --git a/src/subsidy_gui.cpp b/src/subsidy_gui.cpp
index d617f1d17..392ec2095 100644
--- a/src/subsidy_gui.cpp
+++ b/src/subsidy_gui.cpp
@@ -78,7 +78,7 @@ struct SubsidyListWindow : Window {
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 */
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index ad0cf2ac7..843e639be 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -463,7 +463,7 @@ static void TileLoop_Town(TileIndex tile)
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;
diff --git a/src/town_gui.cpp b/src/town_gui.cpp
index 110a68acf..b8dfe4fcf 100644
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -333,7 +333,7 @@ public:
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;
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 835c69639..3a4dde6a9 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -76,7 +76,7 @@ static inline DiagDirection TrainExitDir(Direction direction, TrackBits track)
*/
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 @@ static void TrainCargoChanged(Train *v)
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()) {
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 95c6c8fff..a92931706 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -1290,7 +1290,7 @@ const Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID
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 {
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 1fcd3bb5a..4cd80de46 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -251,7 +251,7 @@ static RefitOption *DrawVehicleRefitWindow(const RefitList *list, int sel, uint
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 @@ uint ShowRefitOptionsList(int left, int right, int y, EngineID engine)
if (!first) b = strecpy(b, ", ", lastof(string));
first = false;
- b = InlineString(b, GetCargo(cid)->name);
+ b = InlineString(b, CargoSpec::Get(cid)->name);
}
}