@@ -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);
/* 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);
RestoreTrainBackup(original);
Status change: