Fix: Clear rail vehicle flipped flag if reverse probability callback returns false. (#14281)

This now distinguishes between not-flipped and callback not implemented.
This commit is contained in:
Peter Nelson
2025-05-20 23:03:55 +01:00
committed by GitHub
parent acf594a7b7
commit a2addf0fe7
6 changed files with 24 additions and 10 deletions

View File

@@ -374,7 +374,11 @@ static CommandCost BuildReplacementVehicle(Vehicle *old_veh, Vehicle **new_vehic
/* Try to reverse the vehicle, but do not care if it fails as the new type might not be reversible */
if (new_veh->type == VEH_TRAIN && Train::From(old_veh)->flags.Test(VehicleRailFlag::Flipped)) {
Command<CMD_REVERSE_TRAIN_DIRECTION>::Do(DoCommandFlag::Execute, new_veh->index, true);
/* Only copy the reverse state if neither old or new vehicle implements reverse-on-build probability callback. */
if (!TestVehicleBuildProbability(old_veh, old_veh->engine_type, BuildProbabilityType::Reversed).has_value() &&
!TestVehicleBuildProbability(new_veh, new_veh->engine_type, BuildProbabilityType::Reversed).has_value()) {
Command<CMD_REVERSE_TRAIN_DIRECTION>::Do(DoCommandFlag::Execute, new_veh->index, true);
}
}
return cost;