1061 Vehicle *orig_tail = dst_tail; |
1061 Vehicle *orig_tail = dst_tail; |
1062 Vehicle *next_to_attach = src; |
1062 Vehicle *next_to_attach = src; |
1063 Vehicle *src_previous = src->Previous(); |
1063 Vehicle *src_previous = src->Previous(); |
1064 |
1064 |
1065 while (next_to_attach != NULL) { |
1065 while (next_to_attach != NULL) { |
|
1066 /* Back up and clear the first_engine data to avoid using wagon override group */ |
|
1067 EngineID first_engine = next_to_attach->u.rail.first_engine; |
|
1068 next_to_attach->u.rail.first_engine = INVALID_ENGINE; |
|
1069 |
1066 uint16 callback = GetVehicleCallbackParent(CBID_TRAIN_ALLOW_WAGON_ATTACH, 0, 0, dst_head->engine_type, next_to_attach, dst_head); |
1070 uint16 callback = GetVehicleCallbackParent(CBID_TRAIN_ALLOW_WAGON_ATTACH, 0, 0, dst_head->engine_type, next_to_attach, dst_head); |
|
1071 |
|
1072 /* Restore original first_engine data */ |
|
1073 next_to_attach->u.rail.first_engine = first_engine; |
|
1074 |
1067 if (callback != CALLBACK_FAILED) { |
1075 if (callback != CALLBACK_FAILED) { |
1068 StringID error = STR_NULL; |
1076 StringID error = STR_NULL; |
1069 |
1077 |
1070 if (callback == 0xFD) error = STR_INCOMPATIBLE_RAIL_TYPES; |
1078 if (callback == 0xFD) error = STR_INCOMPATIBLE_RAIL_TYPES; |
1071 if (callback < 0xFD) error = GetGRFStringID(GetEngineGRFID(dst_head->engine_type), 0xD000 + callback); |
1079 if (callback < 0xFD) error = GetGRFStringID(GetEngineGRFID(dst_head->engine_type), 0xD000 + callback); |
1085 if (src_previous != NULL) src_previous->SetNext(src); |
1093 if (src_previous != NULL) src_previous->SetNext(src); |
1086 |
1094 |
1087 return_cmd_error(error); |
1095 return_cmd_error(error); |
1088 } |
1096 } |
1089 } |
1097 } |
|
1098 |
|
1099 /* Only check further wagons if told to move the chain */ |
|
1100 if (!HasBit(p2, 0)) break; |
1090 |
1101 |
1091 /* |
1102 /* |
1092 * Adding a next wagon to the chain so we can test the other wagons. |
1103 * Adding a next wagon to the chain so we can test the other wagons. |
1093 * First 'take' the first wagon from 'next_to_attach' and move it |
1104 * First 'take' the first wagon from 'next_to_attach' and move it |
1094 * to the next wagon. Then add that to the tail of the destination |
1105 * to the next wagon. Then add that to the tail of the destination |