Fix #11307: Incorrect GroupStatistics after selling leading wagon

When this results in a countable consist
pull/603/head
Jonathan G Rennison 9 months ago
parent f5d1b1d8f8
commit cd2a368d77

@ -2334,18 +2334,20 @@ 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()) {
/* 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;
new_head->AddToShared(first);
DeleteVehicleOrders(first);
/* Copy other important data from the front engine */
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
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;
new_head->AddToShared(first);
DeleteVehicleOrders(first);
/* Copy other important data from the front engine */
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, if required
} else if (v->IsPrimaryVehicle() && data & (MAKE_ORDER_BACKUP_FLAG >> 20)) {
OrderBackup::Backup(v, user);
}

Loading…
Cancel
Save