From a1b7ca979bfb7288f0323ad0607534106a847baa Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sun, 17 Mar 2024 16:23:14 +0000 Subject: [PATCH] Fix #12302: Allow empty train engines to use an invalid cargo type. (#12325) The cargo type will be forced to the first available type (usually passengers) instead of the engine being disabled. (cherry picked from commit 88cf99017a26f887230d2c14d057a97bbf077f7c) --- src/newgrf.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 704c963ee0..fa676673eb 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -10821,7 +10821,15 @@ static void CalculateRefitMasks() ei->cargo_type = (CargoID)FindFirstBit(ei->refit_mask); } } - if (ei->cargo_type == INVALID_CARGO) ei->climates = 0; + if (!IsValidCargoID(ei->cargo_type) && e->type == VEH_TRAIN && e->u.rail.railveh_type != RAILVEH_WAGON && e->u.rail.capacity == 0) { + /* For train engines which do not carry cargo it does not matter if their cargo type is invalid. + * Fallback to the first available instead, if the cargo type has not been changed (as indicated by + * cargo_label not being CT_INVALID). */ + if (GetActiveCargoLabel(ei->cargo_label) != CT_INVALID) { + ei->cargo_type = static_cast(FindFirstBit(_standard_cargo_mask)); + } + } + if (!IsValidCargoID(ei->cargo_type)) ei->climates = 0; /* Clear refit_mask for not refittable ships */ if (e->type == VEH_SHIP && !e->u.ship.old_refittable) {