Skip to content

Commit

Permalink
Fix OpenTTD#12302: Allow empty train engines to use an invalid cargo …
Browse files Browse the repository at this point in the history
…type. (OpenTTD#12325)

The cargo type will be forced to the first available type (usually passengers) instead of the engine being disabled.
  • Loading branch information
PeterN authored Mar 17, 2024
1 parent 322ca6e commit 88cf990
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/newgrf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9161,6 +9161,14 @@ static void CalculateRefitMasks()
ei->cargo_type = (CargoID)FindFirstBit(ei->refit_mask);
}
}
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<CargoID>(FindFirstBit(_standard_cargo_mask));
}
}
if (!IsValidCargoID(ei->cargo_type)) ei->climates = 0;

/* Clear refit_mask for not refittable ships */
Expand Down

0 comments on commit 88cf990

Please sign in to comment.