equal
deleted
inserted
replaced
1005 |
1005 |
1006 if (!IsValidVehicleID(s)) return CMD_ERROR; |
1006 if (!IsValidVehicleID(s)) return CMD_ERROR; |
1007 |
1007 |
1008 src = GetVehicle(s); |
1008 src = GetVehicle(s); |
1009 |
1009 |
1010 if (src->type != VEH_Train) return CMD_ERROR; |
1010 if (src->type != VEH_Train || !CheckOwnership(src->owner)) return CMD_ERROR; |
1011 |
1011 |
1012 // if nothing is selected as destination, try and find a matching vehicle to drag to. |
1012 // if nothing is selected as destination, try and find a matching vehicle to drag to. |
1013 if (d == INVALID_VEHICLE) { |
1013 if (d == INVALID_VEHICLE) { |
1014 dst = IsTrainEngine(src) ? NULL : FindGoodVehiclePos(src); |
1014 dst = IsTrainEngine(src) ? NULL : FindGoodVehiclePos(src); |
1015 } else { |
1015 } else { |
|
1016 if (!IsValidVehicleID(d)) return CMD_ERROR; |
1016 dst = GetVehicle(d); |
1017 dst = GetVehicle(d); |
|
1018 if (dst->type != VEH_Train || !CheckOwnership(dst->owner)) return CMD_ERROR; |
1017 } |
1019 } |
1018 |
1020 |
1019 // if an articulated part is being handled, deal with its parent vehicle |
1021 // if an articulated part is being handled, deal with its parent vehicle |
1020 while (IsArticulatedPart(src)) src = GetPrevVehicleInChain(src); |
1022 while (IsArticulatedPart(src)) src = GetPrevVehicleInChain(src); |
1021 if (dst != NULL) { |
1023 if (dst != NULL) { |
1023 } |
1025 } |
1024 |
1026 |
1025 // don't move the same vehicle.. |
1027 // don't move the same vehicle.. |
1026 if (src == dst) return 0; |
1028 if (src == dst) return 0; |
1027 |
1029 |
1028 /* the player must be the owner */ |
|
1029 if (!CheckOwnership(src->owner) || (dst != NULL && !CheckOwnership(dst->owner))) |
|
1030 return CMD_ERROR; |
|
1031 |
|
1032 /* locate the head of the two chains */ |
1030 /* locate the head of the two chains */ |
1033 src_head = GetFirstVehicleInChain(src); |
1031 src_head = GetFirstVehicleInChain(src); |
1034 dst_head = NULL; |
|
1035 if (dst != NULL) { |
1032 if (dst != NULL) { |
1036 dst_head = GetFirstVehicleInChain(dst); |
1033 dst_head = GetFirstVehicleInChain(dst); |
|
1034 if (dst_head->tile != src_head->tile) return CMD_ERROR; |
1037 // Now deal with articulated part of destination wagon |
1035 // Now deal with articulated part of destination wagon |
1038 dst = GetLastEnginePart(dst); |
1036 dst = GetLastEnginePart(dst); |
|
1037 } else { |
|
1038 dst_head = NULL; |
1039 } |
1039 } |
1040 |
1040 |
1041 if (dst != NULL && IsMultiheaded(dst) && !IsTrainEngine(dst) && IsTrainWagon(src)) { |
1041 if (dst != NULL && IsMultiheaded(dst) && !IsTrainEngine(dst) && IsTrainWagon(src)) { |
1042 /* We are moving a wagon to the rear part of a multiheaded engine */ |
1042 /* We are moving a wagon to the rear part of a multiheaded engine */ |
1043 if (dst->next == NULL) { |
1043 if (dst->next == NULL) { |
1090 |
1090 |
1091 if (dst_head != NULL) { |
1091 if (dst_head != NULL) { |
1092 // check if all vehicles in the dest train are stopped. |
1092 // check if all vehicles in the dest train are stopped. |
1093 dst_len = CheckTrainStoppedInDepot(dst_head); |
1093 dst_len = CheckTrainStoppedInDepot(dst_head); |
1094 if (dst_len < 0) return_cmd_error(STR_881A_TRAINS_CAN_ONLY_BE_ALTERED); |
1094 if (dst_len < 0) return_cmd_error(STR_881A_TRAINS_CAN_ONLY_BE_ALTERED); |
1095 |
|
1096 assert(dst_head->tile == src_head->tile); |
|
1097 } |
1095 } |
1098 |
1096 |
1099 // We are moving between rows, so only count the wagons from the source |
1097 // We are moving between rows, so only count the wagons from the source |
1100 // row that are being moved. |
1098 // row that are being moved. |
1101 if (HASBIT(p2, 0)) { |
1099 if (HASBIT(p2, 0)) { |