# HG changeset patch # User frosch # Date 1282325769 0 # Node ID f386e33cdd1ebdf32b17640d54dfc356bb1a89c8 # Parent 097904c36bdeec7d441599a71d6187254615085e (svn r20583) -Fix: Autoreplace failed while attaching non-replaced wagons to the new chain, if to-be-sold-engines would become front-engines and the unitnumber limit would be exceeded. diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -459,6 +459,7 @@ /* Append engines to the new chain * We do this from back to front, so that the head of the temporary vehicle chain does not change all the time. + * That way we also have less trouble when exceeding the unitnumber limit. * OTOH the vehicle attach callback is more expensive this way :s */ Train *last_engine = NULL; ///< Shall store the last engine unit after this step if (cost.Succeeded()) { @@ -467,6 +468,13 @@ if (RailVehInfo(append->engine_type)->railveh_type == RAILVEH_WAGON) continue; + if (new_vehs[i] != NULL) { + /* Move the old engine to a separate row with DC_AUTOREPLACE. Else + * moving the wagon in front may fail later due to unitnumber limit. + * (We have to attach wagons without DC_AUTOREPLACE.) */ + MoveVehicle(old_vehs[i], NULL, DC_EXEC | DC_AUTOREPLACE, false); + } + if (last_engine == NULL) last_engine = append; cost.AddCost(MoveVehicle(append, new_head, DC_EXEC, false)); if (cost.Failed()) break;