Changeset - r15889:68e9eadf2026
[Not reviewed]
master
0 1 0
rubidium - 14 years ago 2010-08-20 17:35:10
rubidium@openttd.org
(svn r20582) -Fix [FS#4044]: Autoreplace can trigger an assertion when at the vehicle limit
1 file changed with 5 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/train_cmd.cpp
Show inline comments
 
@@ -1050,24 +1050,25 @@ static CommandCost CheckTrainAttachment(
 
 * Validate whether we are going to create valid trains.
 
 * @note All vehicles are/were 'heads' of their chains.
 
 * @param original_dst The original destination chain.
 
 * @param dst          The destination chain after constructing the train.
 
 * @param original_dst The original source chain.
 
 * @param dst          The source chain after constructing the train.
 
 * @param check_limit  Whether to check the vehicle limit.
 
 * @return possible error of this command.
 
 */
 
static CommandCost ValidateTrains(Train *original_dst, Train *dst, Train *original_src, Train *src)
 
static CommandCost ValidateTrains(Train *original_dst, Train *dst, Train *original_src, Train *src, bool check_limit)
 
{
 
	/* Check whether we may actually construct the trains. */
 
	CommandCost ret = CheckTrainAttachment(src);
 
	if (ret.Failed()) return ret;
 
	ret = CheckTrainAttachment(dst);
 
	if (ret.Failed()) return ret;
 

	
 
	/* Check whether we need to build a new train. */
 
	return CheckNewTrain(original_dst, dst, original_src, src);
 
	return check_limit ? CheckNewTrain(original_dst, dst, original_src, src) : CommandCost();
 
}
 

	
 
/**
 
 * Arrange the trains in the wanted way.
 
 * @param dst_head   The destination chain of the to be moved vehicle.
 
 * @param dst        The destination for the to be moved vehicle.
 
@@ -1232,13 +1233,13 @@ CommandCost CmdMoveRailVehicle(TileIndex
 
	ArrangeTrains(&dst_head, dst, &src_head, src, move_chain);
 

	
 
	if ((flags & DC_AUTOREPLACE) == 0) {
 
		/* If the autoreplace flag is set we do not need to test for the validity
 
		 * because we are going to revert the train to its original state. As we
 
		 * assume the original state was correct autoreplace can skip this. */
 
		CommandCost ret = ValidateTrains(original_dst_head, dst_head, original_src_head, src_head);
 
		CommandCost ret = ValidateTrains(original_dst_head, dst_head, original_src_head, src_head, true);
 
		if (ret.Failed()) {
 
			/* Restore the train we had. */
 
			RestoreTrainBackup(original_src);
 
			RestoreTrainBackup(original_dst);
 
			return ret;
 
		}
 
@@ -1352,13 +1353,13 @@ CommandCost CmdSellRailWagon(DoCommandFl
 
	Train *sell_head = NULL;
 

	
 
	/* Split the train in the wanted way. */
 
	ArrangeTrains(&sell_head, NULL, &new_head, v, sell_chain);
 

	
 
	/* We don't need to validate the second train; it's going to be sold. */
 
	CommandCost ret = ValidateTrains(NULL, NULL, first, new_head);
 
	CommandCost ret = ValidateTrains(NULL, NULL, first, new_head, (flags & DC_AUTOREPLACE) == 0);
 
	if (ret.Failed()) {
 
		/* Restore the train we had. */
 
		RestoreTrainBackup(original);
 
		return ret;
 
	}
 

	
0 comments (0 inline, 0 general)