changeset 14936:58044b15c59e draft

(svn r19539) -Codechange: Use a macro to loop through the list of sorted cargo specifications.
author terkhen <terkhen@openttd.org>
date Fri, 02 Apr 2010 12:20:41 +0000
parents a64a273253c0
children 205fdbada4d7
files src/build_vehicle_gui.cpp src/cargotype.h src/graph_gui.cpp
diffstat 3 files changed, 17 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -853,9 +853,10 @@
 		}
 
 		/* 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++;
 		}
 
--- a/src/cargotype.h
+++ b/src/cargotype.h
@@ -149,4 +149,6 @@
 		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 */
--- a/src/graph_gui.cpp
+++ b/src/graph_gui.cpp
@@ -845,8 +845,11 @@
 	{
 		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++;
 		}
 	}
 
@@ -919,12 +922,14 @@
 	{
 		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;
 	}