(svn r8878) -Fix
authortron
Sat, 24 Feb 2007 14:36:14 +0000
changeset 6462 f57392bee868
parent 6461 20d2c1168b9e
child 6463 cc9e4a024b61
(svn r8878) -Fix

-Fix: Do a better job when checking the parameters of CmdMoveRailVehicle()
NOTE: 0.5 candidate
src/train_cmd.cpp
--- a/src/train_cmd.cpp	Sat Feb 24 12:50:05 2007 +0000
+++ b/src/train_cmd.cpp	Sat Feb 24 14:36:14 2007 +0000
@@ -1007,13 +1007,15 @@
 
 	src = GetVehicle(s);
 
-	if (src->type != VEH_Train) return CMD_ERROR;
+	if (src->type != VEH_Train || !CheckOwnership(src->owner)) return CMD_ERROR;
 
 	// if nothing is selected as destination, try and find a matching vehicle to drag to.
 	if (d == INVALID_VEHICLE) {
 		dst = IsTrainEngine(src) ? NULL : FindGoodVehiclePos(src);
 	} else {
+		if (!IsValidVehicleID(d)) return CMD_ERROR;
 		dst = GetVehicle(d);
+		if (dst->type != VEH_Train || !CheckOwnership(dst->owner)) return CMD_ERROR;
 	}
 
 	// if an articulated part is being handled, deal with its parent vehicle
@@ -1025,17 +1027,15 @@
 	// don't move the same vehicle..
 	if (src == dst) return 0;
 
-	/* the player must be the owner */
-	if (!CheckOwnership(src->owner) || (dst != NULL && !CheckOwnership(dst->owner)))
-		return CMD_ERROR;
-
 	/* locate the head of the two chains */
 	src_head = GetFirstVehicleInChain(src);
-	dst_head = NULL;
 	if (dst != NULL) {
 		dst_head = GetFirstVehicleInChain(dst);
+		if (dst_head->tile != src_head->tile) return CMD_ERROR;
 		// Now deal with articulated part of destination wagon
 		dst = GetLastEnginePart(dst);
+	} else {
+		dst_head = NULL;
 	}
 
 	if (dst != NULL && IsMultiheaded(dst) && !IsTrainEngine(dst) && IsTrainWagon(src)) {
@@ -1092,8 +1092,6 @@
 				// check if all vehicles in the dest train are stopped.
 				dst_len = CheckTrainStoppedInDepot(dst_head);
 				if (dst_len < 0) return_cmd_error(STR_881A_TRAINS_CAN_ONLY_BE_ALTERED);
-
-				assert(dst_head->tile == src_head->tile);
 			}
 
 			// We are moving between rows, so only count the wagons from the source