diff options
author | peter1138 <peter1138@openttd.org> | 2007-02-24 23:20:21 +0000 |
---|---|---|
committer | peter1138 <peter1138@openttd.org> | 2007-02-24 23:20:21 +0000 |
commit | bc968d23f179b1c606989cb7d7ac32f0412db62d (patch) | |
tree | 953522568a4df36b0eb313ad9f8f22918ab8e79c | |
parent | bee20f6abc2294317fb2a4c618efca0b0f9d38e4 (diff) | |
download | openttd-bc968d23f179b1c606989cb7d7ac32f0412db62d.tar.xz |
(svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
-rw-r--r-- | src/newgrf.cpp | 24 | ||||
-rw-r--r-- | src/newgrf.h | 1 | ||||
-rw-r--r-- | src/newgrf_engine.cpp | 2 |
3 files changed, 26 insertions, 1 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 41fa5f0bb..1263ea151 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -3707,6 +3707,29 @@ static void ClearTemporaryNewGRFData(void) _cur_grffile->spritegroups_count = 0; } +static void BuildCargoTranslationMap() +{ + memset(_cur_grffile->cargo_map, 0xFF, sizeof(_cur_grffile->cargo_map)); + + for (CargoID c = 0; c < NUM_CARGO; c++) { + const CargoSpec *cs = GetCargo(c); + if (!cs->IsValid()) continue; + + if (_cur_grffile->cargo_max == 0) { + /* Default translation table, so just a straight mapping to bitnum */ + _cur_grffile->cargo_map[c] = cs->bitnum; + } else { + /* Check the translation table for this cargo's label */ + for (uint i = 0; i < _cur_grffile->cargo_max; i++) { + if (cs->label == _cur_grffile->cargo_list[i]) { + _cur_grffile->cargo_map[c] = i; + break; + } + } + } + } +} + static void InitNewGRFFile(const GRFConfig *config, int sprite_offset) { GRFFile *newfile; @@ -4032,6 +4055,7 @@ void LoadNewGRF(uint load_index, uint file_index) LoadNewGRFFile(c, slot++, stage); if (stage == GLS_ACTIVATION) { ClearTemporaryNewGRFData(); + BuildCargoTranslationMap(); DEBUG(sprite, 2, "Currently %i sprites are loaded", _cur_spriteid); } } diff --git a/src/newgrf.h b/src/newgrf.h index 964f533ae..74a49113e 100644 --- a/src/newgrf.h +++ b/src/newgrf.h @@ -64,6 +64,7 @@ typedef struct GRFFile { uint8 cargo_max; CargoLabel *cargo_list; + uint8 cargo_map[NUM_CARGO]; } GRFFile; extern GRFFile *_first_grffile; diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp index 412c23585..27320ce61 100644 --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -608,7 +608,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by */ const CargoSpec *cs = GetCargo(v->cargo_type); - return (cs->classes << 16) | (cs->weight << 8) | cs->bitnum; + return (cs->classes << 16) | (cs->weight << 8) | GetEngineGRF(v->engine_type)->cargo_map[v->cargo_type]; } case 0x48: return GetVehicleTypeInfo(v->engine_type); /* Vehicle Type Info */ |