diff options
author | peter1138 <peter1138@openttd.org> | 2007-03-23 00:03:08 +0000 |
---|---|---|
committer | peter1138 <peter1138@openttd.org> | 2007-03-23 00:03:08 +0000 |
commit | 4621436d0719fd9c5ce2f71258d90bf1dc09d401 (patch) | |
tree | daa64b95f66410c7095ff258544230ac80326214 /src | |
parent | 9a10771046ebdfe0f95fbe4d57e5dda24fe6371c (diff) | |
download | openttd-4621436d0719fd9c5ce2f71258d90bf1dc09d401.tar.xz |
(svn r9413) -Codechange: Remove default cargo translation table and use bitnums directly if no table is provided. This lets pre-cargolabel cargo definitions work.
Diffstat (limited to 'src')
-rw-r--r-- | src/newgrf.cpp | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp index cea365e96..3579930ba 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -77,10 +77,6 @@ bool _have_2cc = false; /* Set if there are any newhouses loaded. */ bool _have_newhouses = false; -/* Default cargo translation table. By default there are 27 possible cargo types */ -static const uint _default_cargo_max = 27; -static CargoLabel _default_cargo_list[_default_cargo_max]; - enum GrfDataType { GDT_SOUND, @@ -2354,14 +2350,35 @@ static CargoID TranslateCargo(uint8 feature, uint8 ctype) if (feature == GSF_STATION && ctype == 0xFE) return CT_DEFAULT_NA; if (ctype == 0xFF) return CT_PURCHASE; + if (_cur_grffile->cargo_max == 0) { + /* No cargo table, so use bitnum values */ + if (ctype >= 32) { + grfmsg(1, "FeatureMapSpriteGroup: Cargo bitnum %d out of range (max 31), skipping.", ctype); + return CT_INVALID; + } + + for (CargoID c = 0; c < NUM_CARGO; c++) { + const CargoSpec *cs = GetCargo(c); + if (!cs->IsValid()) continue; + + if (cs->bitnum == ctype) { + grfmsg(6, "FeatureMapSpriteGroup: Cargo bitnum %d mapped to cargo type %d.", ctype, c); + return c; + } + } + + grfmsg(5, "FeatureMapSpriteGroup: Cargo bitnum %d not available in this climate, skipping.", ctype); + return CT_INVALID; + } + /* Check if the cargo type is out of bounds of the cargo translation table */ - if (ctype >= (_cur_grffile->cargo_max == 0 ? _default_cargo_max : _cur_grffile->cargo_max)) { - grfmsg(1, "FeatureMapSpriteGroup: Cargo type %d out of range (max %d), skipping.", ctype, (_cur_grffile->cargo_max == 0 ? _default_cargo_max : _cur_grffile->cargo_max) - 1); + if (ctype >= _cur_grffile->cargo_max) { + grfmsg(1, "FeatureMapSpriteGroup: Cargo type %d out of range (max %d), skipping.", ctype, _cur_grffile->cargo_max - 1); return CT_INVALID; } /* Look up the cargo label from the translation table */ - CargoLabel cl = _cur_grffile->cargo_max == 0 ? _default_cargo_list[ctype] : _cur_grffile->cargo_list[ctype]; + CargoLabel cl = _cur_grffile->cargo_list[ctype]; if (cl == 0) { grfmsg(5, "FeatureMapSpriteGroup: Cargo type %d not available in this climate, skipping.", ctype); return CT_INVALID; @@ -4160,13 +4177,6 @@ static void ResetNewGRFData() /* Set up the default cargo types */ SetupCargoForClimate(_opt.landscape); - /* Generate default cargo translation table */ - memset(_default_cargo_list, 0, sizeof(_default_cargo_list)); - for (CargoID c = 0; c < NUM_CARGO; c++) { - const CargoSpec *cs = GetCargo(c); - if (cs->IsValid()) _default_cargo_list[cs->bitnum] = cs->label; - } - /* Reset misc GRF features and train list display variables */ _misc_grf_features = 0; _traininfo_vehicle_pitch = 0; |