changeset 14965:8616df9ca587 draft

(svn r19573) -Fix (r19541): Special cargos did not appear at the refit list.
author terkhen <terkhen@openttd.org>
date Wed, 07 Apr 2010 14:17:29 +0000
parents 0fc8317971e8
children c2e2c495370e
files src/build_vehicle_gui.cpp src/cargotype.cpp src/cargotype.h src/graph_gui.cpp src/station_gui.cpp
diffstat 5 files changed, 25 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -854,7 +854,7 @@
 
 		/* Collect available cargo types for filtering. */
 		const CargoSpec *cs;
-		FOR_ALL_SORTED_CARGOSPECS(cs) {
+		FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
 			this->cargo_filter[filter_items] = cs->Index();
 			this->cargo_filter_texts[filter_items] = cs->name;
 			filter_items++;
--- a/src/cargotype.cpp
+++ b/src/cargotype.cpp
@@ -116,7 +116,9 @@
 }
 
 const CargoSpec *_sorted_cargo_specs[NUM_CARGO]; ///< Cargo specifications sorted alphabetically by name.
-uint8 _sorted_cargo_specs_size;                  ///< Number of cargo specifications stored at the _sorted_cargo_specs array.
+uint8 _sorted_cargo_specs_size;                  ///< Number of cargo specifications stored at the _sorted_cargo_specs array (including special cargos).
+uint8 _sorted_standard_cargo_specs_size;         ///< Number of standard cargo specifications stored at the _sorted_cargo_specs array.
+
 
 /** Sort cargo specifications by their name. */
 static int CDECL CargoSpecNameSorter(const CargoSpec * const *a, const CargoSpec * const *b)
@@ -140,7 +142,10 @@
 	if (res == 0) {
 		res = ((*b)->classes & CC_MAIL) - ((*a)->classes & CC_MAIL);
 		if (res == 0) {
-			return CargoSpecNameSorter(a, b);
+			res = ((*a)->classes & CC_SPECIAL) - ((*b)->classes & CC_SPECIAL);
+			if (res == 0) {
+				return CargoSpecNameSorter(a, b);
+			}
 		}
 	}
 
@@ -151,15 +156,20 @@
 void InitializeSortedCargoSpecs()
 {
 	_sorted_cargo_specs_size = 0;
-	CargoSpec *cargo;
+	const CargoSpec *cargo;
 	/* Add each cargo spec to the list. */
 	FOR_ALL_CARGOSPECS(cargo) {
-		if ((cargo->classes & CC_SPECIAL) != 0) continue; // Exclude fake cargo types.
 		_sorted_cargo_specs[_sorted_cargo_specs_size] = cargo;
 		_sorted_cargo_specs_size++;
 	}
 
 	/* Sort cargo specifications by cargo class and name. */
 	QSortT(_sorted_cargo_specs, _sorted_cargo_specs_size, &CargoSpecClassSorter);
+
+	_sorted_standard_cargo_specs_size = 0;
+	FOR_ALL_SORTED_CARGOSPECS(cargo) {
+		if (cargo->classes & CC_SPECIAL) break;
+		_sorted_standard_cargo_specs_size++;
+	}
 }
 
--- a/src/cargotype.h
+++ b/src/cargotype.h
@@ -134,6 +134,7 @@
 void InitializeSortedCargoSpecs();
 extern const CargoSpec *_sorted_cargo_specs[NUM_CARGO];
 extern uint8 _sorted_cargo_specs_size;
+extern uint8 _sorted_standard_cargo_specs_size;
 
 /** Does cargo \a c have cargo class \a cc?
  * @param c  Cargo type.
@@ -151,4 +152,6 @@
 
 #define FOR_ALL_SORTED_CARGOSPECS(var) for (uint8 index = 0; var = _sorted_cargo_specs[index], index < _sorted_cargo_specs_size; index++)
 
+#define FOR_ALL_SORTED_STANDARD_CARGOSPECS(var) for (uint8 index = 0; var = _sorted_cargo_specs[index], index < _sorted_standard_cargo_specs_size; index++)
+
 #endif /* CARGOTYPE_H */
--- a/src/graph_gui.cpp
+++ b/src/graph_gui.cpp
@@ -851,7 +851,7 @@
 
 		int i = 0;
 		const CargoSpec *cs;
-		FOR_ALL_SORTED_CARGOSPECS(cs) {
+		FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
 			if (HasBit(_legend_excluded_cargo, cs->Index())) SetBit(this->excluded_data, i);
 			i++;
 		}
@@ -859,7 +859,7 @@
 
 	void UpdateLoweredWidgets()
 	{
-		for (int i = 0; i < _sorted_cargo_specs_size; i++) {
+		for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) {
 			this->SetWidgetLoweredState(CPW_CARGO_FIRST + i, !HasBit(this->excluded_data, i));
 		}
 	}
@@ -924,7 +924,7 @@
 				/* Add all cargos to the excluded lists. */
 				int i = 0;
 				const CargoSpec *cs;
-				FOR_ALL_SORTED_CARGOSPECS(cs) {
+				FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
 					SetBit(_legend_excluded_cargo, cs->Index());
 					SetBit(this->excluded_data, i);
 					i++;
@@ -962,7 +962,7 @@
 
 		int i = 0;
 		const CargoSpec *cs;
-		FOR_ALL_SORTED_CARGOSPECS(cs) {
+		FOR_ALL_SORTED_STANDARD_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, cs->Index());
@@ -978,14 +978,14 @@
 {
 	NWidgetVertical *ver = new NWidgetVertical;
 
-	for (int i = 0; i < _sorted_cargo_specs_size; i++) {
+	for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) {
 		NWidgetBackground *leaf = new NWidgetBackground(WWT_PANEL, COLOUR_ORANGE, CPW_CARGO_FIRST + i, NULL);
 		leaf->tool_tip = STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO;
 		leaf->SetFill(1, 0);
 		leaf->SetLowered(true);
 		ver->Add(leaf);
 	}
-	*biggest_index = CPW_CARGO_FIRST + _sorted_cargo_specs_size - 1;
+	*biggest_index = CPW_CARGO_FIRST + _sorted_standard_cargo_specs_size - 1;
 	return ver;
 }
 
--- a/src/station_gui.cpp
+++ b/src/station_gui.cpp
@@ -1128,7 +1128,7 @@
 		y += FONT_HEIGHT_NORMAL;
 
 		const CargoSpec *cs;
-		FOR_ALL_SORTED_CARGOSPECS(cs) {
+		FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
 			const GoodsEntry *ge = &st->goods[cs->Index()];
 			if (!HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP)) continue;