200 * sell the old engine in a moment |
200 * sell the old engine in a moment |
201 */ |
201 */ |
202 /* Get the vehicle in front of the one we move out */ |
202 /* Get the vehicle in front of the one we move out */ |
203 Vehicle *front = old_v->Previous(); |
203 Vehicle *front = old_v->Previous(); |
204 /* 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 */ |
204 /* 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 */ |
205 if (IsMultiheaded(front) && !IsTrainEngine(front)) front = front->Previous(); |
205 if (IsRearDualheaded(front)) front = front->Previous(); |
206 /* Now we move the old one out of the train */ |
206 /* Now we move the old one out of the train */ |
207 DoCommand(0, (INVALID_VEHICLE << 16) | old_v->index, 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE); |
207 DoCommand(0, (INVALID_VEHICLE << 16) | old_v->index, 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE); |
208 /* Add the new vehicle */ |
208 /* Add the new vehicle */ |
209 DoCommand(0, (front->index << 16) | new_v->index, 1, DC_EXEC, CMD_MOVE_RAIL_VEHICLE); |
209 DoCommand(0, (front->index << 16) | new_v->index, 1, DC_EXEC, CMD_MOVE_RAIL_VEHICLE); |
210 } else { |
210 } else { |
248 } else { // flags & DC_EXEC not set |
248 } else { // flags & DC_EXEC not set |
249 CommandCost tmp_move; |
249 CommandCost tmp_move; |
250 |
250 |
251 if (old_v->type == VEH_TRAIN && IsFrontEngine(old_v)) { |
251 if (old_v->type == VEH_TRAIN && IsFrontEngine(old_v)) { |
252 Vehicle *next_veh = GetNextVehicle(old_v); |
252 Vehicle *next_veh = GetNextVehicle(old_v); |
253 if (IsMultiheaded(next_veh) && !IsTrainEngine(next_veh)) next_veh = next_veh->Next(); // don't try to move the rear multiheaded engine |
253 if (IsRearDualheaded(next_veh)) next_veh = next_veh->Next(); // don't try to move the rear multiheaded engine |
254 if (next_veh != NULL) { |
254 if (next_veh != NULL) { |
255 /* Verify that the wagons can be placed on the engine in question. |
255 /* Verify that the wagons can be placed on the engine in question. |
256 * This is done by building an engine, test if the wagons can be added and then sell the test engine. */ |
256 * This is done by building an engine, test if the wagons can be added and then sell the test engine. */ |
257 DoCommand(old_v->tile, new_engine_type, 3, DC_EXEC, GetCmdBuildVeh(old_v)); |
257 DoCommand(old_v->tile, new_engine_type, 3, DC_EXEC, GetCmdBuildVeh(old_v)); |
258 Vehicle *temp = GetVehicle(_new_vehicle_id); |
258 Vehicle *temp = GetVehicle(_new_vehicle_id); |