Changeset - r12405:ba094e765533
[Not reviewed]
src/ai/api/ai_cargo.cpp
Show inline comments
 
@@ -2,55 +2,55 @@
 

	
 
/** @file ai_cargo.cpp Implementation of AICargo. */
 

	
 
#include "ai_cargo.hpp"
 
#include "../../cargotype.h"
 
#include "../../economy_func.h"
 
#include "../../core/alloc_func.hpp"
 
#include "../../core/bitmath_func.hpp"
 
#include "../../newgrf_cargo.h"
 

	
 
/* 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 */
 
	char *cargo_label = MallocT<char>(sizeof(cargo->label) + 1);
 
	for (uint i = 0; i < sizeof(cargo->label); i++) {
 
		cargo_label[i] = GB(cargo->label, (uint8)(sizeof(cargo->label) - i - 1) * 8, 8);
 
	}
 
	cargo_label[sizeof(cargo->label)] = '\0';
 
	return cargo_label;
 
}
 

	
 
/* 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;
 
}
 

	
 
/* static */ bool AICargo::HasCargoClass(CargoID cargo_type, CargoClass cargo_class)
 
{
 
	if (!IsValidCargo(cargo_type)) return false;
 
	return ::IsCargoInClass(cargo_type, (::CargoClass)cargo_class);
 
}
 

	
 
/* static */ AICargo::TownEffect AICargo::GetTownEffect(CargoID cargo_type)
 
{
 
	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)
 
{
 
	if (!IsValidCargo(cargo_type)) return -1;
 
	return ::GetTransportedGoodsIncome(1, distance, Clamp(days_in_transit * 2 / 5, 0, 255), cargo_type);
 
}
src/ai/api/ai_cargolist.cpp
Show inline comments
 
@@ -2,25 +2,25 @@
 

	
 
/** @file ai_cargolist.cpp Implementation of AICargoList and friends. */
 

	
 
#include "ai_cargolist.hpp"
 
#include "ai_industry.hpp"
 
#include "../../cargotype.h"
 
#include "../../tile_type.h"
 
#include "../../industry.h"
 

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

	
 
AICargoList_IndustryAccepting::AICargoList_IndustryAccepting(IndustryID industry_id)
 
{
 
	if (!AIIndustry::IsValidIndustry(industry_id)) return;
 

	
 
	Industry *ind = ::Industry::Get(industry_id);
 
	for (uint i = 0; i < lengthof(ind->accepts_cargo); i++) {
src/ai/api/ai_subsidy.cpp
Show inline comments
 
@@ -48,40 +48,40 @@
 

	
 
/* static */ CargoID AISubsidy::GetCargoType(SubsidyID subsidy_id)
 
{
 
	if (!IsValidSubsidy(subsidy_id)) return CT_INVALID;
 

	
 
	return Subsidy::Get(subsidy_id)->cargo_type;
 
}
 

	
 
/* static */ bool AISubsidy::SourceIsTown(SubsidyID subsidy_id)
 
{
 
	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)
 
{
 
	if (!IsValidSubsidy(subsidy_id)) return INVALID_STATION;
 

	
 
	return Subsidy::Get(subsidy_id)->from;
 
}
 

	
 
/* static */ bool AISubsidy::DestinationIsTown(SubsidyID subsidy_id)
 
{
 
	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:
 
		case TE_FOOD:
 
			return true;
 
		default:
 
			return false;
 
	}
 
}
 

	
 
/* static */ int32 AISubsidy::GetDestination(SubsidyID subsidy_id)
 
{
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -436,25 +436,25 @@ static int DrawCargoCapacityInfo(int lef
 
static int DrawRailWagonPurchaseInfo(int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi)
 
{
 
	const Engine *e = Engine::Get(engine_number);
 

	
 
	/* Purchase cost */
 
	SetDParam(0, e->GetCost());
 
	DrawString(left, right, y, STR_PURCHASE_INFO_COST);
 
	y += FONT_HEIGHT_NORMAL;
 

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

	
 
	/* Wagon speed limit, displayed if above zero */
 
	if (_settings_game.vehicle.wagon_speed_limits) {
 
		uint max_speed = e->GetDisplayMaxSpeed();
 
		if (max_speed > 0) {
 
			SetDParam(0, max_speed);
 
			DrawString(left, right, y, STR_PURCHASE_INFO_SPEED);
 
			y += FONT_HEIGHT_NORMAL;
 
		}
 
@@ -812,25 +812,25 @@ struct BuildVehicleWindow : Window {
 
		filter_items++;
 

	
 
		/* Add item for vehicles not carrying anything, e.g. train engines.
 
		 * This could also be useful for eyecandy vehicles of other types, but is likely too confusing for joe, */
 
		if (type == VEH_TRAIN) {
 
			this->cargo_filter[filter_items] = CF_NONE;
 
			this->cargo_filter_texts[filter_items] = STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY_NONE;
 
			filter_items++;
 
		}
 

	
 
		/* 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;
 
			this->cargo_filter_texts[filter_items] = cargo->name;
 
			filter_items++;
 
		}
 

	
 
		this->cargo_filter_texts[filter_items] = INVALID_STRING_ID;
 
		if (this->cargo_filter_criteria >= filter_items) this->cargo_filter_criteria = 0;
 

	
 
		this->eng_list.SetFilterFuncs(_filter_funcs);
 
		this->eng_list.SetFilterState(this->cargo_filter[this->cargo_filter_criteria] != CF_ANY);
src/cargotype.cpp
Show inline comments
 
@@ -2,82 +2,84 @@
 

	
 
/** @file cargotype.cpp Implementation of cargos. */
 

	
 
#include "stdafx.h"
 
#include "newgrf_cargo.h"
 
#include "cargotype.h"
 
#include "core/bitmath_func.hpp"
 

	
 
#include "table/sprites.h"
 
#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;
 

	
 

	
 
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;
 

	
 
	for (CargoID i = 0; i < lengthof(_default_climate_cargo[l]); i++) {
 
		CargoLabel cl = _default_climate_cargo[l][i];
 

	
 
		/* 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;
 
		}
 

	
 
		/* Loop through each of the default cargo types to see if
 
		 * 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);
 
				break;
 
			}
 
		}
 
	}
 
}
 

	
 

	
 
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 */
 
	return CT_INVALID;
 
}
 

	
 

	
 
/** Find the CargoID of a 'bitnum' value.
 
 * @param bitnum 'bitnum' to find.
 
 * @return First CargoID with the given bitnum, or CT_INVALID if not found.
 
 */
 
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 */
 
	return CT_INVALID;
 
}
 

	
src/cargotype.h
Show inline comments
 
@@ -45,41 +45,48 @@ struct CargoSpec {
 
	StringID abbrev;
 

	
 
	SpriteID sprite;
 

	
 
	uint16 classes;
 
	const struct GRFFile *grffile;   ///< NewGRF where 'group' belongs to
 
	const struct SpriteGroup *group;
 

	
 
	bool IsValid() const
 
	{
 
		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);
 
/* Get the cargo icon for a given cargo ID */
 
SpriteID GetCargoSprite(CargoID i);
 
/* Get the cargo ID with the cargo label */
 
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 */
src/economy.cpp
Show inline comments
 
@@ -824,25 +824,25 @@ void StartupEconomy()
 
	_economy.fluct = GB(Random(), 0, 8) + 168;
 

	
 
	StartupIndustryDailyChanges(true); // As we are starting a new game, initialize the counter too
 

	
 
}
 

	
 
void ResetEconomy()
 
{
 
	/* Test if resetting the economy is needed. */
 
	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;
 
			break;
 
		}
 
	}
 

	
 
	if (!needed) return;
 

	
 
	/* Remember old unrounded maximum loan value. NewGRF has the ability
 
	 * to change all the other inflation affected base costs. */
 
	Money old_value = _economy.max_loan_unround;
 
@@ -857,25 +857,25 @@ void ResetEconomy()
 
	}
 
}
 

	
 
Money GetPriceByIndex(uint8 index)
 
{
 
	if (index > NUM_PRICES) return 0;
 

	
 
	return ((Money*)&_price)[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)) {
 
		uint32 var18 = min(dist, 0xFFFF) | (min(num_pieces, 0xFF) << 16) | (transit_days << 24);
 
		uint16 callback = GetCargoCallback(CBID_CARGO_PROFIT_CALC, 0, var18, cs);
 
		if (callback != CALLBACK_FAILED) {
 
			int result = GB(callback, 0, 14);
 

	
 
			/* Simulate a 15 bit signed value */
 
			if (HasBit(callback, 14)) result = 0x4000 - result;
 

	
 
			/* "The result should be a signed multiplier that gets multiplied
 
@@ -1080,25 +1080,25 @@ static Money DeliverGoods(int num_pieces
 
	SetBit(company->cargo_types, cargo_type);
 

	
 
	const Station *s_to = Station::Get(dest);
 

	
 
	if (source != INVALID_STATION) {
 
		const Station *s_from = Station::Get(source);
 

	
 
		/* Check if a subsidy applies. */
 
		subsidised = CheckSubsidised(s_from, s_to, cargo_type, company->index);
 
	}
 

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

	
 
	/* Give the goods to the industry. */
 
	DeliverGoodsToIndustry(s_to, cargo_type, num_pieces);
 

	
 
	/* Determine profit */
 
	Money profit = GetTransportedGoodsIncome(num_pieces, DistanceManhattan(source_tile, s_to->xy), days_in_transit, cargo_type);
 

	
 
	/* Modify profit if a subsidy is in effect */
 
	if (subsidised) {
 
		switch (_settings_game.difficulty.subsidy_multiplier) {
src/graph_gui.cpp
Show inline comments
 
@@ -728,25 +728,25 @@ enum CargoPaymentRatesWidgets {
 
	CPW_CLOSEBOX,
 
	CPW_CAPTION,
 
	CPW_BACKGROUND,
 
	CPW_CARGO_FIRST,
 
};
 

	
 
struct PaymentRatesGraphWindow : BaseGraphWindow {
 
	PaymentRatesGraphWindow(const WindowDesc *desc, WindowNumber window_number) :
 
			BaseGraphWindow(desc, window_number, 2, 24, 200, false, STR_CURRCOMPACT)
 
	{
 
		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 */
 
		ResizeWindow(this, 0, max(num_active, 12U) * 8);
 

	
 
		/* Add widgets for each cargo type */
 
		this->widget_count += num_active;
 
		this->widget = ReallocT(this->widget, this->widget_count + 1);
 
		this->widget[this->widget_count].type = WWT_LAST;
 

	
 
		/* Set the properties of each widget */
 
		for (uint i = 0; i != num_active; i++) {
 
@@ -778,25 +778,25 @@ struct PaymentRatesGraphWindow : BaseGra
 

	
 
	virtual void OnPaint()
 
	{
 
		this->DrawWidgets();
 

	
 
		this->excluded_data = _legend_excluded_cargo;
 

	
 
		int x = 495;
 
		int y = 24;
 

	
 
		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
 
			 * exist then the local company has used the climate cheat or
 
			 * changed the NewGRF configuration with this window open. */
 
			if (i + CPW_CARGO_FIRST < this->widget_count) {
 
				/* Since the buttons have no text, no images,
 
				 * both the text and the coloured box have to be manually painted.
 
				 * clk_dif will move one pixel down and one pixel to the right
 
				 * when the button is clicked */
 
				byte clk_dif = this->IsWidgetLowered(i + CPW_CARGO_FIRST) ? 1 : 0;
 

	
src/industry_cmd.cpp
Show inline comments
 
@@ -2067,25 +2067,25 @@ int WhoCanServiceIndustry(Industry *ind)
 
 */
 
static void ReportNewsProductionChangeIndustry(Industry *ind, CargoID type, int percent)
 
{
 
	NewsSubtype ns;
 

	
 
	switch (WhoCanServiceIndustry(ind)) {
 
		case 0: ns = NS_INDUSTRY_NOBODY;  break;
 
		case 1: ns = NS_INDUSTRY_OTHER;   break;
 
		case 2: ns = NS_INDUSTRY_COMPANY; break;
 
		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,
 
		ns,
 
		ind->index
 
	);
 
}
 

	
 
enum {
 
	PERCENT_TRANSPORTED_60 = 153,
 
	PERCENT_TRANSPORTED_80 = 204,
 
};
src/industry_gui.cpp
Show inline comments
 
@@ -252,39 +252,39 @@ public:
 
			DrawString(x_str, right, y_str, STR_INDUSTRY_BUILD_COST);
 
			y_str += 11;
 
		}
 

	
 
		/* Draw the accepted cargos, if any. Otherwhise, will print "Nothing" */
 
		StringID str = STR_INDUSTRY_VIEW_REQUIRES_CARGO;
 
		byte p = 0;
 
		SetDParam(0, STR_JUST_NOTHING);
 
		SetDParam(1, STR_EMPTY);
 
		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);
 
		y_str += 11;
 

	
 
		/* Draw the produced cargos, if any. Otherwhise, will print "Nothing" */
 
		str = STR_INDUSTRY_VIEW_PRODUCES_CARGO;
 
		p = 0;
 
		SetDParam(0, STR_JUST_NOTHING);
 
		SetDParam(1, STR_EMPTY);
 
		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);
 
		y_str += 11;
 

	
 
		/* Get the additional purchase info text, if it has not already been */
 
		if (this->text[this->selected_index] == STR_NULL) {   // Have i been called already?
 
			if (HasBit(indsp->callback_flags, CBM_IND_FUND_MORE_TEXT)) {          // No. Can it be called?
 
				uint16 callback_res = GetIndustryCallback(CBID_INDUSTRY_FUND_MORE_TEXT, 0, 0, NULL, this->selected_type, INVALID_TILE);
 
				if (callback_res != CALLBACK_FAILED) {  // Did it failed?
 
					StringID newtxt = GetGRFStringID(indsp->grf_prop.grffile->grfid, 0xD000 + callback_res);  // No. here's the new string
 
					this->text[this->selected_index] = newtxt;   // Store it for further usage
 
@@ -513,25 +513,25 @@ public:
 
				SetDParam(1, i->incoming_cargo_waiting[j]);
 
				SetDParam(2, GetCargoSuffix(j, CST_VIEW, i, i->type, ind));
 
				DrawString(4, this->widget[IVW_INFO].right, y, STR_INDUSTRY_VIEW_WAITING_STOCKPILE_CARGO);
 
				y += 10;
 
			}
 
		} else {
 
			StringID str = STR_INDUSTRY_VIEW_REQUIRES_CARGO;
 
			byte p = 0;
 
			for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
 
				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) {
 
				DrawString(2, this->widget[IVW_INFO].right, y, str);
 
				y += 10;
 
			}
 
		}
 

	
 
		first = true;
 
		for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
 
			if (i->produced_cargo[j] == CT_INVALID) continue;
 
			if (first) {
src/misc.cpp
Show inline comments
 
@@ -124,16 +124,16 @@ void InitializeGame(uint size_x, uint si
 
	GamelogMode();
 
	GamelogGRFAddList(_grfconfig);
 
	GamelogStopAction();
 
}
 

	
 

	
 
/* Calculate constants that depend on the landscape type. */
 
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;
 
	}
 
}
src/misc_gui.cpp
Show inline comments
 
@@ -231,28 +231,28 @@ public:
 
		for (CargoID i = 0; i < NUM_CARGO; ++i) {
 
			if (acceptance[i] > 0) {
 
				/* Add a comma between each item. */
 
				if (found) {
 
					*strp++ = ',';
 
					*strp++ = ' ';
 
				}
 
				found = true;
 

	
 
				/* 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]));
 
				}
 
			}
 
		}
 
		if (!found) this->landinfo_data[LAND_INFO_MULTICENTER_LINE][0] = '\0';
 

	
 
		if (found) line_nr += 2;
 

	
 
		if (line_nr > 6) ResizeWindow(this, 0, 12 * (line_nr - 6));
 

	
 
		this->FindWindowPlacementAndResize(&_land_info_desc);
 

	
 
#if defined(_DEBUG)
 
@@ -825,25 +825,25 @@ static int DrawStationCoverageText(const
 
			case SCT_NON_PASSENGERS_ONLY: if (IsCargoInClass(i, CC_PASSENGERS)) continue; break;
 
			case SCT_ALL: break;
 
			default: NOT_REACHED();
 
		}
 
		if (cargos[i] >= (supplies ? 1U : 8U)) {
 
			if (first) {
 
				first = false;
 
			} else {
 
				/* Add a comma if this is not the first item */
 
				*b++ = ',';
 
				*b++ = ' ';
 
			}
 
			b = InlineString(b, GetCargo(i)->name);
 
			b = InlineString(b, CargoSpec::Get(i)->name);
 
		}
 
	}
 

	
 
	/* If first is still true then no cargo is accepted */
 
	if (first) b = InlineString(b, STR_JUST_NOTHING);
 

	
 
	*b = '\0';
 

	
 
	/* Make sure we detect any buffer overflow */
 
	assert(b < endof(string));
 

	
 
	SetDParamStr(0, string);
src/newgrf.cpp
Show inline comments
 
@@ -1497,25 +1497,25 @@ static ChangeInfoResult TownHouseChangeI
 
				housespec->local_id = hid + i;
 
				housespec->substitute_id = subs_id;
 
				housespec->grffile = _cur_grffile;
 
				housespec->random_colour[0] = 0x04;  // those 4 random colours are the base colour
 
				housespec->random_colour[1] = 0x08;  // for all new houses
 
				housespec->random_colour[2] = 0x0C;  // they stand for red, blue, orange and green
 
				housespec->random_colour[3] = 0x06;
 

	
 
				/* Make sure that the third cargo type is valid in this
 
				 * 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;
 
				}
 

	
 
				/**
 
				 * New houses do not (currently) expect to have a default start
 
				 * date before 1930, as this breaks the build date stuff.
 
				 * @see FinaliseHouseArray() for more details.
 
				 */
 
				if (housespec->min_year < 1930) housespec->min_year = 1930;
 

	
 
				_loaded_newgrf_features.has_newhouses = true;
 
			} break;
 
@@ -1543,25 +1543,25 @@ static ChangeInfoResult TownHouseChangeI
 
				housespec->cargo_acceptance[prop - 0x0D] = grf_load_byte(&buf);
 
				break;
 

	
 
			case 0x0F: { // Goods/candy, food/fizzy drinks acceptance
 
				int8 goods = grf_load_byte(&buf);
 

	
 
				/* If value of goods is negative, it means in fact food or, if in toyland, fizzy_drink acceptance.
 
				 * Else, we have "standard" 3rd cargo type, goods or candy, for toyland once more */
 
				CargoID cid = (goods >= 0) ? ((_settings_game.game_creation.landscape == LT_TOYLAND) ? CT_CANDY : CT_GOODS) :
 
						((_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
 
			} break;
 

	
 
			case 0x10: // Local authority rating decrease on removal
 
				housespec->remove_rating_decrease = grf_load_word(&buf);
 
				break;
 

	
 
			case 0x11: // Removal cost multiplier
 
				housespec->removal_cost = grf_load_byte(&buf);
 
				break;
 
@@ -1888,25 +1888,25 @@ static ChangeInfoResult GlobalVarReserve
 

	
 
static ChangeInfoResult CargoChangeInfo(uint cid, int numinfo, int prop, byte **bufp, int len)
 
{
 
	byte *buf = *bufp;
 
	ChangeInfoResult ret = CIR_SUCCESS;
 

	
 
	if (cid + numinfo > NUM_CARGO) {
 
		grfmsg(2, "CargoChangeInfo: Cargo type %d out of range (max %d)", cid + numinfo, NUM_CARGO - 1);
 
		return CIR_INVALID_ID;
 
	}
 

	
 
	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
 
				cs->bitnum = grf_load_byte(&buf);
 
				if (cs->IsValid()) {
 
					cs->grffile = _cur_grffile;
 
					SetBit(_cargo_mask, cid + i);
 
				} else {
 
					ClrBit(_cargo_mask, cid + i);
 
				}
 
				break;
 

	
 
@@ -2986,25 +2986,25 @@ static CargoID TranslateCargo(uint8 feat
 
	/* Special cargo types for purchase list and stations */
 
	if (feature == GSF_STATION && ctype == 0xFE) return CT_DEFAULT_NA;
 
	if (ctype == 0xFF) return CT_PURCHASE;
 

	
 
	if (_cur_grffile->cargo_max == 0) {
 
		/* No cargo table, so use bitnum values */
 
		if (ctype >= 32) {
 
			grfmsg(1, "TranslateCargo: Cargo bitnum %d out of range (max 31), skipping.", ctype);
 
			return CT_INVALID;
 
		}
 

	
 
		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) {
 
				grfmsg(6, "TranslateCargo: Cargo bitnum %d mapped to cargo type %d.", ctype, c);
 
				return c;
 
			}
 
		}
 

	
 
		grfmsg(5, "TranslateCargo: Cargo bitnum %d not available in this climate, skipping.", ctype);
 
		return CT_INVALID;
 
	}
 

	
 
@@ -3281,25 +3281,25 @@ static void CargoMapSpriteGroup(byte *bu
 

	
 
	uint16 groupid = grf_load_word(&buf);
 
	if (!IsValidGroupID(groupid, "CargoMapSpriteGroup")) return;
 

	
 
	for (uint i = 0; i < idcount; i++) {
 
		CargoID cid = cargos[i];
 

	
 
		if (cid >= NUM_CARGO) {
 
			grfmsg(1, "CargoMapSpriteGroup: Cargo ID %d out of range, skipping", cid);
 
			continue;
 
		}
 

	
 
		CargoSpec *cs = &_cargo[cid];
 
		CargoSpec *cs = CargoSpec::Get(cid);
 
		cs->grffile = _cur_grffile;
 
		cs->group = _cur_grffile->spritegroups[groupid];
 
	}
 
}
 

	
 

	
 
/* Action 0x03 */
 
static void FeatureMapSpriteGroup(byte *buf, size_t len)
 
{
 
	/* <03> <feature> <n-id> <ids>... <num-cid> [<cargo-type> <cid>]... <def-cid>
 
	 * id-list    := [<id>] [id-list]
 
	 * cargo-list := <cargo-type> <cid> [cargo-list]
 
@@ -5578,25 +5578,25 @@ static void ResetNewGRFData()
 
	/* Clear all GRF overrides */
 
	_grf_id_overrides.clear();
 

	
 
	InitializeSoundPool();
 
	_spritegroup_pool.CleanPool();
 
}
 

	
 
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) {
 
			/* Default translation table, so just a straight mapping to bitnum */
 
			_cur_grffile->cargo_map[c] = cs->bitnum;
 
		} else {
 
			/* Check the translation table for this cargo's label */
 
			for (uint i = 0; i < _cur_grffile->cargo_max; i++) {
 
				if (cs->label == _cur_grffile->cargo_list[i]) {
 
					_cur_grffile->cargo_map[c] = i;
 
					break;
 
				}
 
@@ -5690,36 +5690,36 @@ static void CalculateRefitMasks()
 
				uint num_cargo = min(32, file->cargo_max);
 
				for (uint i = 0; i < num_cargo; i++) {
 
					if (!HasBit(ei->refit_mask, i)) continue;
 

	
 
					CargoID c = GetCargoIDByLabel(file->cargo_list[i]);
 
					if (c == CT_INVALID) continue;
 

	
 
					SetBit(xor_mask, c);
 
				}
 
			} 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);
 
				}
 
			}
 
		}
 

	
 
		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);
 
			}
 
		} else if (xor_mask == 0) {
 
			/* Don't apply default refit mask to wagons or engines with no capacity */
 
			if (e->type != VEH_TRAIN || (e->u.rail.capacity != 0 && e->u.rail.railveh_type != RAILVEH_WAGON)) {
 
				const CargoLabel *cl = _default_refitmasks[e->type];
 
				for (uint i = 0;; i++) {
 
					if (cl[i] == 0) break;
 

	
 
					CargoID cargo = GetCargoIDByLabel(cl[i]);
 
					if (cargo == CT_INVALID) continue;
src/newgrf_cargo.cpp
Show inline comments
 
@@ -113,23 +113,23 @@ CargoID GetCargoTranslation(uint8 cargo,
 
			if (cargo < grffile->cargo_max) return GetCargoIDByLabel(grffile->cargo_list[cargo]);
 
		} else {
 
			/* Else the cargo value is a 'climate independent' 'bitnum' */
 
			if (HasBit(_cargo_mask, cargo)) return GetCargoIDByBitnum(cargo);
 
		}
 
	}
 
	return CT_INVALID;
 
}
 

	
 
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 */
 
	for (uint i = 0; i < grffile->cargo_max; i++) {
 
		if (cs->label == grffile->cargo_list[i]) return i;
 
	}
 

	
 
	/* No matching label was found, so we return the 'climate independent' 'bitnum' */
 
	return cs->bitnum;;
 
}
src/newgrf_engine.cpp
Show inline comments
 
@@ -484,25 +484,25 @@ static uint32 VehicleGetVariable(const R
 
{
 
	Vehicle *v = const_cast<Vehicle*>(GRV(object));
 

	
 
	if (v == NULL) {
 
		/* Vehicle does not exist, so we're in a purchase list */
 
		switch (variable) {
 
			case 0x43: return _current_company | (LiveryHelper(object->u.vehicle.self_type, NULL) << 24); // Owner information
 
			case 0x46: return 0;               // Motion counter
 
			case 0x47: { // Vehicle cargo info
 
				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;
 
				}
 
			}
 
			case 0x48: return Engine::Get(object->u.vehicle.self_type)->flags; // Vehicle Type Info
 
			case 0x49: return _cur_year; // 'Long' format build year
 
			case 0xC4: return Clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; // Build year
 
			case 0xDA: return INVALID_VEHICLE; // Next vehicle
 
			case 0xF2: return 0; // Cargo subtype
 
		}
 

	
 
@@ -540,25 +540,25 @@ static uint32 VehicleGetVariable(const R
 
				uint8 common_subtype = 0xFF; // Return 0xFF if nothing is carried
 

	
 
				/* Reset our arrays */
 
				memset(common_cargos, 0, sizeof(common_cargos));
 
				memset(common_subtypes, 0, sizeof(common_subtypes));
 

	
 
				for (u = v; u != NULL; u = u->Next()) {
 
					if (v->type == VEH_TRAIN) user_def_data |= Train::From(u)->tcache.user_def_data;
 

	
 
					/* 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]++;
 
				}
 

	
 
				/* Pick the most common cargo type */
 
				uint common_cargo_best_amount = 0;
 
				for (CargoID cargo = 0; cargo < NUM_CARGO; cargo++) {
 
					if (common_cargos[cargo] > common_cargo_best_amount) {
 
						common_cargo_best_amount = common_cargos[cargo];
 
						common_cargo_type = cargo;
 
					}
 
				}
 

	
 
@@ -570,25 +570,25 @@ static uint32 VehicleGetVariable(const R
 
					common_subtypes[u->cargo_subtype]++;
 
				}
 

	
 
				/* Pick the most common subcargo type*/
 
				uint common_subtype_best_amount = 0;
 
				for (uint i = 0; i < lengthof(common_subtypes); i++) {
 
					if (common_subtypes[i] > common_subtype_best_amount) {
 
						common_subtype_best_amount = common_subtypes[i];
 
						common_subtype = i;
 
					}
 
				}
 

	
 
				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);
 
			}
 
			return v->vcache.cached_var42;
 

	
 
		case 0x43: // Company information
 
			if (!HasBit(v->vcache.cache_valid, 3)) {
 
				v->vcache.cached_var43 = v->owner | (Company::IsHumanID(v->owner) ? 0 : 0x10000) | (LiveryHelper(v->engine_type, v) << 24);
 
				SetBit(v->vcache.cache_valid, 3);
 
			}
 
			return v->vcache.cached_var43;
 

	
 
@@ -643,25 +643,25 @@ static uint32 VehicleGetVariable(const R
 
		}
 

	
 
		case 0x46: // Motion counter
 
			return v->motion_counter;
 

	
 
		case 0x47: { // Vehicle cargo info
 
			/* Format: ccccwwtt
 
			 * tt - the cargo type transported by the vehicle,
 
			 *     translated if a translation table has been installed.
 
			 * 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];
 
		}
 

	
 
		case 0x48: return Engine::Get(v->engine_type)->flags; // Vehicle Type Info
 
		case 0x49: return v->build_year;
 

	
 
		/* Variables which use the parameter */
 
		case 0x60: // Count consist's engine ID occurance
 
			//EngineID engine = GetNewEngineID(GetEngineGRF(v->engine_type), v->type, parameter);
 
			if (v->type != VEH_TRAIN) return Engine::Get(v->engine_type)->internal_id == parameter;
 

	
src/newgrf_station.cpp
Show inline comments
 
@@ -602,25 +602,25 @@ static void NewStationResolver(ResolverO
 

	
 
static const SpriteGroup *ResolveStation(ResolverObject *object)
 
{
 
	const SpriteGroup *group;
 
	CargoID ctype = CT_DEFAULT_NA;
 

	
 
	if (object->u.station.st == NULL) {
 
		/* No station, so we are in a purchase list */
 
		ctype = CT_PURCHASE;
 
	} 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;
 
				break;
 
			}
 
		}
 
	}
 

	
 
	group = object->u.station.statspec->spritegroup[ctype];
 
	if (group == NULL) {
 
		ctype = CT_DEFAULT;
 
		group = object->u.station.statspec->spritegroup[ctype];
src/order_gui.cpp
Show inline comments
 
@@ -239,25 +239,25 @@ void DrawOrderString(const Vehicle *v, c
 
			if (order->GetDepotOrderType() & ODTFB_SERVICE) {
 
				SetDParam(2, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT);
 
			} else {
 
				SetDParam(2, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO);
 
			}
 

	
 
			if (!timetable && (order->GetDepotActionType() & ODATFB_HALT)) {
 
				SetDParam(6, STR_STOP_ORDER);
 
			}
 

	
 
			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;
 

	
 
		case OT_GOTO_WAYPOINT:
 
			if (v->type == VEH_TRAIN) {
 
				SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_GO_NON_STOP_TO_WAYPOINT : STR_GO_TO_WAYPOINT);
 
				SetDParam(2, order->GetDestination());
 
			} else {
 
				SetDParam(1, STR_GO_TO_STATION);
 
				SetDParam(2, STR_ORDER_GO_VIA);
 
				SetDParam(3, order->GetDestination());
 
				SetDParam(4, STR_EMPTY);
src/saveload/afterload.cpp
Show inline comments
 
@@ -1915,25 +1915,25 @@ bool AfterLoadGame()
 
			}
 
		}
 

	
 
		/* Delete invalid subsidies possibly present in old versions (but converted to new savegame) */
 
		Subsidy *s;
 
		FOR_ALL_SUBSIDIES(s) {
 
			if (s->age >= 12) {
 
				/* Station -> Station */
 
				const Station *from = Station::GetIfValid(s->from);
 
				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:
 
						/* Town -> Town */
 
						if (Town::IsValidID(s->from) && Town::IsValidID(s->to)) continue;
 
						break;
 
					case TE_GOODS:
 
					case TE_FOOD:
 
						/* Industry -> Town */
 
						if (Industry::IsValidID(s->from) && Town::IsValidID(s->to)) continue;
 
						break;
 
					default:
src/station_cmd.cpp
Show inline comments
 
@@ -128,25 +128,25 @@ static bool CMSAMine(TileIndex tile)
 
	/* No industry */
 
	if (!IsTileType(tile, MP_INDUSTRY)) return false;
 

	
 
	const Industry *ind = GetIndustryByTile(tile);
 

	
 
	/* No extractive industry */
 
	if ((GetIndustrySpec(ind->type)->life_type & INDUSTRYLIFE_EXTRACTIVE) == 0) return false;
 

	
 
	for (uint i = 0; i < lengthof(ind->produced_cargo); i++) {
 
		/* 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;
 
		}
 
	}
 

	
 
	return false;
 
}
 

	
 
/**
 
 * Check whether the tile is water.
 
 * @param tile the tile to investigate.
 
 * @return true if and only if the tile is a mine
 
 */
 
@@ -173,25 +173,25 @@ static bool CMSATree(TileIndex tile)
 
static bool CMSAForest(TileIndex tile)
 
{
 
	/* No industry */
 
	if (!IsTileType(tile, MP_INDUSTRY)) return false;
 

	
 
	const Industry *ind = GetIndustryByTile(tile);
 

	
 
	/* No extractive industry */
 
	if ((GetIndustrySpec(ind->type)->life_type & INDUSTRYLIFE_ORGANIC) == 0) return false;
 

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

	
 
#define M(x) ((x) - STR_SV_STNAME)
 

	
 
enum StationNaming {
 
	STATIONNAMING_RAIL = 0,
 
	STATIONNAMING_ROAD = 0,
 
	STATIONNAMING_AIRPORT,
 
	STATIONNAMING_OILRIG,
 
@@ -402,25 +402,25 @@ static uint GetAcceptanceMask(const Stat
 
	for (CargoID i = 0; i < NUM_CARGO; i++) {
 
		if (HasBit(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE)) mask |= 1 << i;
 
	}
 
	return mask;
 
}
 

	
 
/** Items contains the two cargo names that are to be accepted or rejected.
 
 * msg is the string id of the message to display.
 
 */
 
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);
 
	AddNewsItem(msg, NS_ACCEPTANCE, NR_STATION, st->index);
 
}
 

	
 
/**
 
 * Get the cargo types being produced around the tile (in a rectangle).
 
 * @param tile Northtile of area
 
 * @param w X extent of the area
 
 * @param h Y extent of the area
 
 * @param rad Search radius in addition to the given area
src/station_gui.cpp
Show inline comments
 
@@ -40,25 +40,25 @@
 
 * @param type   Cargo type
 
 * @param amount Cargo amount
 
 * @param rating ratings data for that particular cargo
 
 *
 
 * @note Each cargo-bar is 16 pixels wide and 6 pixels high
 
 * @note Each rating 14 pixels wide and 1 pixel high and is 1 pixel below the cargo-bar
 
 */
 
static void StationsWndShowStationRating(int left, int right, int y, CargoID type, uint amount, byte rating)
 
{
 
	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;
 
	uint w = (minu(amount, units_full) + 5) / 36;
 

	
 
	/* Draw total cargo (limited) on station (fits into 16 pixels) */
 
	if (w != 0) GfxFillRect(left, y, left + w - 1, y + 6, colour);
 

	
 
	/* Draw a one pixel-wide bar of additional cargo meter, useful
 
	 * for stations with only a small amount (<=30) */
 
	if (w == 0) {
 
		uint rest = amount / 5;
 
@@ -249,34 +249,34 @@ protected:
 

	
 
public:
 
	CompanyStationsWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
 
	{
 
		this->owner = (Owner)this->window_number;
 
		this->vscroll.cap = 12;
 
		this->resize.step_height = 10;
 
		this->resize.height = this->height - 10 * 7; // minimum if 5 in the list
 

	
 
		/* 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;
 
		this->widget = ReallocT(this->widget, this->widget_count + 1);
 
		this->widget[this->widget_count].type = WWT_LAST;
 

	
 
		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;
 
			wi->display_flags = RESIZE_NONE;
 
			wi->colour   = COLOUR_GREY;
 
			wi->left     = 89 + i * 14;
 
			wi->right    = wi->left + 13;
 
			wi->top      = 14;
 
			wi->bottom   = 24;
 
			wi->data     = 0;
 
			wi->tooltips = STR_USE_CTRL_TO_SELECT_MORE;
 

	
 
@@ -337,25 +337,25 @@ public:
 
		this->DrawWidgets();
 

	
 
		/* draw arrow pointing up/down for ascending/descending sorting */
 
		this->DrawSortButtonState(SLW_SORTBY, this->stations.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
 

	
 
		int cg_ofst;
 
		int x = 89;
 
		int y = 14;
 
		int xb = 2; ///< offset from left of widget
 

	
 
		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;
 
			GfxFillRect(x + cg_ofst, y + cg_ofst, x + cg_ofst + 10 , y + cg_ofst + 7, cs->rating_colour);
 
			DrawString(x + cg_ofst, x + 12 + cg_ofst, y + cg_ofst, cs->abbrev, TC_BLACK, SA_CENTER);
 
			x += 14;
 
			i++;
 
		}
 

	
 
		cg_ofst = this->IsWidgetLowered(SLW_NOCARGOWAITING) ? 2 : 1;
 
		DrawString(x + cg_ofst, x + cg_ofst + 12, y + cg_ofst, STR_ABBREV_NONE, TC_BLACK, SA_CENTER);
 
		x += 14;
 
@@ -448,25 +448,25 @@ public:
 
					this->LowerWidget(i + SLW_TRAIN);
 
				}
 
				this->LowerWidget(SLW_FACILALL);
 

	
 
				this->facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
 
				this->stations.ForceRebuild();
 
				this->SetDirty();
 
				break;
 

	
 
			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++;
 
				}
 
				this->LowerWidget(SLW_NOCARGOWAITING);
 
				this->LowerWidget(SLW_CARGOALL);
 

	
 
				this->cargo_filter = _cargo_mask;
 
				this->include_empty = true;
 
				this->stations.ForceRebuild();
 
				this->SetDirty();
 
				break;
 
			}
 
@@ -498,25 +498,25 @@ public:
 
				}
 
				this->SetWidgetLoweredState(SLW_CARGOALL, this->cargo_filter == _cargo_mask && this->include_empty);
 
				this->stations.ForceRebuild();
 
				this->SetDirty();
 
				break;
 

	
 
			default:
 
				if (widget >= SLW_CARGOSTART) { // change cargo_filter
 
					/* Determine the selected cargo type */
 
					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++;
 
					}
 

	
 
					if (_ctrl_pressed) {
 
						ToggleBit(this->cargo_filter, c);
 
						this->ToggleWidgetLoweredState(widget);
 
					} else {
 
						for (uint i = SLW_CARGOSTART; i < this->widget_count; i++) {
 
							this->RaiseWidget(i);
 
						}
 
						this->RaiseWidget(SLW_NOCARGOWAITING);
 
@@ -715,25 +715,25 @@ static const NWidgetPart _nested_station
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SVW_ACCEPTS), SetMinimalSize(61, 12), SetDataTip(STR_STATION_VIEW_RATINGS_BUTTON, STR_STATION_VIEW_RATINGS_TOOLTIP),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SVW_RENAME), SetMinimalSize(60, 12), SetResize(1, 0), SetDataTip(STR_QUERY_RENAME, STR_STATION_VIEW_RENAME_TOOLTIP),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SVW_TRAINS), SetMinimalSize(14, 12), SetDataTip(STR_TRAIN, STR_SCHEDULED_TRAINS_TIP),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SVW_ROADVEHS), SetMinimalSize(14, 12), SetDataTip(STR_LORRY, STR_SCHEDULED_ROAD_VEHICLES_TIP),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SVW_PLANES),  SetMinimalSize(14, 12), SetDataTip(STR_PLANE, STR_SCHEDULED_AIRCRAFT_TIP),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SVW_SHIPS), SetMinimalSize(14, 12), SetDataTip(STR_SHIP, STR_SCHEDULED_SHIPS_TIP),
 
		NWidget(WWT_RESIZEBOX, COLOUR_GREY, SVW_RESIZE),
 
	EndContainer(),
 
};
 

	
 
SpriteID GetCargoSprite(CargoID i)
 
{
 
	const CargoSpec *cs = GetCargo(i);
 
	const CargoSpec *cs = CargoSpec::Get(i);
 
	SpriteID sprite;
 

	
 
	if (cs->sprite == 0xFFFF) {
 
		/* A value of 0xFFFF indicates we should draw a custom icon */
 
		sprite = GetCustomCargoSprite(cs);
 
	} else {
 
		sprite = cs->sprite;
 
	}
 

	
 
	if (sprite == 0) sprite = SPR_CARGO_GOODS;
 

	
 
	return sprite;
 
@@ -915,46 +915,46 @@ struct StationViewWindow : public Window
 
			b = InlineString(b, STR_STATION_VIEW_ACCEPTS_CARGO);
 

	
 
			for (CargoID i = 0; i < NUM_CARGO; i++) {
 
				if (b >= lastof(string) - (1 + 2 * 4)) break; // ',' or ' ' and two calls to Utf8Encode()
 
				if (HasBit(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE)) {
 
					if (first) {
 
						first = false;
 
					} else {
 
						/* Add a comma if this is not the first item */
 
						*b++ = ',';
 
						*b++ = ' ';
 
					}
 
					b = InlineString(b, GetCargo(i)->name);
 
					b = InlineString(b, CargoSpec::Get(i)->name);
 
				}
 
			}
 

	
 
			/* If first is still true then no cargo is accepted */
 
			if (first) b = InlineString(b, STR_JUST_NOTHING);
 

	
 
			*b = '\0';
 

	
 
			/* Make sure we detect any buffer overflow */
 
			assert(b < endof(string));
 

	
 
			SetDParamStr(0, string);
 
			DrawStringMultiLine(this->widget[SVW_ACCEPTLIST].left + 2, this->widget[SVW_ACCEPTLIST].right - 2, this->widget[SVW_ACCEPTLIST].top + 1, this->widget[SVW_ACCEPTLIST].bottom - 1, STR_JUST_RAW_STRING);
 
		} else { // extended window with list of cargo ratings
 
			y = this->widget[SVW_RATINGLIST].top + 1;
 

	
 
			DrawString(this->widget[SVW_ACCEPTLIST].left + 2, this->widget[SVW_ACCEPTLIST].right - 2, y, STR_STATION_VIEW_CARGO_RATINGS_TITLE);
 
			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];
 
				if (!HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP)) continue;
 

	
 
				SetDParam(0, cs->name);
 
				SetDParam(2, ge->rating * 101 >> 8);
 
				SetDParam(1, STR_CARGO_RATING_APPALLING + (ge->rating >> 5));
 
				DrawString(this->widget[SVW_ACCEPTLIST].left + 8, this->widget[SVW_ACCEPTLIST].right - 2, y, STR_STATION_VIEW_CARGO_RATING);
 
				y += 10;
 
			}
 
		}
src/strings.cpp
Show inline comments
 
@@ -602,25 +602,25 @@ static char *FormatString(char *buff, co
 
			case SCC_CURRENCY_COMPACT: // {CURRCOMPACT}
 
				buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), true, last);
 
				break;
 

	
 
			case SCC_REVISION: // {REV}
 
				buff = strecpy(buff, _openttd_revision, last);
 
				break;
 

	
 
			case SCC_CARGO_SHORT: { // {SHORTCARGO}
 
				/* 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];
 
						assert(_settings_game.locale.units < lengthof(units));
 
						args[0] = GetInt32(&argv) * units[_settings_game.locale.units].w_m >> units[_settings_game.locale.units].w_s;
 
						buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].l_weight), args, modifier >> 24, last);
 
						modifier = 0;
 
						break;
 
					}
 

	
 
					case STR_LITERS: {
 
						int64 args[1];
 
@@ -741,25 +741,25 @@ static char *FormatString(char *buff, co
 
			}
 

	
 
			case SCC_DATE_ISO: { // {DATE_ISO}
 
				buff = FormatTinyOrISODate(buff, GetInt32(&argv), STR_DATE_ISO, last);
 
				break;
 
			}
 

	
 
			case SCC_CARGO: { // {CARGO}
 
				/* Layout now is:
 
				 *   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;
 
			}
 

	
 
			case SCC_POWER: { // {POWER}
 
				int64 args[1];
 
				assert(_settings_game.locale.units < lengthof(units));
 
				args[0] = GetInt32(&argv) * units[_settings_game.locale.units].p_m >> units[_settings_game.locale.units].p_s;
 
				buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].power), args, modifier >> 24, last);
 
				modifier = 0;
 
				break;
 
			}
src/subsidy.cpp
Show inline comments
 
@@ -48,25 +48,25 @@
 
 */
 
void InitializeSubsidies()
 
{
 
	Subsidy::Clean();
 
}
 

	
 
Pair SetupSubsidyDecodeParam(const Subsidy *s, bool mode)
 
{
 
	NewsReferenceType reftype1 = NR_NONE;
 
	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) {
 
		if (cs->town_effect != TE_PASSENGERS && cs->town_effect != TE_MAIL) {
 
			SetDParam(1, STR_INDUSTRY);
 
			SetDParam(2, s->from);
 
			reftype1 = NR_INDUSTRY;
 

	
 
			if (cs->town_effect != TE_GOODS && cs->town_effect != TE_FOOD) {
 
				SetDParam(4, STR_INDUSTRY);
 
				SetDParam(5, s->to);
 
				reftype2 = NR_INDUSTRY;
 
@@ -94,39 +94,39 @@ Pair SetupSubsidyDecodeParam(const Subsi
 

	
 
	Pair p;
 
	p.a = reftype1;
 
	p.b = reftype2;
 
	return p;
 
}
 

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

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

	
 
void DeleteSubsidyWithStation(StationID index)
 
{
 
	bool dirty = false;
 

	
 
@@ -183,25 +183,25 @@ static void FindSubsidyCargoRoute(FoundR
 
		total = i->last_month_production[1];
 
	} else {
 
		cargo = i->produced_cargo[0];
 
		trans = i->last_month_pct_transported[0];
 
		total = i->last_month_production[0];
 
	}
 

	
 
	/* Quit if no production in this industry
 
	 * or if the cargo type is passengers
 
	 * 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;
 

	
 
	if (cs->town_effect == TE_GOODS || cs->town_effect == TE_FOOD) {
 
		/*  The destination is a town */
 
		Town *t = Town::GetRandom();
 

	
 
		/* Only want big towns */
 
		if (t == NULL || t->population < 900) return;
 

	
 
		fr->distance = DistanceManhattan(i->xy, t->xy);
 
@@ -278,25 +278,25 @@ void SubsidyMonthlyLoop()
 
			FindSubsidyPassengerRoute(&fr);
 
			if (fr.distance <= 70) {
 
				s->cargo_type = CT_PASSENGERS;
 
				s->from = ((Town*)fr.from)->index;
 
				s->to = ((Town*)fr.to)->index;
 
				goto add_subsidy;
 
			}
 
			FindSubsidyCargoRoute(&fr);
 
			if (fr.distance <= 70) {
 
				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:
 
				if (!CheckSubsidyDuplicate(s)) {
 
					s->age = 0;
 
					Pair reftype = SetupSubsidyDecodeParam(s, 0);
 
					AddNewsItem(STR_NEWS_SERVICE_SUBSIDY_OFFERED, NS_SUBSIDIES, (NewsReferenceType)reftype.a, s->from, (NewsReferenceType)reftype.b, s->to);
 
					AI::BroadcastNewEvent(new AIEventSubsidyOffer(s->Index()));
 
					modified = true;
 
					break;
 
				}
 
			}
 
@@ -317,25 +317,25 @@ bool CheckSubsidised(const Station *from
 
		if (s->cargo_type == cargo_type &&
 
				s->age >= 12 &&
 
				s->from == from->index &&
 
				s->to == to->index) {
 
			return true;
 
		}
 
	}
 

	
 
	/* check if there's a new subsidy that applies.. */
 
	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 {
 
				xy = Industry::Get(s->from)->xy;
 
			}
 
			if (DistanceMax(xy, from->xy) > 9) continue;
 

	
 
			/* Check distance from dest */
 
			switch (cs->town_effect) {
 
				case TE_PASSENGERS:
 
				case TE_MAIL:
 
				case TE_GOODS:
src/subsidy_gui.cpp
Show inline comments
 
@@ -69,25 +69,25 @@ struct SubsidyListWindow : Window {
 
			if (s->age >= 12) {
 
				y -= FONT_HEIGHT_NORMAL;
 
				if (y < 0) {
 
					this->HandleClick(s);
 
					return;
 
				}
 
			}
 
		}
 
	}
 

	
 
	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 */
 
		uint offs = s->from;
 
		if (s->age >= 12) {
 
			xy = Station::Get(offs)->xy;
 
		} else if (te == TE_PASSENGERS || te == TE_MAIL) {
 
			xy = Town::Get(offs)->xy;
 
		} else {
 
			xy = Industry::Get(offs)->xy;
 
		}
 

	
src/town_cmd.cpp
Show inline comments
 
@@ -454,25 +454,25 @@ static void TileLoop_Town(TileIndex tile
 
			uint16 callback = GetHouseCallback(CBID_HOUSE_PRODUCE_CARGO, i, r, house_id, t, tile);
 

	
 
			if (callback == CALLBACK_FAILED || callback == CALLBACK_HOUSEPRODCARGO_END) break;
 

	
 
			CargoID cargo = GetCargoTranslation(GB(callback, 8, 7), hs->grffile);
 
			if (cargo == CT_INVALID) continue;
 

	
 
			uint amt = GB(callback, 0, 8);
 
			if (amt == 0) continue;
 

	
 
			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;
 
					t->new_act_pass += moved;
 
					break;
 

	
 
				case TE_MAIL:
 
					t->new_max_mail += amt;
 
					t->new_act_mail += moved;
 
					break;
 

	
 
				default:
src/town_gui.cpp
Show inline comments
 
@@ -324,25 +324,25 @@ public:
 

	
 
			default: break;
 
		}
 

	
 
		if (cargo_needed_for_growth > 0) {
 
			DrawString(2, this->width - 2, y += 10, STR_CARGO_FOR_TOWNGROWTH);
 

	
 
			CargoID first_food_cargo = CT_INVALID;
 
			StringID food_name = STR_CARGO_PLURAL_FOOD;
 
			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;
 
				}
 
				if (first_water_cargo == CT_INVALID && cs->town_effect == TE_WATER) {
 
					first_water_cargo = cid;
 
					water_name = cs->name;
 
				}
 
			}
 

	
 
			if (first_food_cargo != CT_INVALID && this->town->act_food > 0) {
 
				SetDParam(0, first_food_cargo);
src/train_cmd.cpp
Show inline comments
 
@@ -67,25 +67,25 @@ static inline DiagDirection TrainExitDir
 
	}
 

	
 
	return diagdir;
 
}
 

	
 

	
 
/** Return the cargo weight multiplier to use for a rail vehicle
 
 * @param cargo Cargo type to get multiplier for
 
 * @return Cargo weight multiplier
 
 */
 
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;
 
}
 

	
 

	
 
/**
 
 * Recalculates the cached total power of a train. Should be called when the consist is changed
 
 * @param v First vehicle of the consist.
 
 */
 
void TrainPowerChanged(Train *v)
 
{
 
	uint32 total_power = 0;
 
	uint32 max_te = 0;
 
@@ -130,25 +130,25 @@ void TrainPowerChanged(Train *v)
 

	
 

	
 
/**
 
 * Recalculates the cached weight of a train and its vehicles. Should be called each time the cargo on
 
 * the consist changes.
 
 * @param v First vehicle of the consist.
 
 */
 
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()) {
 
			/* vehicle weight is the sum of the weight of the vehicle and the weight of its cargo */
 
			vweight += GetVehicleProperty(u, 0x16, RailVehInfo(u->engine_type)->weight);
 
		}
 

	
 
		/* powered wagons have extra weight added */
 
		if (HasBit(u->flags, VRF_POWEREDWAGON)) {
 
			vweight += RailVehInfo(u->tcache.first_engine)->pow_wag_weight;
 
		}
 

	
src/vehicle.cpp
Show inline comments
 
@@ -1281,25 +1281,25 @@ const Livery *GetEngineLivery(EngineID e
 
				if (v != NULL && parent_engine_type != INVALID_ENGINE && (UsesWagonOverride(v) || (Train::From(v)->IsArticulatedPart() && rvi->railveh_type != RAILVEH_WAGON))) {
 
					/* Wagonoverrides use the coloir scheme of the front engine.
 
					 * Articulated parts use the colour scheme of the first part. (Not supported for articulated wagons) */
 
					engine_type = parent_engine_type;
 
					e = Engine::Get(engine_type);
 
					rvi = RailVehInfo(engine_type);
 
					/* Note: Luckily cargo_type is not needed for engines */
 
				}
 

	
 
				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 {
 
							switch (RailVehInfo(parent_engine_type)->engclass) {
 
								default: NOT_REACHED();
 
								case EC_STEAM:    scheme = LS_PASSENGER_WAGON_STEAM;    break;
 
								case EC_DIESEL:   scheme = LS_PASSENGER_WAGON_DIESEL;   break;
 
								case EC_ELECTRIC: scheme = LS_PASSENGER_WAGON_ELECTRIC; break;
 
								case EC_MONORAIL: scheme = LS_PASSENGER_WAGON_MONORAIL; break;
 
								case EC_MAGLEV:   scheme = LS_PASSENGER_WAGON_MAGLEV;   break;
 
							}
 
						}
src/vehicle_gui.cpp
Show inline comments
 
@@ -242,25 +242,25 @@ static RefitOption *DrawVehicleRefitWind
 
	uint i;
 

	
 
	/* Draw the list, and find the selected cargo (by its position in list) */
 
	for (i = 0; i < num_lines; i++) {
 
		TextColour colour = TC_BLACK;
 
		if (sel == 0) {
 
			selected = &refit[i];
 
			colour = TC_WHITE;
 
		}
 

	
 
		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) {
 
				DrawString(last_x + 1, right, y, GetGRFStringID(GetEngineGRFID(refit[i].engine), 0xD000 + refit[i].value), colour);
 
			}
 
			y += delta;
 
		}
 

	
 
		sel--;
 
	}
 

	
 
	return selected;
 
@@ -494,25 +494,25 @@ uint ShowRefitOptionsList(int left, int 
 

	
 
		bool first = true;
 

	
 
		/* Add each cargo type to the list */
 
		for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
 
			if (!HasBit(cmask, cid)) continue;
 

	
 
			if (b >= lastof(string) - (2 + 2 * 4)) break; // ", " and two calls to Utf8Encode()
 

	
 
			if (!first) b = strecpy(b, ", ", lastof(string));
 
			first = false;
 

	
 
			b = InlineString(b, GetCargo(cid)->name);
 
			b = InlineString(b, CargoSpec::Get(cid)->name);
 
		}
 
	}
 

	
 
	/* Terminate and display the completed string */
 
	*b = '\0';
 

	
 
	/* Make sure we detect any buffer overflow */
 
	assert(b < endof(string));
 

	
 
	SetDParamStr(0, string);
 
	return DrawStringMultiLine(left, right, y, INT32_MAX, STR_JUST_RAW_STRING);
 
}
0 comments (0 inline, 0 general)