diff options
author | frosch <frosch@openttd.org> | 2021-04-30 17:35:32 +0200 |
---|---|---|
committer | frosch <github@elsenhans.name> | 2021-05-13 23:28:43 +0200 |
commit | 9f8d0b1bee104471aff1a5e318b2a92bc235d934 (patch) | |
tree | fc0ff5fa0ae9e6eba562b07a02f1d5cc9876d056 /src/cargotype.cpp | |
parent | a9ff296c3d608f04a14cd604a94531f5b42b2061 (diff) | |
download | openttd-9f8d0b1bee104471aff1a5e318b2a92bc235d934.tar.xz |
Fix: Resolve cargo-types of default vehicles via their cargo label.
Default vehicles now behave as if they had a cargo translation table. This fixes default vehicles carrying seemingly random cargos, if NewGRF industry sets are present.
This behavior is disabled, when a NewGRF touches any of the cargo-type or refitting properties. In that case it's up to the NewGRF to define its own cargo translation table.
Diffstat (limited to 'src/cargotype.cpp')
-rw-r--r-- | src/cargotype.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/cargotype.cpp b/src/cargotype.cpp index bf9561dda..a6ea680d8 100644 --- a/src/cargotype.cpp +++ b/src/cargotype.cpp @@ -78,6 +78,28 @@ void SetupCargoForClimate(LandscapeID l) } /** + * Get the cargo ID of a default cargo, if present. + * @param l Landscape + * @param ct Default cargo type. + * @return ID number if the cargo exists, else #CT_INVALID + */ +CargoID GetDefaultCargoID(LandscapeID l, CargoType ct) +{ + assert(l < lengthof(_default_climate_cargo)); + + if (ct == CT_INVALID) return CT_INVALID; + + assert(ct < lengthof(_default_climate_cargo[0])); + CargoLabel cl = _default_climate_cargo[l][ct]; + /* Bzzt: check if cl is just an index into the cargo table */ + if (cl < lengthof(_default_cargo)) { + cl = _default_cargo[cl].label; + } + + return GetCargoIDByLabel(cl); +} + +/** * Get the cargo ID by cargo label. * @param cl Cargo type to get. * @return ID number if the cargo exists, else #CT_INVALID |