Fix #11307: Incorrect GroupStatistics after selling leading wagon

When this results in a countable consist
This commit is contained in:
Jonathan G Rennison
2023-09-17 17:40:32 +01:00
parent f5d1b1d8f8
commit cd2a368d77

View File

@@ -2334,18 +2334,20 @@ CommandCost CmdSellRailWagon(DoCommandFlag flags, Vehicle *t, uint16 data, uint3
/* First normalise the sub types of the chain. */ /* First normalise the sub types of the chain. */
NormaliseSubtypes(new_head); NormaliseSubtypes(new_head);
if (v == first && v->IsEngine() && !sell_chain && new_head != nullptr && new_head->IsFrontEngine()) { if (v == first && !sell_chain && new_head != nullptr && new_head->IsFrontEngine()) {
/* We are selling the front engine. In this case we want to if (v->IsEngine()) {
* 'give' the order, unit number and such to the new head. */ /* We are selling the front engine. In this case we want to
new_head->orders = first->orders; * 'give' the order, unit number and such to the new head. */
new_head->AddToShared(first); new_head->orders = first->orders;
DeleteVehicleOrders(first); new_head->AddToShared(first);
DeleteVehicleOrders(first);
/* Copy other important data from the front engine */ /* Copy other important data from the front engine */
new_head->CopyVehicleConfigAndStatistics(first); new_head->CopyVehicleConfigAndStatistics(first);
new_head->speed_restriction = first->speed_restriction; new_head->speed_restriction = first->speed_restriction;
SB(Train::From(new_head)->flags, VRF_SPEED_ADAPTATION_EXEMPT, 1, GB(Train::From(first)->flags, VRF_SPEED_ADAPTATION_EXEMPT, 1)); SB(Train::From(new_head)->flags, VRF_SPEED_ADAPTATION_EXEMPT, 1, GB(Train::From(first)->flags, VRF_SPEED_ADAPTATION_EXEMPT, 1));
GroupStatistics::CountVehicle(new_head, 1); // after copying over the profit }
GroupStatistics::CountVehicle(new_head, 1); // after copying over the profit, if required
} else if (v->IsPrimaryVehicle() && data & (MAKE_ORDER_BACKUP_FLAG >> 20)) { } else if (v->IsPrimaryVehicle() && data & (MAKE_ORDER_BACKUP_FLAG >> 20)) {
OrderBackup::Backup(v, user); OrderBackup::Backup(v, user);
} }