(svn r7473) -Fix (r7269): Pass a cargo type to determine the freight weight
authorpeter1138
Sun, 10 Dec 2006 19:00:06 +0000
changeset 5316 b04421921eae
parent 5315 ce659994e392
child 5317 e235a3a573e3
(svn r7473) -Fix (r7269): Pass a cargo type to determine the freight weight
multiplier instead of a vehicle. Fixes incorrect display of total
train capacity.
train.h
train_cmd.c
train_gui.c
--- a/train.h	Sun Dec 10 15:28:11 2006 +0000
+++ b/train.h	Sun Dec 10 19:00:06 2006 +0000
@@ -222,6 +222,6 @@
 int CheckTrainInDepot(const Vehicle *v, bool needs_to_be_stopped);
 void CcCloneTrain(bool success, TileIndex tile, uint32 p1, uint32 p2);
 
-byte FreightWagonMult(const Vehicle *v);
+byte FreightWagonMult(CargoID cargo);
 
 #endif /* TRAIN_H */
--- a/train_cmd.c	Sun Dec 10 15:28:11 2006 +0000
+++ b/train_cmd.c	Sun Dec 10 19:00:06 2006 +0000
@@ -42,14 +42,13 @@
 
 
 /** Return the cargo weight multiplier to use for a rail vehicle
- * @param v Vehicle (wagon) to get multiplier for
+ * @param cargo Cargo type to get multiplier for
  * @return Cargo weight multiplier
  */
-byte FreightWagonMult(const Vehicle *v)
+byte FreightWagonMult(CargoID cargo)
 {
-	assert(v->type == VEH_Train);
 	// XXX NewCargos introduces a specific "is freight" flag for this test.
-	if (v->cargo_type == CT_PASSENGERS || v->cargo_type == CT_MAIL) return 1;
+	if (cargo == CT_PASSENGERS || cargo == CT_MAIL) return 1;
 	return _patches.freight_trains;
 }
 
@@ -66,7 +65,7 @@
 
 	for (u = v; u != NULL; u = u->next) {
 		const RailVehicleInfo *rvi = RailVehInfo(u->engine_type);
-		uint32 vweight = (_cargoc.weights[u->cargo_type] * u->cargo_count * FreightWagonMult(u)) / 16;
+		uint32 vweight = (_cargoc.weights[u->cargo_type] * u->cargo_count * FreightWagonMult(u->cargo_type)) / 16;
 
 		// Vehicle weight is not added for articulated parts.
 		if (!IsArticulatedPart(u)) {
--- a/train_gui.c	Sun Dec 10 15:28:11 2006 +0000
+++ b/train_gui.c	Sun Dec 10 19:00:06 2006 +0000
@@ -844,7 +844,7 @@
 			SetDParam(1, num);
 			SetDParam(2, v->cargo_source);
 			SetDParam(3, _patches.freight_trains);
-			str = FreightWagonMult(v) > 1 ? STR_FROM_MULT : STR_8813_FROM;
+			str = FreightWagonMult(v->cargo_type) > 1 ? STR_FROM_MULT : STR_8813_FROM;
 		}
 		DrawString(x, y, str, 0);
 	}
@@ -870,7 +870,7 @@
 		SetDParam(0, v->cargo_type);
 		SetDParam(1, v->cargo_cap);
 		SetDParam(2, _patches.freight_trains);
-		DrawString(x, y, FreightWagonMult(v) > 1 ? STR_CAPACITY_MULT : STR_013F_CAPACITY, 0);
+		DrawString(x, y, FreightWagonMult(v->cargo_type) > 1 ? STR_CAPACITY_MULT : STR_013F_CAPACITY, 0);
 	}
 }
 
@@ -1008,7 +1008,7 @@
 				SetDParam(2, i);            // {SHORTCARGO} #1
 				SetDParam(3, max_cargo[i]); // {SHORTCARGO} #2
 				SetDParam(4, _patches.freight_trains);
-				DrawString(x, y + 2, FreightWagonMult(v) > 1 ? STR_TOTAL_CAPACITY_MULT : STR_013F_TOTAL_CAPACITY, 0);
+				DrawString(x, y + 2, FreightWagonMult(i) > 1 ? STR_TOTAL_CAPACITY_MULT : STR_013F_TOTAL_CAPACITY, 0);
 			}
 		}
 	}