(svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()

This commit is contained in:
smatz 2009-07-16 19:00:13 +00:00
parent b6889daf8d
commit 1f29e38b83
28 changed files with 99 additions and 90 deletions

View File

@ -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)

View File

@ -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);
}

View File

@ -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:

View File

@ -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;

View File

@ -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 */

View File

@ -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 */

View File

@ -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;

View File

@ -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

View File

@ -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,

View File

@ -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) {

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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 */

View File

@ -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];
}

View File

@ -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;

View File

@ -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;

View File

@ -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:

View File

@ -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);

View File

@ -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];

View File

@ -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;
}

View File

@ -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 {

View File

@ -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 */

View File

@ -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;

View File

@ -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;

View File

@ -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()) {

View File

@ -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 {

View File

@ -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);
}
}