(svn r6690) - Fix (r6602): Translate global to per-climate cargo ids before... doing anything with them. (Thanks to MeusH for pointing this out...)
authorpeter1138
Sun, 08 Oct 2006 19:28:55 +0000
changeset 4776 f9c174047c5d
parent 4775 4e0daa957997
child 4777 7fb41edb3a6d
(svn r6690) - Fix (r6602): Translate global to per-climate cargo ids before... doing anything with them. (Thanks to MeusH for pointing this out...)
vehicle_gui.c
--- a/vehicle_gui.c	Sun Oct 08 17:56:08 2006 +0000
+++ b/vehicle_gui.c	Sun Oct 08 19:28:55 2006 +0000
@@ -216,9 +216,14 @@
 
 		/* Loop through all cargos in the refit mask */
 		for (cid = 0; cmask != 0 && num_lines < max_lines; cmask >>= 1, cid++) {
+			CargoID lcid;
+
 			/* Skip cargo type if it's not listed */
 			if (!HASBIT(cmask, 0)) continue;
 
+			lcid = _local_cargo_id_ctype[cid];
+			if (lcid == CT_INVALID) continue;
+
 			/* Check the vehicle's callback mask for cargo suffixes */
 			if (HASBIT(callbackmask, CBM_CARGO_SUFFIX)) {
 				/* Make a note of the original cargo type. It has to be
@@ -227,7 +232,7 @@
 				byte temp_subtype  = u->cargo_subtype;
 				byte refit_cyc;
 
-				u->cargo_type = cid;
+				u->cargo_type = lcid;
 
 				for (refit_cyc = 0; refit_cyc < 16 && num_lines < max_lines; refit_cyc++) {
 					bool duplicate = false;
@@ -241,12 +246,12 @@
 
 					/* Check if this cargo and subtype combination are listed */
 					for (i = 0; i < num_lines && !duplicate; i++) {
-						if (refit[i].cargo == cid && refit[i].value == callback) duplicate = true;
+						if (refit[i].cargo == lcid && refit[i].value == callback) duplicate = true;
 					}
 
 					if (duplicate) continue;
 
-					refit[num_lines].cargo   = cid;
+					refit[num_lines].cargo   = lcid;
 					refit[num_lines].subtype = refit_cyc;
 					refit[num_lines].value   = callback;
 					refit[num_lines].engine  = u->engine_type;
@@ -261,11 +266,11 @@
 				bool duplicate = false;
 
 				for (i = 0; i < num_lines && !duplicate; i++) {
-					if (refit[i].cargo == cid && refit[i].value == CALLBACK_FAILED) duplicate = true;
+					if (refit[i].cargo == lcid && refit[i].value == CALLBACK_FAILED) duplicate = true;
 				}
 
 				if (!duplicate) {
-					refit[num_lines].cargo   = cid;
+					refit[num_lines].cargo   = lcid;
 					refit[num_lines].subtype = 0;
 					refit[num_lines].value   = CALLBACK_FAILED;
 					refit[num_lines].engine  = INVALID_ENGINE;
@@ -306,7 +311,7 @@
 
 		if (i >= pos && i < pos + rows) {
 			/* Draw the cargo name */
-			int last_x = DrawString(2, y, _cargoc.names_s[_local_cargo_id_ctype[refit[i].cargo]], colour);
+			int last_x = DrawString(2, y, _cargoc.names_s[refit[i].cargo], colour);
 
 			/* If the callback succeeded, draw the cargo suffix */
 			if (refit[i].value != CALLBACK_FAILED) {