|
@@ -1193,25 +1193,25 @@ CommandCost CmdMoveRailVehicle(DoCommand
|
|
|
|
|
|
/* Do not allow moving crashed vehicles inside the depot, it is likely to cause asserts later */
|
|
|
if (src->vehstatus & VS_CRASHED) return CMD_ERROR;
|
|
|
|
|
|
/* if nothing is selected as destination, try and find a matching vehicle to drag to. */
|
|
|
Train *dst;
|
|
|
if (dest_veh == INVALID_VEHICLE) {
|
|
|
dst = (src->IsEngine() || (flags & DC_AUTOREPLACE)) ? nullptr : FindGoodVehiclePos(src);
|
|
|
} else {
|
|
|
dst = Train::GetIfValid(dest_veh);
|
|
|
if (dst == nullptr) return CMD_ERROR;
|
|
|
|
|
|
CommandCost ret = CheckOwnership(dst->owner);
|
|
|
ret = CheckOwnership(dst->owner);
|
|
|
if (ret.Failed()) return ret;
|
|
|
|
|
|
/* Do not allow appending to crashed vehicles, too */
|
|
|
if (dst->vehstatus & VS_CRASHED) return CMD_ERROR;
|
|
|
}
|
|
|
|
|
|
/* if an articulated part is being handled, deal with its parent vehicle */
|
|
|
src = src->GetFirstEnginePart();
|
|
|
if (dst != nullptr) {
|
|
|
dst = dst->GetFirstEnginePart();
|
|
|
}
|
|
|
|
|
@@ -1262,25 +1262,25 @@ CommandCost CmdMoveRailVehicle(DoCommand
|
|
|
* original_src_head can't be nullptr; src is by definition != nullptr, so src_head can't be nullptr as
|
|
|
* src->GetFirst() always yields non-nullptr, so eventually original_src_head != nullptr as well. */
|
|
|
bool original_src_head_front_engine = original_src_head->IsFrontEngine();
|
|
|
bool original_dst_head_front_engine = original_dst_head != nullptr && original_dst_head->IsFrontEngine();
|
|
|
|
|
|
/* (Re)arrange the trains in the wanted arrangement. */
|
|
|
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, true);
|
|
|
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;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/* do it? */
|
|
|
if (flags & DC_EXEC) {
|
|
|
/* Remove old heads from the statistics */
|
|
|
if (original_src_head_front_engine) GroupStatistics::CountVehicle(original_src_head, -1);
|