diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index f7feb9d0a8..dd6fca40d0 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -278,11 +278,10 @@ void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height, int &xoff * @param tile tile of the depot where aircraft is built. * @param flags type of operation. * @param e the engine to build. - * @param data unused. * @param[out] ret the vehicle that has been built. * @return the cost of this operation or an error. */ -CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **ret) +CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine *e, Vehicle **ret) { const AircraftVehicleInfo *avi = &e->u.air; const Station *st = Station::GetByTile(tile); diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 44e30beab0..4bffca1b8d 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -264,11 +264,10 @@ void RoadVehUpdateCache(RoadVehicle *v, bool same_length) * @param tile tile of the depot where road vehicle is built. * @param flags type of operation. * @param e the engine to build. - * @param data unused. * @param[out] ret the vehicle that has been built. * @return the cost of this operation or an error. */ -CommandCost CmdBuildRoadVehicle(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **ret) +CommandCost CmdBuildRoadVehicle(TileIndex tile, DoCommandFlag flags, const Engine *e, Vehicle **ret) { /* Check that the vehicle can drive on the road in question */ RoadType rt = e->u.road.roadtype; diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index d87c89e38d..984369c518 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -1116,11 +1116,10 @@ void Ship::SetDestTile(TileIndex tile) * @param tile tile of the depot where ship is built. * @param flags type of operation. * @param e the engine to build. - * @param data unused. * @param[out] ret the vehicle that has been built. * @return the cost of this operation or an error. */ -CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **ret) +CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, const Engine *e, Vehicle **ret) { tile = GetShipDepotNorthTile(tile); if (flags & DC_EXEC) { diff --git a/src/train.h b/src/train.h index 80aa0bf966..cb269a1077 100644 --- a/src/train.h +++ b/src/train.h @@ -90,6 +90,7 @@ void CheckBreakdownFlags(Train *v); void GetTrainSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type); bool TrainOnCrossing(TileIndex tile); +void NormalizeTrainVehInDepot(const Train *u); inline int GetTrainRealisticBrakingTargetDecelerationLimit(int acceleration_type) { diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index be09565e9e..746ae5a0a7 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -1520,7 +1520,7 @@ static CommandCost CmdBuildRailWagon(TileIndex tile, DoCommandFlag flags, 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 && @@ -1576,11 +1576,10 @@ static void AddRearEngineToMultiheadedTrain(Train *v) * @param tile tile of the depot where rail-vehicle is built. * @param flags type of operation. * @param e the engine to build. - * @param data bit 0 prevents any free cars from being added to the train. * @param[out] ret the vehicle that has been built. * @return the cost of this operation or an error. */ -CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **ret) +CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, const Engine *e, Vehicle **ret) { const RailVehicleInfo *rvi = &e->u.rail; @@ -1652,10 +1651,6 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, const Engin v->ConsistChanged(CCF_ARRANGE); UpdateTrainGroupID(v); - if (!HasBit(data, 0) && !(flags & DC_AUTOREPLACE)) { // check if the cars should be added to the new vehicle - NormalizeTrainVehInDepot(v); - } - CheckConsistencyOfArticulatedVehicle(v); InvalidateVehicleTickCaches(); diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index b549a246f9..9eaa65142c 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -72,10 +72,10 @@ const uint32 _send_to_depot_proc_table[] = { }; -CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v); -CommandCost CmdBuildRoadVehicle(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v); -CommandCost CmdBuildShip (TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v); -CommandCost CmdBuildAircraft (TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v); +CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, const Engine *e, Vehicle **v); +CommandCost CmdBuildRoadVehicle(TileIndex tile, DoCommandFlag flags, const Engine *e, Vehicle **v); +CommandCost CmdBuildShip (TileIndex tile, DoCommandFlag flags, const Engine *e, Vehicle **v); +CommandCost CmdBuildAircraft (TileIndex tile, DoCommandFlag flags, const Engine *e, Vehicle **v); static CommandCost GetRefitCost(const Vehicle *v, EngineID engine_type, CargoID new_cid, byte new_subtype, bool *auto_refit_allowed); /** @@ -84,7 +84,9 @@ static CommandCost GetRefitCost(const Vehicle *v, EngineID engine_type, CargoID * @param flags for command * @param p1 various bitstuffed data * bits 0-15: vehicle type being built. - * bits 16-23: vehicle type specific bits passed on to the vehicle build functions. + * bits 16-23: vehicle type specific bits. + * Trains: + * * bit 16: prevent any free cars from being added to the train. * bits 24-31: refit cargo type. * @param p2 User * @param text unused @@ -149,10 +151,10 @@ CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint Vehicle *v = nullptr; switch (type) { - case VEH_TRAIN: value.AddCost(CmdBuildRailVehicle(tile, subflags, e, GB(p1, 16, 8), &v)); break; - case VEH_ROAD: value.AddCost(CmdBuildRoadVehicle(tile, subflags, e, GB(p1, 16, 8), &v)); break; - case VEH_SHIP: value.AddCost(CmdBuildShip (tile, subflags, e, GB(p1, 16, 8), &v)); break; - case VEH_AIRCRAFT: value.AddCost(CmdBuildAircraft (tile, subflags, e, GB(p1, 16, 8), &v)); break; + case VEH_TRAIN: value.AddCost(CmdBuildRailVehicle(tile, subflags, e, &v)); break; + case VEH_ROAD: value.AddCost(CmdBuildRoadVehicle(tile, subflags, e, &v)); break; + case VEH_SHIP: value.AddCost(CmdBuildShip (tile, subflags, e, &v)); break; + case VEH_AIRCRAFT: value.AddCost(CmdBuildAircraft (tile, subflags, e, &v)); break; default: NOT_REACHED(); // Safe due to IsDepotTile() } @@ -180,6 +182,11 @@ CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint } if (flags & DC_EXEC) { + if (type == VEH_TRAIN && !HasBit(p1, 16) && !(flags & DC_AUTOREPLACE)) { + /* Move any free wagons to the new vehicle. */ + NormalizeTrainVehInDepot(Train::From(v)); + } + InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); InvalidateWindowClassesData(GetWindowClassForVehicleType(type), 0); InvalidateWindowClassesData(WC_DEPARTURES_BOARD, 0);