Fix #10502: Refit engine before attaching free wagons. (#10926)

Caused by incorrect order of operations when buying a train engine with refit and attaching free wagons.
This commit is contained in:
PeterN
2023-06-04 15:57:36 +01:00
committed by GitHub
parent 87ccff16b5
commit ee2d0745e9
4 changed files with 10 additions and 9 deletions

View File

@@ -686,7 +686,7 @@ static CommandCost CmdBuildRailWagon(DoCommandFlag flags, TileIndex tile, const
}
/** Move all free vehicles in the depot to the train */
static void NormalizeTrainVehInDepot(const Train *u)
void NormalizeTrainVehInDepot(const Train *u)
{
for (const Train *v : Train::Iterate()) {
if (v->IsFreeWagon() && v->tile == u->tile &&
@@ -737,11 +737,10 @@ static void AddRearEngineToMultiheadedTrain(Train *v)
* @param flags type of operation.
* @param tile tile of the depot where rail-vehicle is built.
* @param e the engine to build.
* @param free_cars add any free cars to the train.
* @param[out] ret the vehicle that has been built.
* @return the cost of this operation or an error.
*/
CommandCost CmdBuildRailVehicle(DoCommandFlag flags, TileIndex tile, const Engine *e, bool free_cars, Vehicle **ret)
CommandCost CmdBuildRailVehicle(DoCommandFlag flags, TileIndex tile, const Engine *e, Vehicle **ret)
{
const RailVehicleInfo *rvi = &e->u.rail;
@@ -807,10 +806,6 @@ CommandCost CmdBuildRailVehicle(DoCommandFlag flags, TileIndex tile, const Engin
v->ConsistChanged(CCF_ARRANGE);
UpdateTrainGroupID(v);
if (free_cars && !(flags & DC_AUTOREPLACE)) { // check if the cars should be added to the new vehicle
NormalizeTrainVehInDepot(v);
}
CheckConsistencyOfArticulatedVehicle(v);
}