src/train_cmd.cpp
branchnoai
changeset 9476 1d1ed96f32ad
parent 9403 0a2377009af4
child 9517 be1775555bbd
--- a/src/train_cmd.cpp	Mon Mar 19 12:30:11 2007 +0000
+++ b/src/train_cmd.cpp	Mon Mar 19 12:49:27 2007 +0000
@@ -1334,30 +1334,37 @@
 				for (Vehicle *tmp = first; tmp != NULL; tmp = tmp->next) tmp->first = NULL;
 
 				/* 2.2 If there are wagons present after the deleted front engine, check
-         * if the second wagon (which will be first) is an engine. If it is one,
-         * promote it as a new train, retaining the unitnumber, orders */
-				if (new_f != NULL) {
-					if (IsTrainEngine(new_f)) {
-						switch_engine = true;
-						/* Copy important data from the front engine */
-						new_f->unitnumber = first->unitnumber;
-						new_f->current_order = first->current_order;
-						new_f->cur_order_index = first->cur_order_index;
-						new_f->orders = first->orders;
-						if (first->prev_shared != NULL) {
-							first->prev_shared->next_shared = new_f;
-							new_f->prev_shared = first->prev_shared;
-						}
-
-						if (first->next_shared != NULL) {
-							first->next_shared->prev_shared = new_f;
-							new_f->next_shared = first->next_shared;
-						}
-
-						new_f->num_orders = first->num_orders;
-						first->orders = NULL; // XXX - to not to delete the orders */
-						if (IsLocalPlayer()) ShowTrainViewWindow(new_f);
+				 * if the second wagon (which will be first) is an engine. If it is one,
+				 * promote it as a new train, retaining the unitnumber, orders */
+				if (new_f != NULL && IsTrainEngine(new_f)) {
+					switch_engine = true;
+					/* Copy important data from the front engine */
+					new_f->unitnumber      = first->unitnumber;
+					new_f->current_order   = first->current_order;
+					new_f->cur_order_index = first->cur_order_index;
+					new_f->orders          = first->orders;
+					new_f->num_orders      = first->num_orders;
+
+					if (first->prev_shared != NULL) {
+						first->prev_shared->next_shared = new_f;
+						new_f->prev_shared = first->prev_shared;
 					}
+
+					if (first->next_shared != NULL) {
+						first->next_shared->prev_shared = new_f;
+						new_f->next_shared = first->next_shared;
+					}
+
+					/*
+					 * Remove all order information from the front train, to
+					 * prevent the order and the shared order list to be
+					 * destroyed by Destroy/DeleteVehicle.
+					 */
+					first->orders      = NULL;
+					first->prev_shared = NULL;
+					first->next_shared = NULL;
+
+					if (IsLocalPlayer()) ShowTrainViewWindow(new_f);
 				}
 			}
 
@@ -1744,7 +1751,7 @@
 	if (CheckTrainStoppedInDepot(v) < 0) return_cmd_error(STR_TRAIN_MUST_BE_STOPPED);
 
 	/* Check cargo */
-	if (new_cid > NUM_CARGO) return CMD_ERROR;
+	if (new_cid >= NUM_CARGO) return CMD_ERROR;
 
 	SET_EXPENSES_TYPE(EXPENSES_TRAIN_RUN);
 
@@ -2808,7 +2815,7 @@
 {
 	uint num = 0;
 	BEGIN_ENUM_WAGONS(v)
-		if (v->cargo_type == CT_PASSENGERS) num += v->cargo_count;
+		if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) num += v->cargo_count;
 	END_ENUM_WAGONS(v)
 	return num;
 }