193 if (old_v->type == VEH_TRAIN && !IsFrontEngine(old_v)) { |
193 if (old_v->type == VEH_TRAIN && !IsFrontEngine(old_v)) { |
194 /* this is a railcar. We need to move the car into the train |
194 /* this is a railcar. We need to move the car into the train |
195 * We add the new engine after the old one instead of replacing it. It will give the same result anyway when we |
195 * We add the new engine after the old one instead of replacing it. It will give the same result anyway when we |
196 * sell the old engine in a moment |
196 * sell the old engine in a moment |
197 */ |
197 */ |
|
198 /* Get the vehicle in front of the one we move out */ |
198 Vehicle *front = GetPrevVehicleInChain(old_v); |
199 Vehicle *front = GetPrevVehicleInChain(old_v); |
|
200 /* If the vehicle in front is the rear end of a dualheaded engine, then we need to use the one in front of that one */ |
|
201 if (IsMultiheaded(front) && !IsTrainEngine(front)) front = GetPrevVehicleInChain(front); |
199 /* Now we move the old one out of the train */ |
202 /* Now we move the old one out of the train */ |
200 DoCommand(0, (INVALID_VEHICLE << 16) | old_v->index, 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE); |
203 DoCommand(0, (INVALID_VEHICLE << 16) | old_v->index, 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE); |
201 /* Add the new vehicle */ |
204 /* Add the new vehicle */ |
202 DoCommand(0, (front->index << 16) | new_v->index, 1, DC_EXEC, CMD_MOVE_RAIL_VEHICLE); |
205 DoCommand(0, (front->index << 16) | new_v->index, 1, DC_EXEC, CMD_MOVE_RAIL_VEHICLE); |
203 } else { |
206 } else { |