1163 Vehicle *orig_tail = dst_tail; |
1163 Vehicle *orig_tail = dst_tail; |
1164 Vehicle *next_to_attach = src; |
1164 Vehicle *next_to_attach = src; |
1165 Vehicle *src_previous = src->Previous(); |
1165 Vehicle *src_previous = src->Previous(); |
1166 |
1166 |
1167 while (next_to_attach != NULL) { |
1167 while (next_to_attach != NULL) { |
1168 /* Back up and clear the first_engine data to avoid using wagon override group */ |
1168 /* Don't check callback for articulated or rear dual headed parts */ |
1169 EngineID first_engine = next_to_attach->u.rail.first_engine; |
1169 if (!IsArticulatedPart(next_to_attach) && !IsRearDualheaded(next_to_attach)) { |
1170 next_to_attach->u.rail.first_engine = INVALID_ENGINE; |
1170 /* Back up and clear the first_engine data to avoid using wagon override group */ |
1171 |
1171 EngineID first_engine = next_to_attach->u.rail.first_engine; |
1172 uint16 callback = GetVehicleCallbackParent(CBID_TRAIN_ALLOW_WAGON_ATTACH, 0, 0, dst_head->engine_type, next_to_attach, dst_head); |
1172 next_to_attach->u.rail.first_engine = INVALID_ENGINE; |
1173 |
1173 |
1174 /* Restore original first_engine data */ |
1174 uint16 callback = GetVehicleCallbackParent(CBID_TRAIN_ALLOW_WAGON_ATTACH, 0, 0, dst_head->engine_type, next_to_attach, dst_head); |
1175 next_to_attach->u.rail.first_engine = first_engine; |
1175 |
1176 |
1176 /* Restore original first_engine data */ |
1177 if (callback != CALLBACK_FAILED) { |
1177 next_to_attach->u.rail.first_engine = first_engine; |
1178 StringID error = STR_NULL; |
1178 |
1179 |
1179 if (callback != CALLBACK_FAILED) { |
1180 if (callback == 0xFD) error = STR_INCOMPATIBLE_RAIL_TYPES; |
1180 StringID error = STR_NULL; |
1181 if (callback < 0xFD) error = GetGRFStringID(GetEngineGRFID(dst_head->engine_type), 0xD000 + callback); |
1181 |
1182 |
1182 if (callback == 0xFD) error = STR_INCOMPATIBLE_RAIL_TYPES; |
1183 if (error != STR_NULL) { |
1183 if (callback < 0xFD) error = GetGRFStringID(GetEngineGRFID(dst_head->engine_type), 0xD000 + callback); |
1184 /* |
1184 |
1185 * The attaching is not allowed. In this case 'next_to_attach' |
1185 if (error != STR_NULL) { |
1186 * can contain some vehicles of the 'source' and the destination |
1186 /* |
1187 * train can have some too. We 'just' add the to-be added wagons |
1187 * The attaching is not allowed. In this case 'next_to_attach' |
1188 * to the chain and then split it where it was previously |
1188 * can contain some vehicles of the 'source' and the destination |
1189 * separated, i.e. the tail of the original destination train. |
1189 * train can have some too. We 'just' add the to-be added wagons |
1190 * Furthermore the 'previous' link of the original source vehicle needs |
1190 * to the chain and then split it where it was previously |
1191 * to be restored, otherwise the train goes missing in the depot. |
1191 * separated, i.e. the tail of the original destination train. |
1192 */ |
1192 * Furthermore the 'previous' link of the original source vehicle needs |
1193 dst_tail->SetNext(next_to_attach); |
1193 * to be restored, otherwise the train goes missing in the depot. |
1194 orig_tail->SetNext(NULL); |
1194 */ |
1195 if (src_previous != NULL) src_previous->SetNext(src); |
1195 dst_tail->SetNext(next_to_attach); |
1196 |
1196 orig_tail->SetNext(NULL); |
1197 return_cmd_error(error); |
1197 if (src_previous != NULL) src_previous->SetNext(src); |
|
1198 |
|
1199 return_cmd_error(error); |
|
1200 } |
1198 } |
1201 } |
1199 } |
1202 } |
1200 |
1203 |
1201 /* Only check further wagons if told to move the chain */ |
1204 /* Only check further wagons if told to move the chain */ |
1202 if (!HasBit(p2, 0)) break; |
1205 if (!HasBit(p2, 0)) break; |