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,7 +2334,8 @@ CommandCost CmdSellRailWagon(DoCommandFlag flags, Vehicle *t, uint16 data, uint3
/* First normalise the sub types of the chain. */
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()) {
if (v->IsEngine()) {
/* We are selling the front engine. In this case we want to
* 'give' the order, unit number and such to the new head. */
new_head->orders = first->orders;
@@ -2345,7 +2346,8 @@ CommandCost CmdSellRailWagon(DoCommandFlag flags, Vehicle *t, uint16 data, uint3
new_head->CopyVehicleConfigAndStatistics(first);
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));
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)) {
OrderBackup::Backup(v, user);
}