* 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. */
| 24 | * @param label Label to install. |
| 25 | */ |
| 26 | static 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 |
no test coverage detected