MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / MaybeInstallFallbackCargoLabel

Function MaybeInstallFallbackCargoLabel

src/newgrf/newgrf_act0_cargo.cpp:26–40  ·  view source on GitHub ↗

* Install cargo label in a fallback cargo list, if a NewGRF-defined cargo list is not present. * This allows this NewGRF to use its self-defined cargo types without needing an explicit translation table. * @param id ID of the cargo. * @param last ID of the last cargo being set up. * @param label Label to install. */

Source from the content-addressed store, hash-verified

24 * @param label Label to install.
25 */
26static void MaybeInstallFallbackCargoLabel(uint id, uint last, CargoLabel label)
27{
28 if (_cur_gps.grffile->cargo_list.empty()) {
29 /* Cargo translation table isn't configured yet, assume it won't be and configure the cargo list as a fallback list. */
30 auto default_cargo_list = GetCargoTranslationTable(*_cur_gps.grffile);
31 _cur_gps.grffile->cargo_list.assign(default_cargo_list.begin(), default_cargo_list.end());
32 _cur_gps.grffile->cargo_list_is_fallback = true;
33 }
34
35 if (_cur_gps.grffile->cargo_list_is_fallback) {
36 /* Automatically fill fallback cargo list with the defined label, resizing as needed. */
37 if (_cur_gps.grffile->cargo_list.size() < last) _cur_gps.grffile->cargo_list.resize(last, CT_INVALID);
38 _cur_gps.grffile->cargo_list[id] = label;
39 }
40}
41
42/**
43 * Define properties for cargoes

Callers 1

CargoReserveInfoFunction · 0.85

Calls 7

GetCargoTranslationTableFunction · 0.85
resizeMethod · 0.80
emptyMethod · 0.45
assignMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected