173 |
173 |
174 if (flags & DC_EXEC) { |
174 if (flags & DC_EXEC) { |
175 new_v = GetVehicle(_new_vehicle_id); |
175 new_v = GetVehicle(_new_vehicle_id); |
176 *w = new_v; //we changed the vehicle, so MaybeReplaceVehicle needs to work on the new one. Now we tell it what the new one is |
176 *w = new_v; //we changed the vehicle, so MaybeReplaceVehicle needs to work on the new one. Now we tell it what the new one is |
177 |
177 |
178 new_v->group_id = old_v->group_id; |
|
179 /* refit if needed */ |
178 /* refit if needed */ |
180 if (replacement_cargo_type != CT_NO_REFIT) { |
179 if (replacement_cargo_type != CT_NO_REFIT) { |
181 if (CmdFailed(DoCommand(0, new_v->index, replacement_cargo_type, DC_EXEC, GetCmdRefitVeh(new_v)))) { |
180 if (CmdFailed(DoCommand(0, new_v->index, replacement_cargo_type, DC_EXEC, GetCmdRefitVeh(new_v)))) { |
182 /* Being here shows a failure, which most likely is in GetNewCargoTypeForReplace() or incorrect estimation costs */ |
181 /* Being here shows a failure, which most likely is in GetNewCargoTypeForReplace() or incorrect estimation costs */ |
183 error("Autoreplace failed to refit. Replace engine %d to %d and refit to cargo %d", old_v->engine_type, new_v->engine_type, replacement_cargo_type); |
182 error("Autoreplace failed to refit. Replace engine %d to %d and refit to cargo %d", old_v->engine_type, new_v->engine_type, replacement_cargo_type); |
203 new_v->cur_order_index = old_v->cur_order_index; |
202 new_v->cur_order_index = old_v->cur_order_index; |
204 ChangeVehicleViewWindow(old_v, new_v); |
203 ChangeVehicleViewWindow(old_v, new_v); |
205 new_v->profit_this_year = old_v->profit_this_year; |
204 new_v->profit_this_year = old_v->profit_this_year; |
206 new_v->profit_last_year = old_v->profit_last_year; |
205 new_v->profit_last_year = old_v->profit_last_year; |
207 new_v->service_interval = old_v->service_interval; |
206 new_v->service_interval = old_v->service_interval; |
208 new_v->group_id = old_v->group_id; |
207 DoCommand(0, old_v->group_id, new_v->index, flags, CMD_ADD_VEHICLE_GROUP); |
209 new_front = true; |
208 new_front = true; |
210 new_v->unitnumber = old_v->unitnumber; // use the same unit number |
209 new_v->unitnumber = old_v->unitnumber; // use the same unit number |
211 new_v->dest_tile = old_v->dest_tile; |
210 new_v->dest_tile = old_v->dest_tile; |
212 |
211 |
213 new_v->current_order = old_v->current_order; |
212 new_v->current_order = old_v->current_order; |