Changeset - r14926:3d9a47be1c5a
[Not reviewed]
master
0 3 0
terkhen - 14 years ago 2010-04-02 12:20:41
terkhen@openttd.org
(svn r19539) -Codechange: Use a macro to loop through the list of sorted cargo specifications.
3 files changed with 17 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -844,27 +844,28 @@ struct BuildVehicleWindow : Window {
 
		this->cargo_filter_texts[filter_items] = STR_PURCHASE_INFO_ALL_TYPES;
 
		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 (this->vehicle_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 (int i = 0; i < _sorted_cargo_specs_size; i++) {
 
			this->cargo_filter[filter_items] = _sorted_cargo_specs[i]->Index();
 
			this->cargo_filter_texts[filter_items] = _sorted_cargo_specs[i]->name;
 
		const CargoSpec *cs;
 
		FOR_ALL_SORTED_CARGOSPECS(cs) {
 
			this->cargo_filter[filter_items] = cs->Index();
 
			this->cargo_filter_texts[filter_items] = cs->name;
 
			filter_items++;
 
		}
 

	
 
		/* Terminate the filter list. */
 
		this->cargo_filter_texts[filter_items] = INVALID_STRING_ID;
 

	
 
		/* If not found, the cargo criteria will be set to all cargos. */
 
		this->cargo_filter_criteria = 0;
 

	
 
		/* Find the last cargo filter criteria. */
 
		for (uint i = 0; i < filter_items; i++) {
 
			if (this->cargo_filter[i] == _last_filter_criteria[this->vehicle_type]) {
src/cargotype.h
Show inline comments
 
@@ -140,13 +140,15 @@ extern uint8 _sorted_cargo_specs_size;
 
 * @param cc Cargo class.
 
 * @return The type fits in the class.
 
 */
 
static inline bool IsCargoInClass(CargoID c, CargoClass cc)
 
{
 
	return (CargoSpec::Get(c)->classes & cc) != 0;
 
}
 

	
 
#define FOR_ALL_CARGOSPECS_FROM(var, start) for (size_t cargospec_index = start; var = NULL, cargospec_index < CargoSpec::GetArraySize(); cargospec_index++) \
 
		if ((var = CargoSpec::Get(cargospec_index))->IsValid())
 
#define FOR_ALL_CARGOSPECS(var) FOR_ALL_CARGOSPECS_FROM(var, 0)
 

	
 
#define FOR_ALL_SORTED_CARGOSPECS(var) for (uint8 index = 0; var = _sorted_cargo_specs[index], index < _sorted_cargo_specs_size; index++)
 

	
 
#endif /* CARGOTYPE_H */
src/graph_gui.cpp
Show inline comments
 
@@ -836,26 +836,29 @@ struct PaymentRatesGraphWindow : BaseGra
 
		if (!this->first_init) {
 
			/* Initialise the dataset */
 
			this->OnHundredthTick();
 
			this->UpdateLoweredWidgets();
 
		}
 
		this->first_init = false;
 
	}
 

	
 
	void UpdateExcludedData()
 
	{
 
		this->excluded_data = 0;
 

	
 
		for (int i = 0; i < _sorted_cargo_specs_size; i++) {
 
			if (HasBit(_legend_excluded_cargo, _sorted_cargo_specs[i]->Index())) SetBit(this->excluded_data, i);
 
		int i = 0;
 
		const CargoSpec *cs;
 
		FOR_ALL_SORTED_CARGOSPECS(cs) {
 
			if (HasBit(_legend_excluded_cargo, cs->Index())) SetBit(this->excluded_data, i);
 
			i++;
 
		}
 
	}
 

	
 
	void UpdateLoweredWidgets()
 
	{
 
		for (int i = 0; i < _sorted_cargo_specs_size; i++) {
 
			this->SetWidgetLoweredState(CPW_CARGO_FIRST + i, !HasBit(this->excluded_data, i));
 
		}
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
	{
 
@@ -910,30 +913,32 @@ struct PaymentRatesGraphWindow : BaseGra
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	{
 
		/* Override default OnTick */
 
	}
 

	
 
	virtual void OnHundredthTick()
 
	{
 
		this->UpdateExcludedData();
 

	
 
		int i;
 
		for (i = 0; i < _sorted_cargo_specs_size; i++) {
 
			this->colours[i] = _sorted_cargo_specs[i]->legend_colour;
 
		int i = 0;
 
		const CargoSpec *cs;
 
		FOR_ALL_SORTED_CARGOSPECS(cs) {
 
			this->colours[i] = cs->legend_colour;
 
			for (uint j = 0; j != 20; j++) {
 
				this->cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 4 + 4, _sorted_cargo_specs[i]->Index());
 
				this->cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 4 + 4, cs->Index());
 
			}
 
			i++;
 
		}
 
		this->num_dataset = i;
 
	}
 
};
 

	
 
/** Construct the row containing the digit keys. */
 
static NWidgetBase *MakeCargoButtons(int *biggest_index)
 
{
 
	NWidgetVertical *ver = new NWidgetVertical;
 

	
 
	for (int i = 0; i < _sorted_cargo_specs_size; i++) {
 
		NWidgetBackground *leaf = new NWidgetBackground(WWT_PANEL, COLOUR_ORANGE, CPW_CARGO_FIRST + i, NULL);
0 comments (0 inline, 0 general)